Class: Treetop::Runtime::SyntaxNode
- Inherits:
-
Object
- Object
- Treetop::Runtime::SyntaxNode
- Defined in:
- lib/treetop/runtime/syntax_node.rb
Direct Known Subclasses
Compiler::DeclarationSequence, Compiler::Grammar, Compiler::InlineModule, Compiler::ParsingExpression, Compiler::ParsingRule, Compiler::TreetopFile, TerminalSyntaxNode
Instance Attribute Summary collapse
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #extension_modules ⇒ Object
-
#initialize(input, interval, elements = nil) ⇒ SyntaxNode
constructor
A new instance of SyntaxNode.
- #inspect(indent = "") ⇒ Object
- #nonterminal? ⇒ Boolean
- #terminal? ⇒ Boolean
- #text_value ⇒ Object
Constructor Details
#initialize(input, interval, elements = nil) ⇒ SyntaxNode
Returns a new instance of SyntaxNode.
7 8 9 10 11 12 13 14 15 |
# File 'lib/treetop/runtime/syntax_node.rb', line 7 def initialize(input, interval, elements = nil) @input = input @interval = interval if @elements = elements elements.each do |element| element.parent = self end end end |
Instance Attribute Details
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
4 5 6 |
# File 'lib/treetop/runtime/syntax_node.rb', line 4 def elements @elements end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
4 5 6 |
# File 'lib/treetop/runtime/syntax_node.rb', line 4 def input @input end |
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
4 5 6 |
# File 'lib/treetop/runtime/syntax_node.rb', line 4 def interval @interval end |
#parent ⇒ Object
Returns the value of attribute parent.
5 6 7 |
# File 'lib/treetop/runtime/syntax_node.rb', line 5 def parent @parent end |
Instance Method Details
#empty? ⇒ Boolean
29 30 31 |
# File 'lib/treetop/runtime/syntax_node.rb', line 29 def empty? interval.first == interval.last && interval.exclude_end? end |
#extension_modules ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/treetop/runtime/syntax_node.rb', line 33 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 = "") ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/treetop/runtime/syntax_node.rb', line 45 def inspect(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 + (elements && elements.size > 0 ? ":" + (@elements||[]).map{|e| begin "\n"+e.inspect(indent+" ") rescue # Defend against inspect not taking a parameter "\n"+indent+" "+e.inspect end }.join("") : "" ) end |
#nonterminal? ⇒ Boolean
21 22 23 |
# File 'lib/treetop/runtime/syntax_node.rb', line 21 def nonterminal? !terminal? end |
#terminal? ⇒ Boolean
17 18 19 |
# File 'lib/treetop/runtime/syntax_node.rb', line 17 def terminal? @elements.nil? end |
#text_value ⇒ Object
25 26 27 |
# File 'lib/treetop/runtime/syntax_node.rb', line 25 def text_value input[interval] end |