Class: SrlRuby::ASTBuilder

Inherits:
Rley::ParseRep::ASTBaseBuilder
  • Object
show all
Defined in:
lib/srl_ruby/ast_builder.rb

Overview

The purpose of a ASTBuilder is to build piece by piece an AST (Abstract Syntax Tree) from a sequence of input tokens and visit events produced by walking over a GFGParsing object. Uses the Builder GoF pattern. The Builder pattern creates a complex object (say, a parse tree) from simpler objects (terminal and non-terminal nodes) and using a step by step approach.

Constant Summary collapse

Terminal2NodeClass =
{}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(theTokens) ⇒ ASTBuilder

Create a new AST builder instance.

Parameters:

  • theTokens (Array<Token>)

    The sequence of input tokens.



19
20
21
22
# File 'lib/srl_ruby/ast_builder.rb', line 19

def initialize(theTokens)
  super(theTokens)
  @options = []
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



15
16
17
# File 'lib/srl_ruby/ast_builder.rb', line 15

def options
  @options
end

Instance Method Details

#done!Object

Notification that the parse tree construction is complete.



25
26
27
28
# File 'lib/srl_ruby/ast_builder.rb', line 25

def done!
  apply_options
  super
end