treetop 1.5.3 → 1.6.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +5 -13
  2. data/Gemfile +12 -0
  3. data/History.txt +18 -0
  4. data/README.md +4 -0
  5. data/Rakefile +20 -40
  6. data/Treetop.tmbundle/Preferences/Comments.tmPreferences +28 -0
  7. data/Treetop.tmbundle/Snippets/grammar ___ end.tmSnippet +20 -0
  8. data/Treetop.tmbundle/Snippets/rule ___ end.tmSnippet +18 -0
  9. data/Treetop.tmbundle/Support/nibs/SyntaxTreeViewer.nib/designable.nib +1524 -0
  10. data/Treetop.tmbundle/Support/nibs/SyntaxTreeViewer.nib/keyedobjects.nib +0 -0
  11. data/Treetop.tmbundle/Support/syntax_tree_viewer.rb +117 -0
  12. data/Treetop.tmbundle/Syntaxes/Treetop Grammar.tmLanguage +358 -0
  13. data/Treetop.tmbundle/info.plist +10 -0
  14. data/doc/pitfalls_and_advanced_techniques.markdown +7 -1
  15. data/doc/syntactic_recognition.markdown +7 -2
  16. data/doc/tt.1 +1 -1
  17. data/examples/indented_blocks/indented_blocks.tt +73 -0
  18. data/examples/indented_blocks/indented_blocks_test.rb +24 -0
  19. data/lib/treetop/compiler/grammar_compiler.rb +6 -3
  20. data/lib/treetop/compiler/metagrammar.rb +301 -159
  21. data/lib/treetop/compiler/metagrammar.treetop +96 -13
  22. data/lib/treetop/compiler/node_classes/anything_symbol.rb +10 -2
  23. data/lib/treetop/compiler/node_classes/atomic_expression.rb +2 -2
  24. data/lib/treetop/compiler/node_classes/character_class.rb +10 -2
  25. data/lib/treetop/compiler/node_classes/choice.rb +11 -7
  26. data/lib/treetop/compiler/node_classes/nonterminal.rb +6 -2
  27. data/lib/treetop/compiler/node_classes/parenthesized_expression.rb +5 -1
  28. data/lib/treetop/compiler/node_classes/parsing_expression.rb +10 -1
  29. data/lib/treetop/compiler/node_classes/parsing_rule.rb +1 -1
  30. data/lib/treetop/compiler/node_classes/predicate.rb +8 -1
  31. data/lib/treetop/compiler/node_classes/predicate_block.rb +7 -0
  32. data/lib/treetop/compiler/node_classes/repetition.rb +28 -8
  33. data/lib/treetop/compiler/node_classes/sequence.rb +5 -1
  34. data/lib/treetop/compiler/node_classes/terminal.rb +36 -22
  35. data/lib/treetop/compiler/ruby_builder.rb +2 -2
  36. data/lib/treetop/ruby_extensions/string.rb +0 -6
  37. data/lib/treetop/runtime/compiled_parser.rb +33 -14
  38. data/lib/treetop/runtime/syntax_node.rb +24 -15
  39. data/lib/treetop/runtime/terminal_parse_failure.rb +4 -3
  40. data/lib/treetop/runtime/terminal_syntax_node.rb +4 -4
  41. data/lib/treetop/version.rb +2 -2
  42. data/treetop.gemspec +25 -165
  43. metadata +43 -98
  44. data/doc/site.rb +0 -112
  45. data/doc/sitegen.rb +0 -65
  46. data/examples/lambda_calculus/lambda_calculus +0 -0
  47. data/spec/compiler/and_predicate_spec.rb +0 -36
  48. data/spec/compiler/anything_symbol_spec.rb +0 -44
  49. data/spec/compiler/character_class_spec.rb +0 -301
  50. data/spec/compiler/choice_spec.rb +0 -80
  51. data/spec/compiler/circular_compilation_spec.rb +0 -30
  52. data/spec/compiler/failure_propagation_functional_spec.rb +0 -21
  53. data/spec/compiler/grammar_compiler_spec.rb +0 -113
  54. data/spec/compiler/grammar_spec.rb +0 -41
  55. data/spec/compiler/multibyte_chars_spec.rb +0 -38
  56. data/spec/compiler/namespace_spec.rb +0 -42
  57. data/spec/compiler/nonterminal_symbol_spec.rb +0 -40
  58. data/spec/compiler/not_predicate_spec.rb +0 -38
  59. data/spec/compiler/occurrence_range_spec.rb +0 -189
  60. data/spec/compiler/one_or_more_spec.rb +0 -35
  61. data/spec/compiler/optional_spec.rb +0 -37
  62. data/spec/compiler/parenthesized_expression_spec.rb +0 -19
  63. data/spec/compiler/parsing_rule_spec.rb +0 -61
  64. data/spec/compiler/repeated_subrule_spec.rb +0 -29
  65. data/spec/compiler/semantic_predicate_spec.rb +0 -175
  66. data/spec/compiler/sequence_spec.rb +0 -129
  67. data/spec/compiler/terminal_spec.rb +0 -170
  68. data/spec/compiler/terminal_symbol_spec.rb +0 -37
  69. data/spec/compiler/test_grammar.treetop +0 -7
  70. data/spec/compiler/test_grammar.tt +0 -7
  71. data/spec/compiler/test_grammar_do.treetop +0 -7
  72. data/spec/compiler/test_grammar_magic_coding.treetop +0 -8
  73. data/spec/compiler/test_grammar_magic_encoding.treetop +0 -8
  74. data/spec/compiler/tt_compiler_spec.rb +0 -224
  75. data/spec/compiler/zero_or_more_spec.rb +0 -56
  76. data/spec/composition/a.treetop +0 -11
  77. data/spec/composition/b.treetop +0 -11
  78. data/spec/composition/c.treetop +0 -10
  79. data/spec/composition/d.treetop +0 -10
  80. data/spec/composition/f.treetop +0 -17
  81. data/spec/composition/grammar_composition_spec.rb +0 -40
  82. data/spec/composition/subfolder/e_includes_c.treetop +0 -15
  83. data/spec/ruby_extensions/string_spec.rb +0 -32
  84. data/spec/runtime/compiled_parser_spec.rb +0 -123
  85. data/spec/runtime/interval_skip_list/delete_spec.rb +0 -147
  86. data/spec/runtime/interval_skip_list/expire_range_spec.rb +0 -349
  87. data/spec/runtime/interval_skip_list/insert_and_delete_node_spec.rb +0 -385
  88. data/spec/runtime/interval_skip_list/insert_spec.rb +0 -660
  89. data/spec/runtime/interval_skip_list/interval_skip_list_spec.graffle +0 -6175
  90. data/spec/runtime/interval_skip_list/interval_skip_list_spec.rb +0 -58
  91. data/spec/runtime/interval_skip_list/palindromic_fixture.rb +0 -35
  92. data/spec/runtime/interval_skip_list/palindromic_fixture_spec.rb +0 -163
  93. data/spec/runtime/interval_skip_list/spec_helper.rb +0 -91
  94. data/spec/runtime/syntax_node_spec.rb +0 -77
  95. data/spec/spec_helper.rb +0 -115
