Class: Treetop::Runtime::CompiledParser

### Home Classes Methods

### In Files

- lib/treetop/runtime/compiled_parser.rb

### Parent

Object

### Methods

- ::new
- #failure_column
- #failure_index
- #failure_line
- #failure_reason
- #has_terminal?
- #instantiate_node
- #parse
- #parse_anything
- #prepare_to_parse
- #reset_index
- #terminal_failures
- #terminal_parse_failure

### Included Modules

- Treetop::Runtime

### Files

- LICENSE

### 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::BracketExpression0
- 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::LabeledExpressionSequenceBody0
- 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::ModuleDeclaration4
- Treetop::Compiler::Metagrammar::ModuleDeclaration5
- Treetop::Compiler::Metagrammar::NamedLabel0
- Treetop::Compiler::Metagrammar::NamedLabel1
- Treetop::Compiler::Metagrammar::NamedLabel2
- 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::NullLabel0
- 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::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::Metagrammar::UnlabeledSequencePrimary0
- Treetop::Compiler::Metagrammar::UnlabeledSequencePrimary1
- Treetop::Compiler::Metagrammar::VariableLengthSequenceBody0
- Treetop::Compiler::Metagrammar::VariableLengthSequenceBody1
- Treetop::Compiler::Metagrammar::VariableLengthSequenceBody2
- 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::CompiledParser

### Attributes

consume_all_input[RW]
consume_all_input?[RW]
index[RW]
input[R]
input_length[R]
max_terminal_failure_index[R]
node_cache[R]
root[W]

### Public Class Methods

new() click to toggle source

    # File lib/treetop/runtime/compiled_parser.rb, line 11
    def initialize
      self.consume_all_input = true
    end

### Public Instance Methods

failure_column() click to toggle source

    # File lib/treetop/runtime/compiled_parser.rb, line 33
    def failure_column
      @terminal_failures && input.column_of(failure_index)
    end

failure_index() click to toggle source

    # File lib/treetop/runtime/compiled_parser.rb, line 25
    def failure_index
      max_terminal_failure_index
    end

failure_line() click to toggle source

    # File lib/treetop/runtime/compiled_parser.rb, line 29
    def failure_line
      @terminal_failures && input.line_of(failure_index)
    end

failure_reason() click to toggle source

    # File lib/treetop/runtime/compiled_parser.rb, line 37
    def failure_reason
      return nil unless (tf = terminal_failures) && tf.size > 0
      "Expected " +
        (tf.size == 1 ?
         tf[0].expected_string :
               "one of #{tf.map{|f| f.expected_string}.uniq*', '}"
        ) +
              " at line #{failure_line}, column #{failure_column} (byte #{failure_index+1})" +
              " after #{input[index...failure_index]}"
    end

parse(input, options = {}) click to toggle source

    # File lib/treetop/runtime/compiled_parser.rb, line 15
    def parse(input, options = {})
      prepare_to_parse(input)
      @index = options[:index] if options[:index]
      result = send("_nt_#{options[:root] || root}")
      should_consume_all = options.include?(:consume_all_input) ? options[:consume_all_input] : consume_all_input?
      return nil if (should_consume_all && index != input.size)
      return SyntaxNode.new(input, index...(index + 1)) if result == true
      return result
    end

terminal_failures() click to toggle source

    # File lib/treetop/runtime/compiled_parser.rb, line 48
    def terminal_failures
      if @terminal_failures.empty? || @terminal_failures[0].is_a?(TerminalParseFailure)
        @terminal_failures
      else
        @terminal_failures.map! {|tf_ary| TerminalParseFailure.new(*tf_ary) }
      end
    end

### Protected Instance Methods

has_terminal?(terminal, regex, index) click to toggle source

    # File lib/treetop/runtime/compiled_parser.rb, line 95
    def has_terminal?(terminal, regex, index)
      if regex
        rx = @regexps[terminal] ||= Regexp.new(terminal)
        input.index(rx, index) == index
      else
        input[index, terminal.size] == terminal
      end
    end

instantiate_node(node_type,*args) click to toggle source

    # File lib/treetop/runtime/compiled_parser.rb, line 87
    def instantiate_node(node_type,*args)
      if node_type.respond_to? :new
        node_type.new(*args)
      else
        SyntaxNode.new(*args).extend(node_type)
      end
    end

parse_anything(node_class = SyntaxNode, inline_module = nil) click to toggle source

    # File lib/treetop/runtime/compiled_parser.rb, line 76
    def parse_anything(node_class = SyntaxNode, inline_module = nil)
      if index < input.length
        result = instantiate_node(node_class,input, index...(index + 1))
        result.extend(inline_module) if inline_module
        @index += 1
        result
      else
        terminal_parse_failure("any character")
      end
    end

prepare_to_parse(input) click to toggle source

    # File lib/treetop/runtime/compiled_parser.rb, line 62
    def prepare_to_parse(input)
      @input = input
      @input_length = input.length
      reset_index
      @node_cache = Hash.new {|hash, key| hash[key] = Hash.new}
      @regexps = {}
      @terminal_failures = []
      @max_terminal_failure_index = 0
    end

reset_index() click to toggle source

    # File lib/treetop/runtime/compiled_parser.rb, line 72
    def reset_index
      @index = 0
    end

terminal_parse_failure(expected_string) click to toggle source

    # File lib/treetop/runtime/compiled_parser.rb, line 104
    def terminal_parse_failure(expected_string)
      return nil if index < max_terminal_failure_index
      if index > max_terminal_failure_index
        @max_terminal_failure_index = index
        @terminal_failures = []
      end
      @terminal_failures << [index, expected_string]
      return nil
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.