Class: LiftingSyntaxTreeBuilder

Inherits:
SyntaxTreeBuilder show all
Defined in:
lib/rpdf2txt-rockit/syntax_tree.rb

Instance Attribute Summary

Attributes inherited from SyntaxTreeBuilder

#children_names, #inactive_children_indices, #node_name

Instance Method Summary collapse

Methods inherited from SyntaxTreeBuilder

#==, #activate_child, #active_childrens, #inactivate_child, #inactive_childrens

Methods included from SourceCodeDumpable

as_code, as_method_named, as_module_method_named, #create_new, indent_lines, name_hash, #new_of_my_type, #parameter_named, #to_compact_src, #to_src_in_module, #type_to_src

Constructor Details

#initialize(childrenNames, inactiveChildrenIndices = []) ⇒ LiftingSyntaxTreeBuilder



111
112
113
114
115
# File 'lib/rpdf2txt-rockit/syntax_tree.rb', line 111

def initialize(childrenNames, inactiveChildrenIndices = [])
  super("^", childrenNames, inactiveChildrenIndices)
  @child_to_lift_index = 
    @children_names.index(@children_names.detect {|n| n != "_"})
end

Instance Method Details

#copyObject



129
130
131
# File 'lib/rpdf2txt-rockit/syntax_tree.rb', line 129

def copy
  LiftingSyntaxTreeBuilder.new(children_names, inactive_children_indices)
end

#create_tree(childrenValues) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
# File 'lib/rpdf2txt-rockit/syntax_tree.rb', line 117

def create_tree(childrenValues)
  if @child_to_lift_index
    return childrenValues[@child_to_lift_index]
  else
    # Use first children value which does not have a "lexeme" children
    # ie. which represents a non-terminal
    val = childrenValues.detect {|c| !c.children_names.include?("lexeme")}
    val = childrenValues[0] unless val
    return val
  end
end

#to_src(name = nil, nameHash = {}) ⇒ Object



133
134
135
136
137
# File 'lib/rpdf2txt-rockit/syntax_tree.rb', line 133

def to_src(name = nil, nameHash = {})
  assign_to(name,
     new_of_my_type(as_code(children_names.to_compact_src), 
	     as_code(inactive_children_indices.to_compact_src)))
end