Parent

Included Modules

Files

Class Index [+]

Quicksearch

Treetop::Runtime::CompiledParser

Attributes

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

Public Class Methods

new() click to toggle source
    # File lib/treetop/runtime/compiled_parser.rb, line 11
11:       def initialize
12:         self.consume_all_input = true
13:       end

Public Instance Methods

failure_column() click to toggle source
    # File lib/treetop/runtime/compiled_parser.rb, line 33
33:       def failure_column
34:         @terminal_failures && input.column_of(failure_index)
35:       end
failure_index() click to toggle source
    # File lib/treetop/runtime/compiled_parser.rb, line 25
25:       def failure_index
26:         max_terminal_failure_index
27:       end
failure_line() click to toggle source
    # File lib/treetop/runtime/compiled_parser.rb, line 29
29:       def failure_line
30:         @terminal_failures && input.line_of(failure_index)
31:       end
failure_reason() click to toggle source
    # File lib/treetop/runtime/compiled_parser.rb, line 37
37:       def failure_reason
38:         return nil unless (tf = terminal_failures) && tf.size > 0
39:         "Expected " +
40:           (tf.size == 1 ?
41:            tf[0].expected_string :
42:                  "one of #{tf.map{|f| f.expected_string}.uniq*', '}"
43:           ) +
44:                 " at line #{failure_line}, column #{failure_column} (byte #{failure_index+1})" +
45:                 " after #{input[index...failure_index]}"
46:       end
parse(input, options = {}) click to toggle source
    # File lib/treetop/runtime/compiled_parser.rb, line 15
15:       def parse(input, options = {})
16:         prepare_to_parse(input)
17:         @index = options[:index] if options[:index]
18:         result = send("_nt_#{options[:root] || root}")
19:         should_consume_all = options.include?(:consume_all_input) ? options[:consume_all_input] : consume_all_input?
20:         return nil if (should_consume_all && index != input.size)
21:         return SyntaxNode.new(input, index...(index + 1)) if result == true
22:         return result
23:       end
terminal_failures() click to toggle source
    # File lib/treetop/runtime/compiled_parser.rb, line 48
48:       def terminal_failures
49:         if @terminal_failures.empty? || @terminal_failures[0].is_a?(TerminalParseFailure)
50:           @terminal_failures
51:         else
52:           @terminal_failures.map! {|tf_ary| TerminalParseFailure.new(*tf_ary) }
53:         end
54:       end

Protected Instance Methods

has_terminal?(terminal, regex, index) click to toggle source
     # File lib/treetop/runtime/compiled_parser.rb, line 95
 95:       def has_terminal?(terminal, regex, index)
 96:         if regex
 97:           rx = @regexps[terminal] ||= Regexp.new(terminal)
 98:           input.index(rx, index) == index
 99:         else
100:           input[index, terminal.size] == terminal
101:         end
102:       end
instantiate_node(node_type,*args) click to toggle source
    # File lib/treetop/runtime/compiled_parser.rb, line 87
87:       def instantiate_node(node_type,*args)
88:         if node_type.respond_to? :new
89:           node_type.new(*args)
90:         else
91:           SyntaxNode.new(*args).extend(node_type)
92:         end
93:       end
parse_anything(node_class = SyntaxNode, inline_module = nil) click to toggle source
    # File lib/treetop/runtime/compiled_parser.rb, line 76
76:       def parse_anything(node_class = SyntaxNode, inline_module = nil)
77:         if index < input.length
78:           result = instantiate_node(node_class,input, index...(index + 1))
79:           result.extend(inline_module) if inline_module
80:           @index += 1
81:           result
82:         else
83:           terminal_parse_failure("any character")
84:         end
85:       end
prepare_to_parse(input) click to toggle source
    # File lib/treetop/runtime/compiled_parser.rb, line 62
62:       def prepare_to_parse(input)
63:         @input = input
64:         @input_length = input.length
65:         reset_index
66:         @node_cache = Hash.new {|hash, key| hash[key] = Hash.new}
67:         @regexps = {}
68:         @terminal_failures = []
69:         @max_terminal_failure_index = 0
70:       end
reset_index() click to toggle source
    # File lib/treetop/runtime/compiled_parser.rb, line 72
72:       def reset_index
73:         @index = 0
74:       end
terminal_parse_failure(expected_string) click to toggle source
     # File lib/treetop/runtime/compiled_parser.rb, line 104
104:       def terminal_parse_failure(expected_string)
105:         return nil if index < max_terminal_failure_index
106:         if index > max_terminal_failure_index
107:           @max_terminal_failure_index = index
108:           @terminal_failures = []
109:         end
110:         @terminal_failures << [index, expected_string]
111:         return nil
112:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.