treetop 1.6.5 → 1.6.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/lib/treetop/compiler/metagrammar.rb +32 -3
  3. data/lib/treetop/compiler/metagrammar.treetop +32 -3
  4. data/lib/treetop/compiler/node_classes/anything_symbol.rb +7 -3
  5. data/lib/treetop/compiler/node_classes/atomic_expression.rb +2 -2
  6. data/lib/treetop/compiler/node_classes/character_class.rb +5 -1
  7. data/lib/treetop/compiler/node_classes/choice.rb +3 -3
  8. data/lib/treetop/compiler/node_classes/nonterminal.rb +4 -0
  9. data/lib/treetop/compiler/node_classes/parenthesized_expression.rb +1 -1
  10. data/lib/treetop/compiler/node_classes/parsing_expression.rb +7 -8
  11. data/lib/treetop/compiler/node_classes/parsing_rule.rb +1 -1
  12. data/lib/treetop/compiler/node_classes/predicate.rb +6 -6
  13. data/lib/treetop/compiler/node_classes/predicate_block.rb +1 -1
  14. data/lib/treetop/compiler/node_classes/repetition.rb +14 -14
  15. data/lib/treetop/compiler/node_classes/sequence.rb +1 -1
  16. data/lib/treetop/compiler/node_classes/terminal.rb +32 -28
  17. data/lib/treetop/runtime/compiled_parser.rb +12 -12
  18. data/lib/treetop/runtime/syntax_node.rb +15 -15
  19. data/lib/treetop/runtime/terminal_parse_failure.rb +2 -2
  20. data/lib/treetop/runtime/terminal_syntax_node.rb +4 -4
  21. data/lib/treetop/version.rb +1 -1
  22. data/spec/compiler/anything_symbol_spec.rb +2 -2
  23. data/spec/compiler/character_class_spec.rb +3 -3
  24. data/spec/compiler/grammar_spec.rb +2 -2
  25. data/spec/compiler/not_predicate_spec.rb +6 -6
  26. data/spec/compiler/occurrence_range_spec.rb +4 -4
  27. data/spec/compiler/parenthesized_expression_spec.rb +5 -5
  28. data/spec/compiler/semantic_predicate_spec.rb +7 -7
  29. data/spec/compiler/terminal_spec.rb +6 -6
  30. data/spec/compiler/terminal_symbol_spec.rb +2 -2
  31. data/spec/runtime/compiled_parser_spec.rb +7 -7
  32. data/spec/spec_helper.rb +6 -1
  33. data/treetop.gemspec +12 -21
  34. metadata +8 -17
  35. data/spec/runtime/interval_skip_list/delete_spec.rb +0 -147
  36. data/spec/runtime/interval_skip_list/expire_range_spec.rb +0 -349
  37. data/spec/runtime/interval_skip_list/insert_and_delete_node_spec.rb +0 -385
  38. data/spec/runtime/interval_skip_list/insert_spec.rb +0 -660
  39. data/spec/runtime/interval_skip_list/interval_skip_list_spec.graffle +0 -6175
  40. data/spec/runtime/interval_skip_list/interval_skip_list_spec.rb +0 -58
  41. data/spec/runtime/interval_skip_list/palindromic_fixture.rb +0 -35
  42. data/spec/runtime/interval_skip_list/palindromic_fixture_spec.rb +0 -163
  43. data/spec/runtime/interval_skip_list/spec_helper.rb +0 -91
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 31803050a59c177ca4e26b9ba24396bfc169ec46
4
- data.tar.gz: aa85232de5ed5dcb4368c9f8943dcb62b9068a97
3
+ metadata.gz: f6c63e11a7cd088f719f8fefa071cee15cceb8de
4
+ data.tar.gz: 4ab071ec035ca3d1e6348335643c2cb547c8426d
5
5
  SHA512:
