treetop 0.1.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +3 -0
- data/Rakefile +35 -0
- data/bin/tt +25 -0
- data/lib/treetop.rb +10 -6
- data/lib/treetop/compiler.rb +7 -0
- data/lib/treetop/compiler/grammar_compiler.rb +21 -0
- data/lib/treetop/compiler/lexical_address_space.rb +17 -0
- data/lib/treetop/compiler/load_grammar.rb +7 -0
- data/lib/treetop/compiler/metagrammar.rb +2441 -0
- data/lib/treetop/compiler/metagrammar.treetop +384 -0
- data/lib/treetop/compiler/node_classes.rb +18 -0
- data/lib/treetop/compiler/node_classes/anything_symbol.rb +10 -0
- data/lib/treetop/compiler/node_classes/atomic_expression.rb +9 -0
- data/lib/treetop/compiler/node_classes/character_class.rb +10 -0
- data/lib/treetop/compiler/node_classes/choice.rb +31 -0
- data/lib/treetop/compiler/node_classes/declaration_sequence.rb +24 -0
- data/lib/treetop/compiler/node_classes/grammar.rb +28 -0
- data/lib/treetop/compiler/node_classes/inline_module.rb +27 -0
- data/lib/treetop/compiler/node_classes/nonterminal.rb +11 -0
- data/lib/treetop/compiler/node_classes/optional.rb +19 -0
- data/lib/treetop/compiler/node_classes/parenthesized_expression.rb +9 -0
- data/lib/treetop/compiler/node_classes/parsing_expression.rb +132 -0
- data/lib/treetop/compiler/node_classes/parsing_rule.rb +55 -0
- data/lib/treetop/compiler/node_classes/predicate.rb +45 -0
- data/lib/treetop/compiler/node_classes/repetition.rb +56 -0
- data/lib/treetop/compiler/node_classes/sequence.rb +64 -0
- data/lib/treetop/compiler/node_classes/terminal.rb +10 -0
- data/lib/treetop/compiler/node_classes/treetop_file.rb +9 -0
- data/lib/treetop/compiler/ruby_builder.rb +109 -0
- data/lib/treetop/ruby_extensions.rb +2 -0
- data/lib/treetop/ruby_extensions/string.rb +19 -0
- data/lib/treetop/runtime.rb +9 -0
- data/lib/treetop/runtime/compiled_parser.rb +66 -0
- data/lib/treetop/runtime/node_cache.rb +27 -0
- data/lib/treetop/runtime/parse_cache.rb +19 -0
- data/lib/treetop/runtime/parse_failure.rb +32 -0
- data/lib/treetop/runtime/parse_result.rb +30 -0
- data/lib/treetop/runtime/syntax_node.rb +53 -0
- data/lib/treetop/runtime/terminal_parse_failure.rb +33 -0
- data/lib/treetop/runtime/terminal_syntax_node.rb +12 -0
- data/test/compilation_target/target.rb +143 -0
- data/test/compilation_target/target.treetop +15 -0
- data/test/compilation_target/target_test.rb +56 -0
- data/test/compiler/and_predicate_test.rb +33 -0
- data/test/compiler/anything_symbol_test.rb +24 -0
- data/test/compiler/character_class_test.rb +45 -0
- data/test/compiler/choice_test.rb +49 -0
- data/test/compiler/circular_compilation_test.rb +20 -0
- data/test/compiler/failure_propagation_functional_test.rb +20 -0
- data/test/compiler/grammar_compiler_test.rb +58 -0
- data/test/compiler/grammar_test.rb +33 -0
- data/test/compiler/nonterminal_symbol_test.rb +15 -0
- data/test/compiler/not_predicate_test.rb +35 -0
- data/test/compiler/one_or_more_test.rb +30 -0
- data/test/compiler/optional_test.rb +32 -0
- data/test/compiler/parsing_rule_test.rb +30 -0
- data/test/compiler/sequence_test.rb +68 -0
- data/test/compiler/terminal_symbol_test.rb +35 -0
- data/test/compiler/test_grammar.treetop +7 -0
- data/test/compiler/zero_or_more_test.rb +51 -0
- data/test/composition/a.treetop +11 -0
- data/test/composition/b.treetop +11 -0
- data/test/composition/c.treetop +10 -0
- data/test/composition/d.treetop +10 -0
- data/test/composition/grammar_composition_test.rb +23 -0
- data/test/parser/syntax_node_test.rb +53 -0
- data/test/parser/terminal_parse_failure_test.rb +22 -0
- data/test/ruby_extensions/string_test.rb +33 -0
- data/test/screw/Rakefile +16 -0
- data/test/screw/unit.rb +37 -0
- data/test/screw/unit/assertion_failed_error.rb +14 -0
- data/test/screw/unit/assertions.rb +615 -0
- data/test/screw/unit/auto_runner.rb +227 -0
- data/test/screw/unit/collector.rb +45 -0
- data/test/screw/unit/collector/dir.rb +107 -0
- data/test/screw/unit/collector/objectspace.rb +28 -0
- data/test/screw/unit/error.rb +48 -0
- data/test/screw/unit/failure.rb +45 -0
- data/test/screw/unit/sugar.rb +25 -0
- data/test/screw/unit/test_case.rb +176 -0
- data/test/screw/unit/test_result.rb +73 -0
- data/test/screw/unit/test_suite.rb +70 -0
- data/test/screw/unit/ui.rb +4 -0
- data/test/screw/unit/ui/console/test_runner.rb +118 -0
- data/test/screw/unit/ui/fox/test_runner.rb +268 -0
- data/test/screw/unit/ui/gtk/test_runner.rb +416 -0
- data/test/screw/unit/ui/gtk2/testrunner.rb +465 -0
- data/test/screw/unit/ui/test_runner_mediator.rb +58 -0
- data/test/screw/unit/ui/test_runner_utilities.rb +46 -0
- data/test/screw/unit/ui/tk/test_runner.rb +260 -0
- data/test/screw/unit/util.rb +4 -0
- data/test/screw/unit/util/backtrace_filter.rb +40 -0
- data/test/screw/unit/util/observable.rb +82 -0
- data/test/screw/unit/util/proc_wrapper.rb +48 -0
- data/test/test_helper.rb +89 -0
- metadata +127 -69
- data/lib/treetop/api.rb +0 -3
- data/lib/treetop/api/load_grammar.rb +0 -16
- data/lib/treetop/api/malformed_grammar_exception.rb +0 -9
- data/lib/treetop/grammar.rb +0 -7
- data/lib/treetop/grammar/grammar.rb +0 -48
- data/lib/treetop/grammar/grammar_builder.rb +0 -35
- data/lib/treetop/grammar/parsing_expression_builder.rb +0 -5
- data/lib/treetop/grammar/parsing_expression_builder_helper.rb +0 -121
- data/lib/treetop/grammar/parsing_expressions.rb +0 -18
- data/lib/treetop/grammar/parsing_expressions/and_predicate.rb +0 -17
- data/lib/treetop/grammar/parsing_expressions/anything_symbol.rb +0 -20
- data/lib/treetop/grammar/parsing_expressions/character_class.rb +0 -24
- data/lib/treetop/grammar/parsing_expressions/node_instantiating_parsing_expression.rb +0 -14
- data/lib/treetop/grammar/parsing_expressions/node_propagating_parsing_expression.rb +0 -4
- data/lib/treetop/grammar/parsing_expressions/nonterminal_symbol.rb +0 -42
- data/lib/treetop/grammar/parsing_expressions/not_predicate.rb +0 -18
- data/lib/treetop/grammar/parsing_expressions/one_or_more.rb +0 -12
- data/lib/treetop/grammar/parsing_expressions/optional.rb +0 -14
- data/lib/treetop/grammar/parsing_expressions/ordered_choice.rb +0 -27
- data/lib/treetop/grammar/parsing_expressions/parsing_expression.rb +0 -36
- data/lib/treetop/grammar/parsing_expressions/predicate.rb +0 -25
- data/lib/treetop/grammar/parsing_expressions/repeating_parsing_expression.rb +0 -29
- data/lib/treetop/grammar/parsing_expressions/sequence.rb +0 -41
- data/lib/treetop/grammar/parsing_expressions/terminal_parsing_expression.rb +0 -11
- data/lib/treetop/grammar/parsing_expressions/terminal_symbol.rb +0 -31
- data/lib/treetop/grammar/parsing_expressions/zero_or_more.rb +0 -11
- data/lib/treetop/grammar/parsing_rule.rb +0 -10
- data/lib/treetop/metagrammar.rb +0 -2
- data/lib/treetop/metagrammar/metagrammar.rb +0 -14
- data/lib/treetop/metagrammar/metagrammar.treetop +0 -320
- data/lib/treetop/parser.rb +0 -11
- data/lib/treetop/parser/node_cache.rb +0 -25
- data/lib/treetop/parser/parse_cache.rb +0 -17
- data/lib/treetop/parser/parse_failure.rb +0 -22
- data/lib/treetop/parser/parse_result.rb +0 -26
- data/lib/treetop/parser/parser.rb +0 -24
- data/lib/treetop/parser/sequence_syntax_node.rb +0 -14
- data/lib/treetop/parser/syntax_node.rb +0 -31
- data/lib/treetop/parser/terminal_parse_failure.rb +0 -18
- data/lib/treetop/parser/terminal_syntax_node.rb +0 -7
- data/lib/treetop/protometagrammar.rb +0 -16
- data/lib/treetop/protometagrammar/anything_symbol_expression_builder.rb +0 -13
- data/lib/treetop/protometagrammar/block_expression_builder.rb +0 -17
- data/lib/treetop/protometagrammar/character_class_expression_builder.rb +0 -25
- data/lib/treetop/protometagrammar/grammar_expression_builder.rb +0 -38
- data/lib/treetop/protometagrammar/nonterminal_symbol_expression_builder.rb +0 -45
- data/lib/treetop/protometagrammar/ordered_choice_expression_builder.rb +0 -21
- data/lib/treetop/protometagrammar/parsing_rule_expression_builder.rb +0 -23
- data/lib/treetop/protometagrammar/parsing_rule_sequence_expression_builder.rb +0 -14
- data/lib/treetop/protometagrammar/prefix_expression_builder.rb +0 -25
- data/lib/treetop/protometagrammar/primary_expression_builder.rb +0 -71
- data/lib/treetop/protometagrammar/protometagrammar.rb +0 -25
- data/lib/treetop/protometagrammar/sequence_expression_builder.rb +0 -37
- data/lib/treetop/protometagrammar/suffix_expression_builder.rb +0 -33
- data/lib/treetop/protometagrammar/terminal_symbol_expression_builder.rb +0 -52
- data/lib/treetop/protometagrammar/trailing_block_expression_builder.rb +0 -30
- data/lib/treetop/ruby_extension.rb +0 -11
@@ -1,35 +0,0 @@
|
|
1
|
-
module Treetop
|
2
|
-
class GrammarBuilder
|
3
|
-
attr_accessor :grammar
|
4
|
-
include ParsingExpressionBuilderHelper
|
5
|
-
|
6
|
-
def initialize(grammar)
|
7
|
-
self.grammar = grammar
|
8
|
-
end
|
9
|
-
|
10
|
-
def build(&block)
|
11
|
-
instance_eval(&block)
|
12
|
-
end
|
13
|
-
|
14
|
-
def root(sym)
|
15
|
-
grammar.root = grammar.nonterminal_symbol(sym)
|
16
|
-
end
|
17
|
-
|
18
|
-
def rule(nonterminal_name, expression_or_expression_builder)
|
19
|
-
nonterminal_symbol = grammar.nonterminal_symbol(nonterminal_name)
|
20
|
-
parsing_expression = parsing_expression_for(expression_or_expression_builder)
|
21
|
-
|
22
|
-
grammar.add_parsing_rule(nonterminal_symbol, parsing_expression)
|
23
|
-
end
|
24
|
-
|
25
|
-
def parsing_expression_for(expression_or_expression_builder)
|
26
|
-
case expression_or_expression_builder
|
27
|
-
when ParsingExpression
|
28
|
-
return expression_or_expression_builder
|
29
|
-
when ParsingExpressionBuilder
|
30
|
-
expression_or_expression_builder.grammar = grammar
|
31
|
-
return expression_or_expression_builder.build
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,121 +0,0 @@
|
|
1
|
-
module Treetop
|
2
|
-
module ParsingExpressionBuilderHelper
|
3
|
-
attr_accessor :grammar
|
4
|
-
|
5
|
-
def nonterm(symbol)
|
6
|
-
grammar.nonterminal_symbol(symbol)
|
7
|
-
end
|
8
|
-
|
9
|
-
def term(string)
|
10
|
-
TerminalSymbol.new(string)
|
11
|
-
end
|
12
|
-
|
13
|
-
def exp(object, &block)
|
14
|
-
exp = case object
|
15
|
-
when String
|
16
|
-
term(object)
|
17
|
-
when Symbol
|
18
|
-
nonterm(object)
|
19
|
-
when ParsingExpression
|
20
|
-
object
|
21
|
-
when Array
|
22
|
-
object.map { |elt| exp(elt) }
|
23
|
-
else raise "Argument must be an instance of String, Symbol, or ParsingExpression"
|
24
|
-
end
|
25
|
-
exp.node_class_eval &block if block
|
26
|
-
exp
|
27
|
-
end
|
28
|
-
|
29
|
-
def any
|
30
|
-
AnythingSymbol.new
|
31
|
-
end
|
32
|
-
|
33
|
-
def char_class(char_class_string)
|
34
|
-
CharacterClass.new(char_class_string)
|
35
|
-
end
|
36
|
-
|
37
|
-
def andp(expression)
|
38
|
-
exp(expression).and_predicate
|
39
|
-
end
|
40
|
-
|
41
|
-
def notp(expression)
|
42
|
-
exp(expression).not_predicate
|
43
|
-
end
|
44
|
-
|
45
|
-
def optional(expression)
|
46
|
-
exp(expression).optional
|
47
|
-
end
|
48
|
-
|
49
|
-
def seq(*expressions, &block)
|
50
|
-
sequence = Sequence.new(exp(expressions))
|
51
|
-
sequence.node_class_eval &block if block
|
52
|
-
return sequence
|
53
|
-
end
|
54
|
-
|
55
|
-
def choice(*expressions)
|
56
|
-
OrderedChoice.new(exp(expressions))
|
57
|
-
end
|
58
|
-
|
59
|
-
def zero_or_more(expression)
|
60
|
-
exp(expression).zero_or_more
|
61
|
-
end
|
62
|
-
|
63
|
-
def one_or_more(expression)
|
64
|
-
exp(expression).one_or_more
|
65
|
-
end
|
66
|
-
|
67
|
-
def escaped(character)
|
68
|
-
seq('\\', character)
|
69
|
-
end
|
70
|
-
|
71
|
-
def zero_or_more_delimited(expression, delimiter, &block)
|
72
|
-
n_or_more_delimited(0, expression, delimiter, &block)
|
73
|
-
end
|
74
|
-
|
75
|
-
def two_or_more_delimited(expression, delimiter, &block)
|
76
|
-
n_or_more_delimited(2, expression, delimiter, &block)
|
77
|
-
end
|
78
|
-
|
79
|
-
def n_or_more_delimited(n, expression, delimiter, &block)
|
80
|
-
expression = exp(expression)
|
81
|
-
delimiter = exp(delimiter)
|
82
|
-
|
83
|
-
delimited_sequence = seq(delimited_sequence_head(n, expression),
|
84
|
-
delimited_sequence_tail(n, expression, delimiter)) do
|
85
|
-
def elements
|
86
|
-
return [] if super[0].epsilon?
|
87
|
-
[super[0]] + super[1].elements
|
88
|
-
end
|
89
|
-
end
|
90
|
-
delimited_sequence.node_class_eval(&block) if block
|
91
|
-
|
92
|
-
return delimited_sequence
|
93
|
-
end
|
94
|
-
|
95
|
-
def delimited_sequence_head(n, expression)
|
96
|
-
n == 0 ? optional(expression) : expression
|
97
|
-
end
|
98
|
-
|
99
|
-
def delimited_sequence_tail(n, expression, delimiter)
|
100
|
-
if n > 1
|
101
|
-
tail_elements = one_or_more(delimited_sequence_tail_element(n, expression, delimiter))
|
102
|
-
else
|
103
|
-
tail_elements = zero_or_more(delimited_sequence_tail_element(n, expression, delimiter))
|
104
|
-
end
|
105
|
-
tail_elements.node_class_eval do
|
106
|
-
def elements
|
107
|
-
super.map {|elt| elt.element}
|
108
|
-
end
|
109
|
-
end
|
110
|
-
return tail_elements
|
111
|
-
end
|
112
|
-
|
113
|
-
def delimited_sequence_tail_element(n, expression, delimiter)
|
114
|
-
seq(delimiter, expression) do
|
115
|
-
def element
|
116
|
-
elements[1]
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
dir = File.dirname(__FILE__)
|
2
|
-
require "#{dir}/parsing_expressions/parsing_expression"
|
3
|
-
require "#{dir}/parsing_expressions/node_instantiating_parsing_expression"
|
4
|
-
require "#{dir}/parsing_expressions/node_propagating_parsing_expression"
|
5
|
-
require "#{dir}/parsing_expressions/terminal_parsing_expression"
|
6
|
-
require "#{dir}/parsing_expressions/terminal_symbol"
|
7
|
-
require "#{dir}/parsing_expressions/anything_symbol"
|
8
|
-
require "#{dir}/parsing_expressions/character_class"
|
9
|
-
require "#{dir}/parsing_expressions/nonterminal_symbol"
|
10
|
-
require "#{dir}/parsing_expressions/sequence"
|
11
|
-
require "#{dir}/parsing_expressions/ordered_choice"
|
12
|
-
require "#{dir}/parsing_expressions/repeating_parsing_expression"
|
13
|
-
require "#{dir}/parsing_expressions/zero_or_more"
|
14
|
-
require "#{dir}/parsing_expressions/one_or_more"
|
15
|
-
require "#{dir}/parsing_expressions/optional"
|
16
|
-
require "#{dir}/parsing_expressions/predicate"
|
17
|
-
require "#{dir}/parsing_expressions/and_predicate"
|
18
|
-
require "#{dir}/parsing_expressions/not_predicate"
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Treetop
|
2
|
-
class AndPredicate < Predicate
|
3
|
-
def to_s
|
4
|
-
"&(#{expression.to_s})"
|
5
|
-
end
|
6
|
-
|
7
|
-
protected
|
8
|
-
|
9
|
-
def child_expression_success(index, input, result)
|
10
|
-
return success_at(index, input, [result])
|
11
|
-
end
|
12
|
-
|
13
|
-
def child_expression_failure(index, input, result)
|
14
|
-
return failure_at(index, [result])
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module Treetop
|
2
|
-
class AnythingSymbol < TerminalParsingExpression
|
3
|
-
def initialize
|
4
|
-
super
|
5
|
-
end
|
6
|
-
|
7
|
-
def parse_at(input, start_index, parser)
|
8
|
-
if start_index < input.length
|
9
|
-
interval = (start_index...(start_index + 1))
|
10
|
-
return node_class.new(input, interval)
|
11
|
-
else
|
12
|
-
TerminalParseFailure.new(start_index, self)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def to_s
|
17
|
-
'.'
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module Treetop
|
2
|
-
class CharacterClass < TerminalParsingExpression
|
3
|
-
|
4
|
-
attr_reader :char_class_string, :prefix_regex
|
5
|
-
|
6
|
-
def initialize(char_class_string)
|
7
|
-
super()
|
8
|
-
@char_class_string = char_class_string
|
9
|
-
@prefix_regex = Regexp.new("[#{char_class_string}]")
|
10
|
-
end
|
11
|
-
|
12
|
-
def parse_at(input, start_index, parser)
|
13
|
-
if input.index(prefix_regex, start_index) == start_index
|
14
|
-
return node_class.new(input, start_index...(start_index + 1))
|
15
|
-
else
|
16
|
-
TerminalParseFailure.new(start_index, self)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def to_s
|
21
|
-
return "[#{char_class_string}]"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module Treetop
|
2
|
-
class NodeInstantiatingParsingExpression < ParsingExpression
|
3
|
-
attr_reader :node_class
|
4
|
-
|
5
|
-
def initialize
|
6
|
-
@node_class = Class.new(node_superclass)
|
7
|
-
end
|
8
|
-
|
9
|
-
def node_class_eval(string = nil, &block)
|
10
|
-
node_class.class_eval(string) if string
|
11
|
-
node_class.class_eval(&block) if block
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
module Treetop
|
2
|
-
class NonterminalSymbol < NodePropagatingParsingExpression
|
3
|
-
attr_reader :name, :grammar
|
4
|
-
|
5
|
-
def initialize(name, grammar)
|
6
|
-
@name = name
|
7
|
-
@grammar = grammar
|
8
|
-
end
|
9
|
-
|
10
|
-
def parsing_expression
|
11
|
-
grammar.get_parsing_expression(self)
|
12
|
-
end
|
13
|
-
|
14
|
-
def to_s
|
15
|
-
name.to_s
|
16
|
-
end
|
17
|
-
|
18
|
-
def parse_at(input, start_index, parser)
|
19
|
-
node_cache = parser.node_cache_for(self)
|
20
|
-
if cached_result = node_cache[start_index]
|
21
|
-
return cached_result
|
22
|
-
else
|
23
|
-
return node_cache.store(parse_at_without_caching(input, start_index, parser))
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
protected
|
28
|
-
def parse_at_without_caching(input, start_index, parser)
|
29
|
-
result = parsing_expression.parse_at(input, start_index, parser)
|
30
|
-
|
31
|
-
if result.success?
|
32
|
-
result
|
33
|
-
else
|
34
|
-
return failure_at(start_index, result.nested_failures)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def node_cache(parser)
|
39
|
-
parser.node_cache_for(self)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module Treetop
|
2
|
-
class NotPredicate < Predicate
|
3
|
-
def to_s
|
4
|
-
"!(#{expression.to_s})"
|
5
|
-
end
|
6
|
-
|
7
|
-
protected
|
8
|
-
|
9
|
-
def child_expression_success(index, input, result)
|
10
|
-
return failure_at(index, [result])
|
11
|
-
end
|
12
|
-
|
13
|
-
def child_expression_failure(index, input, result)
|
14
|
-
return success_at(index, input, [result])
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module Treetop
|
2
|
-
class Optional < OrderedChoice
|
3
|
-
attr_reader :expression
|
4
|
-
|
5
|
-
def initialize(optional_expression)
|
6
|
-
super([optional_expression, TerminalSymbol.epsilon])
|
7
|
-
@expression = optional_expression
|
8
|
-
end
|
9
|
-
|
10
|
-
def to_s
|
11
|
-
"(#{expression.to_s})?"
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module Treetop
|
2
|
-
class OrderedChoice < NodePropagatingParsingExpression
|
3
|
-
attr_reader :alternatives
|
4
|
-
|
5
|
-
def initialize(alternatives)
|
6
|
-
@alternatives = alternatives
|
7
|
-
end
|
8
|
-
|
9
|
-
def to_s
|
10
|
-
parenthesize((alternatives.collect {|alt| alt.to_s}).join(" / "))
|
11
|
-
end
|
12
|
-
|
13
|
-
def parse_at(input, start_index, parser)
|
14
|
-
failures = []
|
15
|
-
for alt in alternatives
|
16
|
-
result = alt.parse_at(input, start_index, parser)
|
17
|
-
if result.success?
|
18
|
-
result.update_nested_failures(collect_nested_failures(failures))
|
19
|
-
return result
|
20
|
-
else
|
21
|
-
failures << result
|
22
|
-
end
|
23
|
-
end
|
24
|
-
return failure_at(start_index, failures)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
module Treetop
|
2
|
-
class ParsingExpression
|
3
|
-
def zero_or_more
|
4
|
-
ZeroOrMore.new(self)
|
5
|
-
end
|
6
|
-
|
7
|
-
def one_or_more
|
8
|
-
OneOrMore.new(self)
|
9
|
-
end
|
10
|
-
|
11
|
-
def optional
|
12
|
-
Optional.new(self)
|
13
|
-
end
|
14
|
-
|
15
|
-
def and_predicate
|
16
|
-
AndPredicate.new(self)
|
17
|
-
end
|
18
|
-
|
19
|
-
def not_predicate
|
20
|
-
NotPredicate.new(self)
|
21
|
-
end
|
22
|
-
|
23
|
-
def parenthesize(string)
|
24
|
-
"(#{string})"
|
25
|
-
end
|
26
|
-
|
27
|
-
protected
|
28
|
-
def failure_at(index, nested_results = [])
|
29
|
-
ParseFailure.new(index, collect_nested_failures(nested_results))
|
30
|
-
end
|
31
|
-
|
32
|
-
def collect_nested_failures(results)
|
33
|
-
(results.collect {|result| result.nested_failures}).flatten
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module Treetop
|
2
|
-
class Predicate < NodePropagatingParsingExpression
|
3
|
-
attr_reader :expression
|
4
|
-
|
5
|
-
def initialize(expression)
|
6
|
-
@expression = expression
|
7
|
-
end
|
8
|
-
|
9
|
-
def parse_at(input, start_index, parser)
|
10
|
-
result = expression.parse_at(input, start_index, parser)
|
11
|
-
|
12
|
-
if result.success?
|
13
|
-
return child_expression_success(start_index, input, result)
|
14
|
-
else
|
15
|
-
return child_expression_failure(start_index, input, result)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
protected
|
20
|
-
|
21
|
-
def success_at(index, input, nested_results)
|
22
|
-
SyntaxNode.new(input, index...index, collect_nested_failures(nested_results))
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|