Class: Jaina::Parser::AST::TreeBuilder Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/jaina/parser/ast/tree_builder.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(program) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • progrm (String)

Since:

  • 0.1.0



32
33
34
35
36
# File 'lib/jaina/parser/ast/tree_builder.rb', line 32

def initialize(program)
  @program = program.dup.tap(&:freeze)
  @prefix_form = Jaina::Parser::CodeConverter.to_prefix_form(@program)
  @tokens = Jaina::Parser::Tokenizer.tokenize(@prefix_form)
end

Class Method Details

.build(program) ⇒ Jaina::Parser::AST::Tree

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • program (String)

Returns:

Since:

  • 0.1.0



15
16
17
# File 'lib/jaina/parser/ast/tree_builder.rb', line 15

def build(program)
  new(program).build
end

Instance Method Details

#buildJaina::Parser::AST:Tree

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Jaina::Parser::AST:Tree)

Since:

  • 0.1.0



42
43
44
45
46
47
48
49
50
51
# File 'lib/jaina/parser/ast/tree_builder.rb', line 42

def build
  token_series = tokens.map(&:dup)
  expression_tree = build_expression_tree(token_series)

  Jaina::Parser::AST::Tree.new(
    initial_program: program,
    ast_oriented_program: prefix_form,
    expression: expression_tree
  )
end