6
- metadata.gz: b11615a2b1020389b4c836d7bec5faa91b194a73d917ec14dd366c49330e13a1e1a14886f6e0c1042fa1752c97a5fa3b9e19d9687a54bdd01f932b9cbed594ca
7
- data.tar.gz: 7bbe7339b97970098e054457f189e0504cabeeef1c1c1c1d8fbb03a99a517eb472221c02fd271b364fdefebfb25eb9da72c5ea63f77777edd0a0843dd7ca4b50
6
+ metadata.gz: 742cb0ea64d92e63f27c0742881eefb6098ec36f2c492828d2f4626ce11935fc9702c8f1a10e8adbc1dbd33149b912c97f2341a4d01678efb2f0efb62038c4ee
7
+ data.tar.gz: b06ab49b6d5ec07dfffbc7403036073d1cc6557343d53c025b43f5ea7986dd8ba888ed552de57296ef12b526e38968f2c16930a47251b558283fde5d2b19aadd
@@ -1078,6 +1078,10 @@ module Treetop
1078
1078
  def inline_modules
1079
1079
  (alternatives.map {|alt| alt.inline_modules }).flatten
1080
1080
  end
1081
+
1082
+ def inline_module
1083
+ nil
1084
+ end
1081
1085
  end
1082
1086
 
1083
1087
  def _nt_choice
@@ -1192,6 +1196,10 @@ module Treetop
1192
1196
  parent_modules
1193
1197
  end
1194
1198
 
1199
+ def inline_module
1200
+ node_class_declarations.inline_module
1201
+ end
1202
+
1195
1203
  def inline_module_name
1196
1204
  node_class_declarations.inline_module_name
1197
1205
  end
@@ -1435,6 +1443,10 @@ module Treetop
1435
1443
  atomic.inline_modules
1436
1444
  end
1437
1445
 
1446
+ def inline_module
1447
+ atomic.inline_module
1448
+ end
1449
+
1438
1450
  def inline_module_name
1439
1451
  nil
1440
1452
  end
@@ -1463,6 +1475,9 @@ module Treetop
1463
1475
  def inline_modules
1464
1476
  []
1465
1477
  end
1478
+ def inline_module
1479
+ nil
1480
+ end
1466
1481
  end
1467
1482
 
1468
1483
  module Primary4
@@ -1481,7 +1496,9 @@ module Treetop
1481
1496
 
1482
1497
  module Primary5
1483
1498
  def compile(address, builder, parent_expression=nil)
1484
- # STDERR.puts "Extraneous module ignored after suffix: #{input[interval].inspect}" if node_class_declarations.inline_modules.size > 0 && atomic.inline_modules.size > 0
1499
+ if node_class_declarations.inline_module && atomic.inline_module
1500
+ STDERR.puts "Extraneous module ignored after suffix: #{input[interval].inspect}"
1501
+ end
1485
1502
  suffix.compile(address, builder, self)
1486
1503
  end
1487
1504
 
@@ -1501,6 +1518,10 @@ module Treetop
1501
1518
  atomic.inline_modules + parent_modules
1502
1519
  end
1503
1520
 
1521
+ def inline_module
1522
+ node_class_declarations.inline_module
1523
+ end
1524
+
1504
1525
  def inline_module_name
1505
1526
  node_class_declarations.inline_module_name
1506
1527
  end
@@ -1518,7 +1539,9 @@ module Treetop
1518
1539
 
1519
1540
  module Primary7
1520
1541
  def compile(address, builder, parent_expression=nil)
1521
- STDERR.puts "Extraneous module ignored with nested atomic: #{input[interval].inspect}" if node_class_declarations.inline_modules.size > 0 && atomic.inline_modules.size > 0
1542
+ if node_class_declarations.inline_module && atomic.inline_module
1543
+ STDERR.puts "Extraneous module ignored with nested atomic: #{input[interval].inspect}"
1544
+ end
1522
1545
  atomic.compile(address, builder, self)
1523
1546
  end
1524
1547
 
@@ -1534,6 +1557,10 @@ module Treetop
1534
1557
  atomic.inline_modules + parent_modules
