Class: Treetop::Runtime::SyntaxNode

### Home Classes Methods

### In Files

- lib/treetop/runtime/syntax_node.rb

### Parent

Object

### Methods

- ::new
- #<=>
- #dot_id
- #elements
- #empty?
- #extension_modules
- #inspect
- #nonterminal?
- #terminal?
- #text_value
- #write_dot
- #write_dot_file

### Class/Module Index

Quicksearch

- Treetop
- Treetop::Compiler
- Treetop::Compiler::AndPredicate
- Treetop::Compiler::AnythingSymbol
- Treetop::Compiler::AtomicExpression
- Treetop::Compiler::CharacterClass
- Treetop::Compiler::Choice
- Treetop::Compiler::DeclarationSequence
- Treetop::Compiler::Grammar
- Treetop::Compiler::GrammarCompiler
- Treetop::Compiler::InlineModule
- Treetop::Compiler::InlineModuleMixin
- Treetop::Compiler::LexicalAddressSpace
- Treetop::Compiler::Metagrammar
- Treetop::Compiler::Metagrammar::CharacterClass0
- Treetop::Compiler::Metagrammar::CharacterClass1
- Treetop::Compiler::Metagrammar::CharacterClass2
- Treetop::Compiler::Metagrammar::CharacterClass3
- Treetop::Compiler::Metagrammar::CharacterClass4
- Treetop::Compiler::Metagrammar::Choice0
- Treetop::Compiler::Metagrammar::Choice1
- Treetop::Compiler::Metagrammar::Choice2
- Treetop::Compiler::Metagrammar::CommentToEol0
- Treetop::Compiler::Metagrammar::CommentToEol1
- Treetop::Compiler::Metagrammar::DeclarationSequence0
- Treetop::Compiler::Metagrammar::DeclarationSequence1
- Treetop::Compiler::Metagrammar::DeclarationSequence2
- Treetop::Compiler::Metagrammar::DeclarationSequence3
- Treetop::Compiler::Metagrammar::DoubleQuotedString0
- Treetop::Compiler::Metagrammar::DoubleQuotedString1
- Treetop::Compiler::Metagrammar::Grammar0
- Treetop::Compiler::Metagrammar::Grammar1
- Treetop::Compiler::Metagrammar::GrammarName0
- Treetop::Compiler::Metagrammar::IncludeDeclaration0
- Treetop::Compiler::Metagrammar::IncludeDeclaration1
- Treetop::Compiler::Metagrammar::InlineModule0
- Treetop::Compiler::Metagrammar::InlineModule1
- Treetop::Compiler::Metagrammar::KeywordInsideGrammar0
- Treetop::Compiler::Metagrammar::Label0
- Treetop::Compiler::Metagrammar::Label1
- Treetop::Compiler::Metagrammar::Label2
- Treetop::Compiler::Metagrammar::Label3
- Treetop::Compiler::Metagrammar::LabeledSequencePrimary0
- Treetop::Compiler::Metagrammar::LabeledSequencePrimary1
- Treetop::Compiler::Metagrammar::ModuleDeclaration0
- Treetop::Compiler::Metagrammar::ModuleDeclaration1
- Treetop::Compiler::Metagrammar::ModuleDeclaration2
- Treetop::Compiler::Metagrammar::ModuleDeclaration3
- Treetop::Compiler::Metagrammar::NodeClassDeclarations0
- Treetop::Compiler::Metagrammar::NodeClassDeclarations1
- Treetop::Compiler::Metagrammar::NodeClassExpression0
- Treetop::Compiler::Metagrammar::NodeClassExpression1
- Treetop::Compiler::Metagrammar::NodeClassExpression2
- Treetop::Compiler::Metagrammar::NodeClassExpression3
- Treetop::Compiler::Metagrammar::NonSpaceChar0
- Treetop::Compiler::Metagrammar::Nonterminal0
- Treetop::Compiler::Metagrammar::Nonterminal1
- Treetop::Compiler::Metagrammar::OccurrenceRange0
- Treetop::Compiler::Metagrammar::ParenthesizedExpression0
- Treetop::Compiler::Metagrammar::ParenthesizedExpression1
- Treetop::Compiler::Metagrammar::ParsingRule0
- Treetop::Compiler::Metagrammar::ParsingRule1
- Treetop::Compiler::Metagrammar::PredicateBlock0
- Treetop::Compiler::Metagrammar::Primary0
- Treetop::Compiler::Metagrammar::Primary1
- Treetop::Compiler::Metagrammar::Primary2
- Treetop::Compiler::Metagrammar::Primary3
- Treetop::Compiler::Metagrammar::Primary4
- Treetop::Compiler::Metagrammar::Primary5
- Treetop::Compiler::Metagrammar::Primary6
- Treetop::Compiler::Metagrammar::Primary7
- Treetop::Compiler::Metagrammar::QuotedString0
- Treetop::Compiler::Metagrammar::RequireStatement0
- Treetop::Compiler::Metagrammar::Sequence0
- Treetop::Compiler::Metagrammar::Sequence1
- Treetop::Compiler::Metagrammar::Sequence2
- Treetop::Compiler::Metagrammar::SequencePrimary0
- Treetop::Compiler::Metagrammar::SequencePrimary1
- Treetop::Compiler::Metagrammar::SequencePrimary2
- Treetop::Compiler::Metagrammar::SequencePrimary3
- Treetop::Compiler::Metagrammar::SequencePrimary4
- Treetop::Compiler::Metagrammar::SequencePrimary5
- Treetop::Compiler::Metagrammar::SingleQuotedString0
- Treetop::Compiler::Metagrammar::SingleQuotedString1
- Treetop::Compiler::Metagrammar::TrailingInlineModule0
- Treetop::Compiler::Metagrammar::TrailingInlineModule1
- Treetop::Compiler::Metagrammar::TrailingInlineModule2
- Treetop::Compiler::Metagrammar::TreetopFile0
- Treetop::Compiler::Metagrammar::TreetopFile1
- Treetop::Compiler::Metagrammar::TreetopFile2
- Treetop::Compiler::MetagrammarParser
- Treetop::Compiler::Nonterminal
- Treetop::Compiler::NotPredicate
- Treetop::Compiler::OccurrenceRange
- Treetop::Compiler::OneOrMore
- Treetop::Compiler::Optional
- Treetop::Compiler::ParenthesizedExpression
- Treetop::Compiler::ParsingExpression
- Treetop::Compiler::ParsingRule
- Treetop::Compiler::Predicate
- Treetop::Compiler::PredicateBlock
- Treetop::Compiler::Repetition
- Treetop::Compiler::RubyBuilder
- Treetop::Compiler::Sequence
- Treetop::Compiler::SequenceElementAccessorModule
- Treetop::Compiler::Terminal
- Treetop::Compiler::TransientPrefix
- Treetop::Compiler::TreetopFile
- Treetop::Compiler::ZeroOrMore
- Treetop::Polyglot
- Treetop::Runtime
- Treetop::Runtime::CompiledParser
- Treetop::Runtime::SyntaxNode
- Treetop::Runtime::TerminalParseFailure
- Treetop::Runtime::TerminalSyntaxNode
- IntervalSkipList
- IntervalSkipList::HeadNode
- IntervalSkipList::Node
- Object
- String

