class SheepAst::Node
Sheep Ast node representation
@api private
Attributes
global_matches[RW]
methods_array[RW]
my_action[R]
my_chain_id[R]
my_node_factory[RW]
my_tag[RW]
node_buffer[R]
parent_node[RW]
Public Class Methods
new(chain_num, match = nil, group = nil)
click to toggle source
Calls superclass method
SheepAst::AnyMatchUtil::new
# File lib/sheep_ast/node.rb, line 55 def initialize(chain_num, match = nil, group = nil) @my_group = group @my_match = match @my_chain_id = chain_num T.must(@my_match).my_chain_num = chain_num unless match.nil? @matches_to_node = {} @matches_to_match = {} @node_buffer = NodeBuf.new(@matches_to_node, @my_match, @my_chain_id, @my_group) @methods_array = [] @global_matches = {} @methods_array = [] @ordered_methods_array = [] super() end
Public Instance Methods
create(chain_num, match, group)
click to toggle source
# File lib/sheep_ast/node.rb, line 82 def create(chain_num, match, group) a_node = Node.new(chain_num, match, group) a_node.my_node_factory = @my_node_factory @my_node_factory.create_id(a_node) register_node(a_node, match) return a_node end
find(key)
click to toggle source
# File lib/sheep_ast/node.rb, line 107 def find(key) return @matches_to_node[key] end
find_next_node(data)
click to toggle source
# File lib/sheep_ast/node.rb, line 113 def find_next_node(data) # rubocop: disable all ldebug? and ldebug "#{inspect} start processing..." if @reordered.nil? reordered @reordered = true end @ordered_methods_array.each do |m| #rubocop: disable all match = m.call(data) ldebug? and ldebug "Got match #{match.inspect} at #{m.name}" unless match.nil? match = nil unless match&.additional_cond(data) # if !match.nil? && !match.validate(data) # ldebug? and ldebug 'Additional condition cannot be fullfiled. set nil' # match = nil # end node_info_ = match&.node_info next if node_info_.nil? node_info = NodeInfo.new node_info.copy(node_info_) node_info.status = MatchStatus::NotFound node = @my_node_factory.from_id(node_info.node_id) if @condition_flag # Strategy 0 # The condition match is not done. # This is clearly not End of AST lookup if condition_change? ldebug? and ldebug 'MatchStatus::ConditionMatchingStart' node_info.status = MatchStatus::ConditionMatchingStart else ldebug? and ldebug 'MatchStatus::ConditionMatchingProgress' node_info.status = MatchStatus::ConditionMatchingProgress end elsif node.my_action.nil? # Strategy 1. # The action is nil. # This is the case to continue scanning node_info.status = MatchStatus::MatchingProgress elsif !node.my_action.need_qualify? # Strategy 2 # The action is not nil and condition match is not scope # This is the case of End AST lookup since there are no another nodes # to look up but only action node_info.status = MatchStatus::AtEnd elsif node.my_action.really_end?(data) # Strategy 3 # The action is not nil and condition match is not scope # This is the case of End AST by user specified really_end? function node_info.status = MatchStatus::AtEnd else # Strategy 4 # So, this is the case of not really_end. # This is not End of AST lookup node_info.status = MatchStatus::MatchingProgress end ldebug? and ldebug "node_info.status = #{node_info.status}" ldebug? and ldebug "condition flag = #{@condition_flag.inspect}" if node_info.status == MatchStatus::AtEnd && condition_change? ldebug? and ldebug 'MatchStatus::ConditionMatchingAtEnd' node_info.status = MatchStatus::ConditionMatchingAtEnd end if node_info.status == MatchStatus::MatchingProgress && condition_change? ldebug? and ldebug 'MatchStatus::ConditionEndButMatchingProgress' node_info.status = MatchStatus::ConditionEndButMatchingProgress end return node_info end # Strategy5 # The given keyword does not match any registered nodes. # This is not found status ldebug? and ldebug "No matching match. NotFound. my_id = #{@my_id}, object_id = #{object_id}" return NodeInfo.new(status: MatchStatus::NotFound) end
inspect()
click to toggle source
# File lib/sheep_ast/node.rb, line 71 def inspect "custom inspect: <#{self.class.name} object_id = #{object_id}, my_group = #{@my_group}, "\ "my_match = #{@my_match.inspect}, matches = #{@maches_to_node.inspect}, "\ "my_chain_id = #{@my_chain_id}, my_tag = #{my_tag}>" end
next_command()
click to toggle source
# File lib/sheep_ast/node.rb, line 204 def next_command res = [] @matches_to_match.each do |_k, v| next_command = NextCommand.new next_command.command = v.command next_command.description = v.description res << next_command end return res end
reg_action(action, qualifier = nil)
click to toggle source
# File lib/sheep_ast/node.rb, line 96 def reg_action(action, qualifier = nil) if !@my_action.nil? application_error 'action already registered. Maybe duplicated ast entry' end @my_action = action @my_action.register_qualifier(qualifier) unless qualifier.nil? @node_buffer.reg_action(action) end
reordered()
click to toggle source
# File lib/sheep_ast/node.rb, line 198 def reordered tmp = @methods_array.sort { |a, b| a[0] <=> b[0] } @ordered_methods_array = tmp.transpose[1] end
Private Instance Methods
register_node(node, match)
click to toggle source
# File lib/sheep_ast/node.rb, line 218 def register_node(node, match) # rubocop: disable all match.node_id = node.my_id.dup match_container = global_matches[match.kind?.rank] node.my_tag = match.my_tag node.parent_node = self @my_node_factory.register_tag(node.my_tag, node) if node.my_tag application_error 'unknown match' if match_container.nil? if match_container.key? match.key lfatal "Same key is detected for => #{match.inspect}" application_error end if @my_match.nil? ldebug? and ldebug "register_node: my node = root, got '#{match.key}',my id = #{my_id}"\ " my obect_id = #{object_id}, assigned id = #{node.my_id}, assigned object_id = #{node.object_id}" else ldebug? and ldebug "register_node: my node = #{@my_match.key}, got '#{match.key}', "\ " my object_id = #{object_id}, assigned id = #{node.my_id}, assigned object_id = #{node.object_id}" end match_container[match.key] = match @matches_to_node[match.key] = node @matches_to_match[match.key] = match end