1535
1558
  end
1536
1559
 
1560
+ def inline_module
1561
+ node_class_declarations.inline_module
1562
+ end
1563
+
1537
1564
  def inline_module_name
1538
1565
  node_class_declarations.inline_module_name
1539
1566
  end
@@ -2202,7 +2229,6 @@ module Treetop
2202
2229
  node_class_expression.node_class_name
2203
2230
  end
2204
2231
 
2205
- # !!!! cjh !!!!!
2206
2232
  def inline_modules
2207
2233
  trailing_inline_module.inline_modules
2208
2234
  end
@@ -2496,6 +2522,9 @@ module Treetop
2496
2522
  def inline_modules
2497
2523
  parsing_expression.inline_modules
2498
2524
  end
2525
+ def inline_module
2526
+ parsing_expression.inline_module
2527
+ end
2499
2528
  end
2500
2529
 
2501
2530
  def _nt_parenthesized_expression
@@ -91,6 +91,10 @@ module Treetop
91
91
  def inline_modules
92
92
  (alternatives.map {|alt| alt.inline_modules }).flatten
93
93
  end
94
+
95
+ def inline_module
96
+ nil
97
+ end
94
98
  }
95
99
  end
96
100
 
@@ -114,6 +118,10 @@ module Treetop
114
118
  parent_modules
115
119
  end
116
120
 
121
+ def inline_module
122
+ node_class_declarations.inline_module
123
+ end
124
+
117
125
  def inline_module_name
118
126
  node_class_declarations.inline_module_name
119
127
  end
@@ -166,6 +174,10 @@ module Treetop
166
174
  atomic.inline_modules
167
175
  end
168
176
 
177
+ def inline_module
178
+ atomic.inline_module
179
+ end
180
+
169
181
  def inline_module_name
170
182
  nil
171
183
  end
@@ -184,11 +196,16 @@ module Treetop
184
196
  def inline_modules
185
197
  []
186
198
  end
199
+ def inline_module
200
+ nil
201
+ end
187
202
  }
188
203
  /
