Class: Highway::Compiler::Parse::Tree::Root

Inherits:
Object
  • Object
show all
Defined in:
lib/highway/compiler/parse/tree/root.rb

Overview

This class represents a root node of a parse tree. It contains other nodes, such as variables and steps.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version:) ⇒ Root

Initialize an instance.

Parameters:

  • version (Integer)

    Version of the parse tree.



23
24
25
26
27
# File 'lib/highway/compiler/parse/tree/root.rb', line 23

def initialize(version:)
  @version = version
  @variables = Array.new()
  @steps = Array.new()
end

Instance Attribute Details

#stepsArray<Highway::Compiler::Parse::Tree::Step> (readonly)

Steps in the tree.



42
43
44
# File 'lib/highway/compiler/parse/tree/root.rb', line 42

def steps
  @steps
end

#variablesArray<Highway::Compiler::Parse::Tree::Variable> (readonly)

Variables in the tree.



37
38
39
# File 'lib/highway/compiler/parse/tree/root.rb', line 37

def variables
  @variables
end

#versionInteger (readonly)

Version of the parse tree.

Returns:

  • (Integer)


32
33
34
# File 'lib/highway/compiler/parse/tree/root.rb', line 32

def version
  @version
end

Instance Method Details

#add_step(name:, parameters:, preset:, stage:, index:) ⇒ Void

Add a step to the tree.

Parameters:

  • index (Integer)

    Index of step in its scope.

  • name (String)

    Name of the step.

  • parameters (Hash)

    Parameters of the step.

  • preset (String)

    Parent preset of the step.

  • stage (String)

    Parent stage of the step.

Returns:

  • (Void)


64
65
66
# File 'lib/highway/compiler/parse/tree/root.rb', line 64

def add_step(name:, parameters:, preset:, stage:, index:)
  @steps << Step.new(index: index, name: name, parameters: parameters, preset: preset, stage: stage)
end

#add_variable(name:, value:, preset:) ⇒ Void

Add a variable to the tree.

Parameters:

  • name (String)

    Name of the variable.

  • value (String)

    Raw value of the variable.

  • preset (String)

    Parent preset of the variable.

Returns:

  • (Void)


51
52
53
# File 'lib/highway/compiler/parse/tree/root.rb', line 51

def add_variable(name:, value:, preset:)
  @variables << Variable.new(name: name, value: value, preset: preset)
end