Class: Packrat::ASTBuilder

Inherits:
ResultProducer show all
Defined in:
lib/packrat/grammar.rb

Overview

Build AST tree as result of parsing a Production.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject (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_resultObject



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