189
204
  atomic suffix node_class_declarations {
190
205
  def compile(address, builder, parent_expression=nil)
191
- # STDERR.puts "Extraneous module ignored after suffix: #{input[interval].inspect}" if node_class_declarations.inline_modules.size > 0 && atomic.inline_modules.size > 0
206
+ if node_class_declarations.inline_module && atomic.inline_module
207
+ STDERR.puts "Extraneous module ignored after suffix: #{input[interval].inspect}"
208
+ end
192
209
  suffix.compile(address, builder, self)
193
210
  end
194
211
 
@@ -208,6 +225,10 @@ module Treetop
208
225
  atomic.inline_modules + parent_modules
209
226
  end
210
227
 
228
+ def inline_module
229
+ node_class_declarations.inline_module
230
+ end
231
+
211
232
  def inline_module_name
212
233
  node_class_declarations.inline_module_name
213
234
  end
@@ -215,7 +236,9 @@ module Treetop
215
236
  /
216
237
  atomic node_class_declarations {
217
238
  def compile(address, builder, parent_expression=nil)
218
- STDERR.puts "Extraneous module ignored with nested atomic: #{input[interval].inspect}" if node_class_declarations.inline_modules.size > 0 && atomic.inline_modules.size > 0
239
+ if node_class_declarations.inline_module && atomic.inline_module
240
+ STDERR.puts "Extraneous module ignored with nested atomic: #{input[interval].inspect}"
241
+ end
219
242
  atomic.compile(address, builder, self)
220
243
  end
221
244
 
@@ -231,6 +254,10 @@ module Treetop
231
254
  atomic.inline_modules + parent_modules
232
255
  end
233
256
 
257
+ def inline_module
258
+ node_class_declarations.inline_module
259
+ end
260
+
234
261
  def inline_module_name
235
262
  node_class_declarations.inline_module_name
236
263
  end
@@ -382,7 +409,6 @@ module Treetop
382
409
  node_class_expression.node_class_name
383
410
  end
384
411
 
385
- # !!!! cjh !!!!!
386
412
  def inline_modules
387
413
  trailing_inline_module.inline_modules
388
414
  end
@@ -425,6 +451,9 @@ module Treetop
425
451
  def inline_modules
426
452
  parsing_expression.inline_modules
427
453
  end
454
+ def inline_module
455
+ parsing_expression.inline_module
456
+ end
428
457
  }
429
458
  end
430
459
 
@@ -5,8 +5,8 @@ module Treetop
5
5
  super
6
6
  builder.if__ "index < input_length" do
7
7
  if address == 0 || decorated?
8
- assign_result "instantiate_node(#{node_class_name},input, index...(index + 1))"
9
- extend_result_with_inline_module parent_expression
8
+ assign_result "instantiate_node(#{node_class_name},input, index...(index + 1))"
9
+ extend_result_with_inline_module parent_expression
10
10
  else
11
11
  assign_lazily_instantiated_node
12
12
  end
@@ -19,7 +19,11 @@ module Treetop
19
19
  end
20
20
 
21
21
  def expected
22
- '"any character"'
22
+ '"any character"'
23
+ end
24
+
25
+ def inline_module
26
+ nil
23
27
  end
24
28
  end
25
29
  end
@@ -6,8 +6,8 @@ module Treetop
6
6
  end
7
7
 
8
8
  def single_quote(string)
9
- # Double any backslashes, then backslash any single-quotes:
10
- "'#{string.gsub(/\\/) { '\\\\' }.gsub(/'/) { "\\'"}}'"
9
+ # Double any backslashes, then backslash any single-quotes:
10
+ "'#{string.gsub(/\\/) { '\\\\' }.gsub(/'/) { "\\'"}}'"
11
11
  end
12
12
  end
13
13
  end
@@ -20,7 +20,11 @@ module Treetop
20
20
  end
21
21
 
22
22
  def expected
23
- single_quote('['+characters+']')
23
+ single_quote('['+characters+']')
24
+ end
25
+
26
+ def inline_module
27
+ nil
24
28
  end
25
29
 
26
30
  def grounded_regexp(string)
@@ -13,8 +13,8 @@ module Treetop
13
13
  obtain_new_subexpression_address
14
14
  alternatives.first.compile(subexpression_address, builder)
15
15
  builder.if__ subexpression_success? do
16
- # Undo lazy instantiation:
17
- builder << "#{subexpression_result_var} = SyntaxNode.new(input, (index-1)...index) if #{subexpression_result_var} == true"
16
+ # Undo lazy instantiation:
17
+ builder << "#{subexpression_result_var} = SyntaxNode.new(input, (index-1)...index) if #{subexpression_result_var} == true"
18
18
  assign_result subexpression_result_var
19
19
  extend_result_with_declared_module
20
20
  extend_result_with_inline_module parent_expression
@@ -30,7 +30,7 @@ module Treetop
30
30
  end
31
31
 
32
32
  def expected
33
- '"(any alternative)"'
33
+ '"(any alternative)"'
34
34
  end
35
35
  end
36
36
  end
@@ -8,6 +8,10 @@ module Treetop
8
8
  extend_result_with_declared_module
9
9
  extend_result_with_inline_module parent_expression
10
10
  end
11
+
12
+ def inline_module
13
+ nil
14
+ end
11
15
  end
12
16
  end
13
17
  end
@@ -6,7 +6,7 @@ module Treetop
6
6
  end
7
7
 
8
8
  def expected
9
- elements[2].expected
9
+ elements[2].expected
10
10
  end
11
11
  end
12
12
  end
@@ -79,13 +79,12 @@ module Treetop
79
79
  end
80
80
 
81
81
  def extend_result_with_inline_module parent_expression = nil
82
- # debugger if parent_expression && !parent_expression.respond_to?(:parent_modules)
83
- if parent_expression && parent_expression.parent_modules.size > 0
84
- parent_expression.parent_modules.each do |inline|
85
- extend_result inline.module_name
86
- end
87
- end
88
- extend_result inline_module_name if inline_module_name
82
+ if parent_expression && parent_expression.parent_modules.size > 0
83
+ parent_expression.parent_modules.each do |inline|
84
+ extend_result inline.module_name
85
+ end
86
+ end
87
+ extend_result inline_module_name if inline_module_name
89
88
  end
90
89
 
91
90
  def reset_index
@@ -149,7 +148,7 @@ module Treetop
149
148
  end
150
149
 
151
150
  def expected
152
- nil # Overridden for terminal parse failures
151
+ nil # Overridden for terminal parse failures
153
152
  end
154
153
  end
155
154
  end
@@ -33,7 +33,7 @@ module Treetop
33
33
 
34
34
  def generate_cache_lookup(builder)
35
35
  builder.if_ "node_cache[:#{name}].has_key?(index)" do
36
- cache_address = "node_cache[:#{name}][index]"
36
+ cache_address = "node_cache[:#{name}][index]"
37
37
  builder.assign 'cached', cache_address
38
38
  builder.if_ "cached" do
39
39
  # Handle lazily instantiated nodes:
@@ -36,15 +36,15 @@ module Treetop
36
36
  class NotPredicate < Predicate
37
37
  def when_success
38
38
  assign_failure
39
- if (e = parent.atomic.expected)
40
- builder << "terminal_parse_failure(#{e}, true)"
41
- end
39
+ if (e = parent.atomic.expected)
40
+ builder << "terminal_parse_failure(#{e}, true)"
41
+ end
42
42
  end
43
43
 
44
44
  def when_failure
45
- if (e = parent.atomic.expected)
46
- builder << "@terminal_failures.pop"
47
- end
45
+ if (e = parent.atomic.expected)
46
+ builder << "@terminal_failures.pop"
47
+ end
48
48
  assign_success
49
49
  end
50
50
  end
@@ -16,7 +16,7 @@ module Treetop
16
16
  end
17
17
 
18
18
  def expected
19
- '"<semantic predicate>"' # Should I include (some of) the text_value here?
19
+ '"<semantic predicate>"' # Should I include (some of) the text_value here?
20
20
  end
21
21
  end
22
22
  end
@@ -65,7 +65,7 @@ module Treetop
65
65
  end
66
66
 
67
67
  def expected
68
- parent_expression.atomic.expected && '"at least one "+'+parent_expression.atomic.expected
68
+ parent_expression.atomic.expected && '"at least one "+'+parent_expression.atomic.expected
69
69
  end
70
70
  end
71
71
 
@@ -78,30 +78,30 @@ module Treetop
78
78
  builder.if__ "#{accumulator_var}.size < #{min.text_value}" do
79
79
  reset_index
80
80
  assign_failure start_index_var
81
- end
81
+ end
82
82
  builder.else_ do
83
- clean_unsaturated
84
- assign_and_extend_result parent_expression
85
- end
83
+ clean_unsaturated
84
+ assign_and_extend_result parent_expression
85
+ end
86
86
  else
87
- clean_unsaturated
88
- assign_and_extend_result parent_expression
89
- end
87
+ clean_unsaturated
88
+ assign_and_extend_result parent_expression
89
+ end
90
90
 
91
91
  end_comment(parent_expression)
92
92
  end
93
93
 
94
94
  # remove the last terminal_failure if we merely failed to reach the maximum
95
95
  def clean_unsaturated
96
- if !max.empty? && max.text_value.to_i > 0
97
- builder.if_ "#{accumulator_var}.size < #{max.text_value}" do
98
- builder << '@terminal_failures.pop' # Ignore the last failure.
99
- end
100
- end
96
+ if !max.empty? && max.text_value.to_i > 0
97
+ builder.if_ "#{accumulator_var}.size < #{max.text_value}" do
98
+ builder << '@terminal_failures.pop' # Ignore the last failure.
99
+ end
100
+ end
101
101
  end
102
102
 
103
103
  def expected
104
- parent_expression.atomic.expected && "at least #{min.text_value} "+parent_expression.atomic.expected
104
+ parent_expression.atomic.expected && "at least #{min.text_value} "+parent_expression.atomic.expected
105
105
  end
106
106
  end
107
107
 
@@ -42,7 +42,7 @@ module Treetop
42
42
  end
43
43
 
44
44
  def expected
45
- '"<a sequence>"'
45
+ '"<a sequence>"'
46
46
  end
47
47
  end
48
48
 
@@ -3,38 +3,38 @@ module Treetop
3
3
  class Terminal < AtomicExpression
4
4
  def compile(address, builder, parent_expression = nil)
5
5
  super
6
- # Handle modifiers:
7
- insensitive = modifiers.text_value.include? 'i'
8
- re = modifiers.text_value.include? 'r'
9
- if re
10
- grounded_regexp = "#{('\A'+eval(string)).inspect}"
11
- cache_key = "'__#{modifiers.text_value}__'+(gr = #{grounded_regexp})"
12
- re_modifiers = "#{insensitive ? 'Regexp::IGNORECASE' : 0}"
13
- str = "@regexps[#{cache_key}] ||= Regexp.new(gr, #{re_modifiers})"
14
- mode = ':regexp'
15
- elsif insensitive
16
- str = string.downcase
17
- string_length = eval(str).length
18
- mode = ':insens'
19
- else
20
- str = string
21
- string_length = eval(str).length
22
- mode = 'false'
23
- end
6
+ # Handle modifiers:
7
+ insensitive = modifiers.text_value.include? 'i'
8
+ re = modifiers.text_value.include? 'r'
9
+ if re
10
+ grounded_regexp = "#{('\A'+eval(string)).inspect}"
11
+ cache_key = "'__#{modifiers.text_value}__'+(gr = #{grounded_regexp})"
12
+ re_modifiers = "#{insensitive ? 'Regexp::IGNORECASE' : 0}"
13
+ str = "@regexps[#{cache_key}] ||= Regexp.new(gr, #{re_modifiers})"
14
+ mode = ':regexp'
15
+ elsif insensitive
16
+ str = string.downcase
17
+ string_length = eval(str).length
18
+ mode = ':insens'
19
+ else
20
+ str = string
21
+ string_length = eval(str).length
22
+ mode = 'false'
23
+ end
24
24
 
25
25
  builder.if__ "(match_len = has_terminal?(#{str}, #{mode}, index))" do
26
26
  if address == 0 || decorated? || mode != 'false' || string_length > 1
27
- assign_result "instantiate_node(#{node_class_name},input, index...(index + match_len))"
28
- # debugger if parent_expression and parent_expression.inline_modules.size > 0
29
- # extend_result_with_inline_module parent_expression
30
- if parent_expression
31
- parent_expression.inline_modules.each do |inline|
32
- extend_result inline.module_name
33
- end
34
- end
27
+ assign_result "instantiate_node(#{node_class_name},input, index...(index + match_len))"
28
+ # debugger if parent_expression and parent_expression.inline_modules.size > 0
29
+ # extend_result_with_inline_module parent_expression
30
+ if parent_expression
31
+ parent_expression.inline_modules.each do |inline|
32
+ extend_result inline.module_name
33
+ end
34
+ end
35
35
  else
36
36
  assign_lazily_instantiated_node
37
- end
37
+ end
38
38
  builder << "@index += match_len"
39
39
  end
40
40
  builder.else_ do
@@ -44,7 +44,11 @@ module Treetop
44
44
  end
45
45
 
46
46
  def expected
47
- single_quote(string)
47
+ single_quote(string)
48
+ end
49
+
50
+ def inline_module
51
+ nil
48
52
  end
49
53
  end
50
54
  end