No matching classes.

# 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
      @elements = elements
    end

### Public Instance Methods

<=>(other) click to toggle source

    # File lib/treetop/runtime/syntax_node.rb, line 45
    def <=>(other)
      self.interval.first <=> other.interval.first
    end

dot_id() click to toggle source

    # File lib/treetop/runtime/syntax_node.rb, line 89
    def dot_id
      @dot_id ||= @@dot_id_counter += 1
    end

elements() click to toggle source

    # File lib/treetop/runtime/syntax_node.rb, line 13
    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))
        end
        element.parent = self
        last_element = element
      end

      @comprehensive_elements
    end

empty?() click to toggle source

    # File lib/treetop/runtime/syntax_node.rb, line 41
    def empty?
      interval.first == interval.last && interval.exclude_end?
    end

extension_modules() click to toggle source

    # File lib/treetop/runtime/syntax_node.rb, line 49
    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 61
    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?() click to toggle source

    # File lib/treetop/runtime/syntax_node.rb, line 33
    def nonterminal?
      !terminal?
    end

terminal?() click to toggle source

    # File lib/treetop/runtime/syntax_node.rb, line 29
    def terminal?
      @elements.nil?
    end

text_value() click to toggle source

    # File lib/treetop/runtime/syntax_node.rb, line 37
    def text_value
      input[interval]
    end

write_dot(io) click to toggle source

    # File lib/treetop/runtime/syntax_node.rb, line 93
    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 104
    def write_dot_file(fname)
      File.open(fname + ".dot","w") do
        |file|
        file.puts "digraph G {"
        write_dot(file)
        file.puts "}"
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.