Class: Packrat::ASTBuilder
- Inherits:
-
ResultProducer
- Object
- ResultProducer
- Packrat::ASTBuilder
- Defined in:
- lib/packrat/grammar.rb
Overview
Build AST tree as result of parsing a Production.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #finalize_result(res) ⇒ Object
-
#initialize(nodeName, nameMap = {}) ⇒ ASTBuilder
constructor
A new instance of ASTBuilder.
- #new_result ⇒ Object
- #production=(prod) ⇒ Object
- #update_result(res, subres, elem, index, nhIndex) ⇒ Object
Constructor Details
#initialize(nodeName, nameMap = {}) ⇒ ASTBuilder
Returns a new instance of ASTBuilder.
324 325 326 |
# File 'lib/packrat/grammar.rb', line 324 def initialize(nodeName, nameMap = {}) @name, @name_map = nodeName, nameMap end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
323 324 325 |
# File 'lib/packrat/grammar.rb', line 323 def name @name end |
Instance Method Details
#finalize_result(res) ⇒ Object
337 338 339 |
# File 'lib/packrat/grammar.rb', line 337 def finalize_result(res) @ast_class.new(res, {:only_nonconstant => true}) end |
#new_result ⇒ Object
332 |
# File 'lib/packrat/grammar.rb', line 332 def new_result; Array.new; end |
#production=(prod) ⇒ Object
327 328 329 330 |
# File 'lib/packrat/grammar.rb', line 327 def production=(prod) super @ast_class = prod.grammar.ast_class(@name, prod, @name_map) end |
#update_result(res, subres, elem, index, nhIndex) ⇒ Object
333 334 335 336 |
# File 'lib/packrat/grammar.rb', line 333 def update_result(res, subres, elem, index, nhIndex) res << subres unless @ast_class.constant_elem_at?(nhIndex) res end |