class SheepAst::NodeFactory

Factory object to create Node

@api privte

Attributes

root_node[R]

Public Class Methods

new() click to toggle source
Calls superclass method SheepAst::FactoryBase::new
# File lib/sheep_ast/node_factory.rb, line 24
def initialize
  super()
  @root_node = Node.new(0)
  @root_node.my_tag = :root
  @root_node.parent_node = @root_node
  @tag_node_db = {}
  create_id(@root_node)
  @root_node.my_node_factory = self
  init
end

Public Instance Methods

add(match, group) click to toggle source
# File lib/sheep_ast/node_factory.rb, line 61
def add(match, group)
  if match.parent_tag
    test = @node_tag_db[match.parent_tag]
    if test
      @__node = from_id(test)
    end
  end
  next_node = @__node.find(match.key)
  if next_node.nil?
    if @__node.my_action
      if !@__node.my_action.qualifier?
        lfatal @__node.my_action.warning
        missing_impl 'qualifier is needed for previous action'
      else
        @__node.my_action.need_qualify
      end
    end
    next_node = @__node.create(@__chain_num, match, group)
    @node_tag_db[match.node_tag] = next_node.my_id if match.node_tag
  end
  @__node = next_node
  @__chain_num += 1
end
add_action(action) click to toggle source
# File lib/sheep_ast/node_factory.rb, line 90
def add_action(action)
  ldebug? and ldebug "action = #{action.name} is added to node id = #{@__node.my_id}"
  @__node.reg_action(action, nil)
end
dump_tree(logs) click to toggle source
# File lib/sheep_ast/node_factory.rb, line 109
def dump_tree(logs)
  NodeBuf.buffer_init
  @root_node.node_buffer.save_tree_from_here
  @root_node.node_buffer.dump_buffer(logs)
end
find_from_root_node(data) click to toggle source
# File lib/sheep_ast/node_factory.rb, line 103
def find_from_root_node(data)
  return root_node.find_next_node(data)
end
init() click to toggle source
# File lib/sheep_ast/node_factory.rb, line 96
def init
  @__node = @root_node
  @__chain_num = 1
end
register_nodes(matches, action, group) click to toggle source
# File lib/sheep_ast/node_factory.rb, line 43
def register_nodes(matches, action, group)
  init
  matches.each do |a_match|
    add(a_match, group)
  end
  add_action(action)
end
register_tag(tag, node) click to toggle source
# File lib/sheep_ast/node_factory.rb, line 53
def register_tag(tag, node)
  if @tag_node_db.key?(tag)
    application_error 'the tag is already registered'
  end
  @tag_node_db[tag] = node
end