class Treetop::Runtime::SyntaxNode
Attributes
input[R]
interval[R]
parent[RW]
Public Class Methods
new(input, interval, elements = nil)
click to toggle source
# File lib/treetop/runtime/syntax_node.rb, line 7 def initialize(input, interval, elements = nil) @input = input @interval = interval if (@elements = elements) @elements.each { |e| e.equal?(true) or e.parent = self } end end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/treetop/runtime/syntax_node.rb, line 47 def <=>(other) self.interval.first <=> other.interval.first end
dot_id()
click to toggle source
# File lib/treetop/runtime/syntax_node.rb, line 98 def dot_id @dot_id ||= @@dot_id_counter += 1 end
elements()
click to toggle source
# File lib/treetop/runtime/syntax_node.rb, line 15 def elements return @elements if terminal? # replace the character class placeholders in the sequence (lazy instantiation) last_element = nil @comprehensive_elements ||= @elements.map do |element| if element == true index = last_element ? last_element.interval.last : interval.first element = SyntaxNode.new(input, index...(index + 1)) element.parent = self end last_element = element end @comprehensive_elements end
empty?()
click to toggle source
# File lib/treetop/runtime/syntax_node.rb, line 43 def empty? interval.first == interval.last && interval.exclude_end? end
extension_modules()
click to toggle source
# File lib/treetop/runtime/syntax_node.rb, line 51 def extension_modules local_extensions = class <<self included_modules-Object.included_modules end if local_extensions.size > 0 local_extensions else [] # There weren't any; must be a literal node end end
inspect(indent="")
click to toggle source
# File lib/treetop/runtime/syntax_node.rb, line 91 def inspect(indent="") inspect_self(indent) + inspect_children(indent) end
inspect_children(indent="")
click to toggle source
# File lib/treetop/runtime/syntax_node.rb, line 78 def inspect_children(indent="") return '' unless elements && elements.size > 0 ":" + elements.map do |e| begin "\n"+e.inspect(indent+" ") rescue # Defend against inspect not taking a parameter "\n"+indent+" "+e.inspect end end. join("") end
inspect_self(indent="")
click to toggle source
# File lib/treetop/runtime/syntax_node.rb, line 63 def inspect_self(indent="") em = extension_modules interesting_methods = methods-[em.last ? em.last.methods : nil]-self.class.instance_methods im = interesting_methods.size > 0 ? " (#{interesting_methods.join(",")})" : "" tv = text_value tv = "...#{tv[-20..-1]}" if tv.size > 20 indent + self.class.to_s.sub(/.*:/,'') + em.map{|m| "+"+m.to_s.sub(/.*:/,'')}*"" + " offset=#{interval.first}" + ", #{tv.inspect}" + im end
nonterminal?()
click to toggle source
# File lib/treetop/runtime/syntax_node.rb, line 35 def nonterminal? !terminal? end
terminal?()
click to toggle source
# File lib/treetop/runtime/syntax_node.rb, line 31 def terminal? @elements.nil? end
text_value()
click to toggle source
# File lib/treetop/runtime/syntax_node.rb, line 39 def text_value input[interval] end
write_dot(io)
click to toggle source
# File lib/treetop/runtime/syntax_node.rb, line 102 def write_dot(io) io.puts "node#{dot_id} [label=\"'#{text_value}'\"];" if nonterminal? then elements.each do |x| io.puts "node#{dot_id} -> node#{x.dot_id};" x.write_dot(io) end end end
write_dot_file(fname)
click to toggle source
# File lib/treetop/runtime/syntax_node.rb, line 113 def write_dot_file(fname) File.open(fname + ".dot","w") do |file| file.puts "digraph G {" write_dot(file) file.puts "}" end end