@@ -1,40 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module NonterminalSymbolSpec
4
- describe "A nonterminal symbol followed by a block" do
5
- testing_expression 'foo { def a_method; end }'
6
-
7
- parser_class_under_test.class_eval do
8
- def _nt_foo
9
- '_nt_foo called'
10
- end
11
- end
12
-
13
- it "compiles to a method call, extending its results with the anonymous module for the block" do
14
- result = parse('')
15
- result.should == '_nt_foo called'
16
- result.should respond_to(:a_method)
17
- end
18
- end
19
-
20
- module TestModule
21
- def a_method
22
- end
23
- end
24
-
25
- describe "a non-terminal followed by a module declaration" do
26
- testing_expression 'foo <NonterminalSymbolSpec::TestModule>'
27
-
28
- parser_class_under_test.class_eval do
29
- def _nt_foo
30
- '_nt_foo called'
31
- end
32
- end
33
-
34
- it "compiles to a method call, extending its results with the anonymous module for the block" do
35
- result = parse('')
36
- result.should == '_nt_foo called'
37
- result.should respond_to(:a_method)
38
- end
39
- end
40
- end
@@ -1,38 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module NotPredicateSpec
4
- describe "A !-predicated terminal symbol" do
5
- testing_expression '!"foo"'
6
-
7
- it "fails to parse input matching the terminal symbol" do
8
- parse('foo').should be_nil
9
- end
10
- end
11
-
12
- describe "A sequence of a terminal and an and another !-predicated terminal" do
13
- testing_expression '"foo" !"bar"'
14
-
15
- it "fails to match input matching both terminals" do
16
- parse('foobar').should be_nil
17
- end
18
-
19
- it "successfully parses input matching the first terminal and not the second, reporting the parse failure of the second terminal" do
20
- parse('foo') do |result|
21
- result.should_not be_nil
22
- terminal_failures = parser.terminal_failures
23
- terminal_failures.size.should == 1
24
- failure = terminal_failures.first
25
- failure.index.should == 3
26
- failure.expected_string.should == 'bar'
27
- end
28
- end
29
- end
30
-
31
- describe "A !-predicated sequence" do
32
- testing_expression '!("a" "b" "cc")'
33
-
34
- it "fails to parse matching input" do
35
- parse('abcc').should be_nil
36
- end
37
- end
38
- end
@@ -1,189 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module OccurrenceRangeSpec
4
- class Foo < Treetop::Runtime::SyntaxNode
5
- end
6
-
7
- describe "zero to two of a terminal symbol followed by a node class declaration and a block" do
8
- testing_expression '"foo"..2 <OccurrenceRangeSpec::Foo> { def a_method; end }'
9
-
10
- it "successfully parses epsilon, reporting a failure" do
11
- parse('') do |result|
12
- result.should_not be_nil
13
- result.should be_an_instance_of(Foo)
14
- result.should respond_to(:a_method)
15
-
16
- terminal_failures = parser.terminal_failures
17
- terminal_failures.size.should == 1
18
- failure = terminal_failures.first
19
- failure.index.should == 0
20
- failure.expected_string.should == 'foo'
21
- end
22
- end
23
-
24
- it "successfully parses epsilon, returning an instance declared node class and recording a terminal failure" do
25
- parse('') do |result|
26
- result.should_not be_nil
27
- result.should be_an_instance_of(Foo)
28
- result.should respond_to(:a_method)
29
-
30
- terminal_failures = parser.terminal_failures
31
- terminal_failures.size.should == 1
32
- failure = terminal_failures.first
33
- failure.index.should == 0
34
- failure.expected_string.should == 'foo'
35
- end
36
- end
37
-
38
- it "successfully parses one of that terminal, returning an instance of the declared node class and recording a terminal failure" do
39
- parse("foo") do |result|
40
- result.should_not be_nil
41
- result.should be_an_instance_of(Foo)
42
- result.should respond_to(:a_method)
43
-
44
- terminal_failures = parser.terminal_failures
45
- terminal_failures.size.should == 1
46
- failure = terminal_failures.first
47
- failure.index.should == 3
48
- failure.expected_string.should == 'foo'
49
- end
50
- end
51
-
52
- it "successfully parses two of that terminal, returning an instance of the declared node class and reporting no failure" do
53
- parse("foofoo") do |result|
54
- result.should_not be_nil
55
- result.should be_an_instance_of(Foo)
56
- result.should respond_to(:a_method)
57
-
58
- terminal_failures = parser.terminal_failures
59
- terminal_failures.size.should == 0
60
- end
61
- end
62
-
63
- it "fails to parses three of that terminal, returning an instance of the declared node class and reporting no failure" do
64
- parse("foofoofoo") do |result|
65
- result.should be_nil
66
-
67
- terminal_failures = parser.terminal_failures
68
- terminal_failures.size.should == 0
69
- end
70
- end
71
- end
72
-
73
- describe "two to four of a terminal symbol followed by a node class declaration and a block" do
74
- testing_expression '"foo" 2..4 <OccurrenceRangeSpec::Foo> { def a_method; end }'
75
-
76
- it "fails to parse epsilon, reporting a failure" do
77
- parse('') do |result|
78
- result.should be_nil
79
- terminal_failures = parser.terminal_failures
80
- terminal_failures.size.should == 1
81
- failure = terminal_failures.first
82
- failure.index.should == 0
83
- failure.expected_string.should == 'foo'
84
- end
85
- end
86
-
87
- it "fails to parse one of that terminal, returning an instance of the declared node class and recording a terminal failure" do
88
- parse("foo") do |result|
89
- result.should be_nil
90
-
91
- terminal_failures = parser.terminal_failures
92
- terminal_failures.size.should == 1
93
- failure = terminal_failures.first
94
- failure.index.should == 3
95
- failure.expected_string.should == 'foo'
96
- end
97
- end
98
-
99
- it "successfully parses two of that terminal, returning an instance of the declared node class and reporting no failure" do
100
- parse("foofoo") do |result|
101
- result.should_not be_nil
102
- result.should be_an_instance_of(Foo)
103
- result.should respond_to(:a_method)
104
-
105
- terminal_failures = parser.terminal_failures
106
- terminal_failures.size.should == 1
107
- failure = terminal_failures.first
108
- failure.index.should == 6
109
- failure.expected_string.should == 'foo'
110
- end
111
- end
112
-
113
- it "successfully parses four of that terminal, returning an instance of the declared node class and reporting no failure" do
114
- parse("foofoofoofoo") do |result|
115
- result.should_not be_nil
116
- result.should be_an_instance_of(Foo)
117
- result.should respond_to(:a_method)
118
-
119
- terminal_failures = parser.terminal_failures
120
- terminal_failures.size.should == 0
121
- end
122
- end
123
-
124
- it "fails to parses five of that terminal, returning an instance of the declared node class and reporting no failure" do
125
- parse("foofoofoofoofoo") do |result|
126
- result.should be_nil
127
-
128
- terminal_failures = parser.terminal_failures
129
- terminal_failures.size.should == 0
130
- end
131
- end
132
- end
133
-
134
- describe "two to any number of a terminal symbol followed by a node class declaration and a block" do
135
- testing_expression '"foo" 2.. <OccurrenceRangeSpec::Foo> { def a_method; end }'
136
-
137
- it "fails to parse epsilon, reporting a failure" do
138
- parse('') do |result|
139
- result.should be_nil
140
- terminal_failures = parser.terminal_failures
141
- terminal_failures.size.should == 1
142
- failure = terminal_failures.first
143
- failure.index.should == 0
144
- failure.expected_string.should == 'foo'
145
- end
146
- end
147
-
148
- it "fails to parse one of that terminal, returning an instance of the declared node class and recording a terminal failure" do
149
- parse("foo") do |result|
150
- result.should be_nil
151
-
152
- terminal_failures = parser.terminal_failures
153
- terminal_failures.size.should == 1
154
- failure = terminal_failures.first
155
- failure.index.should == 3
156
- failure.expected_string.should == 'foo'
157
- end
158
- end
159
-
160
- it "successfully parses two of that terminal, returning an instance of the declared node class and reporting no failure" do
161
- parse("foofoo") do |result|
162
- result.should_not be_nil
163
- result.should be_an_instance_of(Foo)
164
- result.should respond_to(:a_method)
165
-
166
- terminal_failures = parser.terminal_failures
167
- terminal_failures.size.should == 1
168
- failure = terminal_failures.first
169
- failure.index.should == 6
170
- failure.expected_string.should == 'foo'
171
- end
172
- end
173
-
174
- it "successfully parses four of that terminal, returning an instance of the declared node class and reporting a failure on the fifth" do
175
- parse("foofoofoofoo") do |result|
176
- result.should_not be_nil
177
- result.should be_an_instance_of(Foo)
178
- result.should respond_to(:a_method)
179
-
180
- terminal_failures = parser.terminal_failures
181
- terminal_failures.size.should == 1
182
- failure = terminal_failures.first
183
- failure.index.should == 12
184
- failure.expected_string.should == 'foo'
185
- end
186
- end
187
- end
188
-
189
- end
@@ -1,35 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module OneOrMoreSpec
4
- class Foo < Treetop::Runtime::SyntaxNode
5
- end
6
-
7
- describe "one or more of a terminal symbol followed by a node class declaration and a block" do
8
- testing_expression '"foo"+ <OneOrMoreSpec::Foo> { def a_method; end }'
9
-
10
- it "fails to parse epsilon, reporting a failure" do
11
- parse('') do |result|
12
- result.should be_nil
13
- terminal_failures = parser.terminal_failures
14
- terminal_failures.size.should == 1
15
- failure = terminal_failures.first
16
- failure.index.should == 0
17
- failure.expected_string.should == 'foo'
18
- end
19
- end
20
-
21
- it "successfully parses two of that terminal in a row, returning an instance of the declared node class and reporting the failure the third parsing attempt" do
22
- parse("foofoo") do |result|
23
- result.should_not be_nil
24
- result.should be_an_instance_of(Foo)
25
- result.should respond_to(:a_method)
26
-
27
- terminal_failures = parser.terminal_failures
28
- terminal_failures.size.should == 1
29
- failure = terminal_failures.first
30
- failure.index.should == 6
31
- failure.expected_string.should == 'foo'
32
- end
33
- end
34
- end
35
- end
@@ -1,37 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module OptionalSpec
4
- describe "An optional terminal symbol" do
5
- testing_expression '"foo"?'
6
-
7
- it "parses input matching the terminal" do
8
- parse('foo').should_not be_nil
9
- end
10
-
11
- it "parses epsilon, recording a failure" do
12
- parse('') do |result|
13
- result.should_not be_nil
14
- result.interval.should == (0...0)
15
-
16
- terminal_failures = parser.terminal_failures
17
- terminal_failures.size.should == 1
18
- failure = terminal_failures.first
19
- failure.index.should == 0
20
- failure.expected_string.should == 'foo'
21
- end
22
- end
23
-
24
- it "parses input not matching the terminal, returning an epsilon result and recording a failure" do
25
- parse('bar', :consume_all_input => false) do |result|
26
- result.should_not be_nil
27
- result.interval.should == (0...0)
28
-
29
- terminal_failures = parser.terminal_failures
30
- terminal_failures.size.should == 1
31
- failure = terminal_failures.first
32
- failure.index.should == 0
33
- failure.expected_string.should == 'foo'
34
- end
35
- end
36
- end
37
- end
@@ -1,19 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module ParenthesizedExpressionSpec
4
- describe "An unadorned expression inside of parentheses" do
5
- testing_expression '("foo")'
6
-
7
- it "should behave as normal" do
8
- parse('foo').should_not be_nil
9
- end
10
- end
11
-
12
- describe "A prefixed-expression inside of parentheses" do
13
- testing_expression '(!"foo")'
14
-
15
- it "should behave as normal" do
16
- parse('foo').should be_nil
17
- end
18
- end
19
- end
@@ -1,61 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module ParsingRuleSpec
4
- describe "a grammar with one parsing rule" do
5
-
6
- testing_grammar %{
7
- grammar Foo
8
- rule bar
9
- "baz"
10
- end
11
- end
12
- }
13
-
14
- it "stores and retrieves nodes in its node cache" do
15
- parser = self.class.const_get(:FooParser).new
16
- parser.send(:prepare_to_parse, 'baz')
17
- node_cache = parser.send(:node_cache)
18
-
19
- node_cache[:bar][0].should be_nil
20
-
21
- parser._nt_bar
22
-
23
- cached_node = node_cache[:bar][0]
24
- cached_node.should be_an_instance_of(Runtime::SyntaxNode)
25
- cached_node.text_value.should == 'baz'
26
-
27
- parser.instance_eval { @index = 0 }
28
- parser._nt_bar.should equal(cached_node)
29
- parser.index.should == cached_node.interval.end
30
- end
31
- end
32
-
33
-
34
- describe "a grammar with choice that uses the cache and has a subsequent expression" do
35
- testing_grammar %{
36
- grammar Logic
37
- rule expression
38
- value_plus
39
- /
40
- value
41
- end
42
-
43
- rule value_plus
44
- value "something else"
45
- end
46
-
47
- rule value
48
- [a-z]
49
- /
50
- "foobar" # the subsequent expression that needs cached.interval.end
51
- end
52
- end
53
- }
54
-
55
- it "parses a single-character value and generates a node from the cache" do
56
- result = parse('a')
57
- result.should be_a(Treetop::Runtime::SyntaxNode)
58
- result.elements.should be_nil
59
- end
60
- end
61
- end
@@ -1,29 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module RepeatedSubruleSpec
4
- describe "a repeated subrule" do
5
- testing_grammar %{
6
- grammar Foo
7
- rule foo
8
- a:'a' space b:'b' space 'cc'
9
- end
10
-
11
- rule space
12
- ' '
13
- end
14
- end
15
- }
16
-
17
- it "should produce a parser having sequence-numbered node accessor methods" do
18
- parse("a b cc") do |result|
19
- result.should_not be_nil
20
- result.should respond_to(:space1)
21
- result.should respond_to(:space2)
22
- result.should_not respond_to(:space)
23
- result.should respond_to(:a)
24
- result.should respond_to(:b)
25
- result.should_not respond_to(:c)
26
- end
27
- end
28
- end
29
- end
@@ -1,175 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module SemanticPredicateSpec
4
- describe "An &-predicate block" do
5
- testing_expression '& {|| $ok_to_succeed}'
6
-
7
- it "succeeds if it returns true, returning an epsilon syntax node" do
8
- $ok_to_succeed = true
9
- parse('foo', :consume_all_input => false) do |result|
10
- result.should_not be_nil
11
- result.interval.should == (0...0)
12
- end
13
- end
14
-
15
- it "fails if it returns false" do
16
- $ok_to_succeed = false
17
- parse('foo', :consume_all_input => false) do |result|
18
- result.should be_nil
19
- terminal_failures = parser.terminal_failures
20
- terminal_failures.size.should == 0
21
- end
22
- end
23
-
24
- end
25
-
26
- describe "A sequence of a terminal and an &-predicate block" do
27
- testing_expression '"prior " &{|s| $value = s[0].text_value; $ok_to_succeed }'
28
-
29
- it "matches the input terminal and consumes it if the block returns true, seeing the terminal in the sequence" do
30
- $ok_to_succeed = true
31
- $value = nil
32
- parse('prior foo', :consume_all_input => false) do |result|
33
- result.should_not be_nil
34
- result.elements[0].text_value.should == "prior "
35
- result.text_value.should == 'prior '
36
- $value.should == 'prior '
37
- end
38
- end
39
-
40
- it "fails if the block returns false, but sees the terminal in the sequence" do
41
- $ok_to_succeed = false
42
- $value = nil
43
- parse('prior foo', :consume_all_input => false) do |result|
44
- result.should be_nil
45
- $value.should == 'prior '
46
- terminal_failures = parser.terminal_failures
47
- terminal_failures.size.should == 0
48
- end
49
- end
50
-
51
- end
52
-
53
- describe "A sequence of an optional terminal and an &-predicate block" do
54
- testing_expression '"prior "? &{|s| $value = s[0].text_value; $ok_to_succeed}'
55
-
56
- it "matches the input terminal and consumes it if the block returns true" do
57
- $ok_to_succeed = true
58
- parse('prior foo', :consume_all_input => false) do |result|
59
- result.should_not be_nil
60
- result.elements[0].text_value.should == "prior "
61
- result.text_value.should == 'prior '
62
- $value.should == 'prior '
63
- end
64
- end
65
-
66
- it "fails with no terminal_failures if the block returns false" do
67
- $ok_to_succeed = false
68
- parse('prior foo', :consume_all_input => false) do |result|
69
- result.should be_nil
70
- $value.should == 'prior '
71
- terminal_failures = parser.terminal_failures
72
- terminal_failures.size.should == 0
73
- end
74
- end
75
-
76
- it "fail and return the expected optional preceeding terminal as expected input if the block returns false" do
77
- $ok_to_succeed = false
78
- parse('foo', :consume_all_input => false) do |result|
79
- result.should be_nil
80
- terminal_failures = parser.terminal_failures
81
- terminal_failures.size.should == 1
82
- failure = terminal_failures[0]
83
- failure.index.should == 0
84
- failure.expected_string.should == 'prior '
85
- end
86
- end
87
-
88
- end
89
-
90
- describe "A !-predicate block" do
91
- testing_expression '! {|| $ok_to_succeed}'
92
-
93
- it "succeeds if it returns false, returning an epsilon syntax node" do
94
- $ok_to_succeed = false
95
- parse('foo', :consume_all_input => false) do |result|
96
- result.should_not be_nil
97
- result.interval.should == (0...0)
98
- end
99
- end
100
-
101
- it "fails if it returns true" do
102
- $ok_to_succeed = true
103
- parse('foo', :consume_all_input => false) do |result|
104
- result.should be_nil
105
- terminal_failures = parser.terminal_failures
106
- terminal_failures.size.should == 0
107
- end
108
- end
109
-
110
- end
111
-
112
- describe "A sequence of a terminal and an !-predicate block" do
113
- testing_expression '"prior " !{|s| $value = s[0].text_value; $ok_to_succeed }'
114
-
115
- it "matches the input terminal and consumes it if the block returns false, seeing the terminal in the sequence" do
116
- $ok_to_succeed = false
117
- $value = nil
118
- parse('prior foo', :consume_all_input => false) do |result|
119
- result.should_not be_nil
120
- result.elements[0].text_value.should == "prior "
121
- result.text_value.should == 'prior '
122
- $value.should == 'prior '
123
- end
124
- end
125
-
126
- it "fails if the block returns true, but sees the terminal in the sequence" do
127
- $ok_to_succeed = true
128
- $value = nil
129
- parse('prior foo', :consume_all_input => false) do |result|
130
- result.should be_nil
131
- $value.should == 'prior '
132
- terminal_failures = parser.terminal_failures
133
- terminal_failures.size.should == 0
134
- end
135
- end
136
-
137
- end
138
-
139
- describe "A sequence of an optional terminal and an !-predicate block" do
140
- testing_expression '"prior "? !{|s| $value = s[0].text_value; $ok_to_succeed}'
141
-
142
- it "matches the input terminal and consumes it if the block returns false" do
143
- $ok_to_succeed = false
144
- parse('prior foo', :consume_all_input => false) do |result|
145
- result.should_not be_nil
146
- result.elements[0].text_value.should == "prior "
147
- result.text_value.should == 'prior '
148
- $value.should == 'prior '
149
- end
150
- end
151
-
152
- it "fails with no terminal_failures if the block returns true" do
153
- $ok_to_succeed = true
154
- parse('prior foo', :consume_all_input => false) do |result|
155
- result.should be_nil
156
- $value.should == 'prior '
157
- terminal_failures = parser.terminal_failures
158
- terminal_failures.size.should == 0
159
- end
160
- end
161
-
162
- it "fail and return the expected optional preceeding terminal as expected input if the block returns true" do
163
- $ok_to_succeed = true
164
- parse('foo', :consume_all_input => false) do |result|
165
- result.should be_nil
166
- terminal_failures = parser.terminal_failures
167
- terminal_failures.size.should == 1
168
- failure = terminal_failures[0]
169
- failure.index.should == 0
170
- failure.expected_string.should == 'prior '
171
- end
172
- end
173
-
174
- end
175
- end