treetop 1.5.3 → 1.6.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/Gemfile +12 -0
- data/History.txt +18 -0
- data/README.md +4 -0
- data/Rakefile +20 -40
- data/Treetop.tmbundle/Preferences/Comments.tmPreferences +28 -0
- data/Treetop.tmbundle/Snippets/grammar ___ end.tmSnippet +20 -0
- data/Treetop.tmbundle/Snippets/rule ___ end.tmSnippet +18 -0
- data/Treetop.tmbundle/Support/nibs/SyntaxTreeViewer.nib/designable.nib +1524 -0
- data/Treetop.tmbundle/Support/nibs/SyntaxTreeViewer.nib/keyedobjects.nib +0 -0
- data/Treetop.tmbundle/Support/syntax_tree_viewer.rb +117 -0
- data/Treetop.tmbundle/Syntaxes/Treetop Grammar.tmLanguage +358 -0
- data/Treetop.tmbundle/info.plist +10 -0
- data/doc/pitfalls_and_advanced_techniques.markdown +7 -1
- data/doc/syntactic_recognition.markdown +7 -2
- data/doc/tt.1 +1 -1
- data/examples/indented_blocks/indented_blocks.tt +73 -0
- data/examples/indented_blocks/indented_blocks_test.rb +24 -0
- data/lib/treetop/compiler/grammar_compiler.rb +6 -3
- data/lib/treetop/compiler/metagrammar.rb +301 -159
- data/lib/treetop/compiler/metagrammar.treetop +96 -13
- data/lib/treetop/compiler/node_classes/anything_symbol.rb +10 -2
- data/lib/treetop/compiler/node_classes/atomic_expression.rb +2 -2
- data/lib/treetop/compiler/node_classes/character_class.rb +10 -2
- data/lib/treetop/compiler/node_classes/choice.rb +11 -7
- data/lib/treetop/compiler/node_classes/nonterminal.rb +6 -2
- data/lib/treetop/compiler/node_classes/parenthesized_expression.rb +5 -1
- data/lib/treetop/compiler/node_classes/parsing_expression.rb +10 -1
- data/lib/treetop/compiler/node_classes/parsing_rule.rb +1 -1
- data/lib/treetop/compiler/node_classes/predicate.rb +8 -1
- data/lib/treetop/compiler/node_classes/predicate_block.rb +7 -0
- data/lib/treetop/compiler/node_classes/repetition.rb +28 -8
- data/lib/treetop/compiler/node_classes/sequence.rb +5 -1
- data/lib/treetop/compiler/node_classes/terminal.rb +36 -22
- data/lib/treetop/compiler/ruby_builder.rb +2 -2
- data/lib/treetop/ruby_extensions/string.rb +0 -6
- data/lib/treetop/runtime/compiled_parser.rb +33 -14
- data/lib/treetop/runtime/syntax_node.rb +24 -15
- data/lib/treetop/runtime/terminal_parse_failure.rb +4 -3
- data/lib/treetop/runtime/terminal_syntax_node.rb +4 -4
- data/lib/treetop/version.rb +2 -2
- data/treetop.gemspec +25 -165
- metadata +43 -98
- data/doc/site.rb +0 -112
- data/doc/sitegen.rb +0 -65
- data/examples/lambda_calculus/lambda_calculus +0 -0
- data/spec/compiler/and_predicate_spec.rb +0 -36
- data/spec/compiler/anything_symbol_spec.rb +0 -44
- data/spec/compiler/character_class_spec.rb +0 -301
- data/spec/compiler/choice_spec.rb +0 -80
- data/spec/compiler/circular_compilation_spec.rb +0 -30
- data/spec/compiler/failure_propagation_functional_spec.rb +0 -21
- data/spec/compiler/grammar_compiler_spec.rb +0 -113
- data/spec/compiler/grammar_spec.rb +0 -41
- data/spec/compiler/multibyte_chars_spec.rb +0 -38
- data/spec/compiler/namespace_spec.rb +0 -42
- data/spec/compiler/nonterminal_symbol_spec.rb +0 -40
- data/spec/compiler/not_predicate_spec.rb +0 -38
- data/spec/compiler/occurrence_range_spec.rb +0 -189
- data/spec/compiler/one_or_more_spec.rb +0 -35
- data/spec/compiler/optional_spec.rb +0 -37
- data/spec/compiler/parenthesized_expression_spec.rb +0 -19
- data/spec/compiler/parsing_rule_spec.rb +0 -61
- data/spec/compiler/repeated_subrule_spec.rb +0 -29
- data/spec/compiler/semantic_predicate_spec.rb +0 -175
- data/spec/compiler/sequence_spec.rb +0 -129
- data/spec/compiler/terminal_spec.rb +0 -170
- data/spec/compiler/terminal_symbol_spec.rb +0 -37
- data/spec/compiler/test_grammar.treetop +0 -7
- data/spec/compiler/test_grammar.tt +0 -7
- data/spec/compiler/test_grammar_do.treetop +0 -7
- data/spec/compiler/test_grammar_magic_coding.treetop +0 -8
- data/spec/compiler/test_grammar_magic_encoding.treetop +0 -8
- data/spec/compiler/tt_compiler_spec.rb +0 -224
- data/spec/compiler/zero_or_more_spec.rb +0 -56
- data/spec/composition/a.treetop +0 -11
- data/spec/composition/b.treetop +0 -11
- data/spec/composition/c.treetop +0 -10
- data/spec/composition/d.treetop +0 -10
- data/spec/composition/f.treetop +0 -17
- data/spec/composition/grammar_composition_spec.rb +0 -40
- data/spec/composition/subfolder/e_includes_c.treetop +0 -15
- data/spec/ruby_extensions/string_spec.rb +0 -32
- data/spec/runtime/compiled_parser_spec.rb +0 -123
- data/spec/runtime/interval_skip_list/delete_spec.rb +0 -147
- data/spec/runtime/interval_skip_list/expire_range_spec.rb +0 -349
- data/spec/runtime/interval_skip_list/insert_and_delete_node_spec.rb +0 -385
- data/spec/runtime/interval_skip_list/insert_spec.rb +0 -660
- data/spec/runtime/interval_skip_list/interval_skip_list_spec.graffle +0 -6175
- data/spec/runtime/interval_skip_list/interval_skip_list_spec.rb +0 -58
- data/spec/runtime/interval_skip_list/palindromic_fixture.rb +0 -35
- data/spec/runtime/interval_skip_list/palindromic_fixture_spec.rb +0 -163
- data/spec/runtime/interval_skip_list/spec_helper.rb +0 -91
- data/spec/runtime/syntax_node_spec.rb +0 -77
- data/spec/spec_helper.rb +0 -115
@@ -1,385 +0,0 @@
|
|
1
|
-
require 'runtime/interval_skip_list/spec_helper'
|
2
|
-
|
3
|
-
shared_examples_for "it is non-empty" do
|
4
|
-
specify "#empty? returns false" do
|
5
|
-
list.should_not be_empty
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
shared_examples_for "#nodes is an array of the three inserted nodes in key order" do
|
10
|
-
specify "#nodes is an array of the three inserted nodes in key order" do
|
11
|
-
list.nodes.should == inserted_nodes.sort_by(&:key)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
shared_examples_for "it has nil forward pointers" do
|
16
|
-
it "has nil forward pointers" do
|
17
|
-
inserted_node.forward.each do |next_pointer|
|
18
|
-
next_pointer.should be_nil
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe IntervalSkipList do
|
24
|
-
attr_reader :list
|
25
|
-
|
26
|
-
before do
|
27
|
-
@list = IntervalSkipList.new
|
28
|
-
end
|
29
|
-
|
30
|
-
describe " when nothing has been inserted" do
|
31
|
-
specify "#empty? returns true" do
|
32
|
-
list.should be_empty
|
33
|
-
end
|
34
|
-
|
35
|
-
specify "#nodes returns an empty array" do
|
36
|
-
list.nodes.should == []
|
37
|
-
end
|
38
|
-
|
39
|
-
describe "#head" do
|
40
|
-
attr_reader :head
|
41
|
-
|
42
|
-
before do
|
43
|
-
@head = list.head
|
44
|
-
end
|
45
|
-
|
46
|
-
it "#has a height of #max_height" do
|
47
|
-
head.height.should == list.max_height
|
48
|
-
end
|
49
|
-
|
50
|
-
it "has nil forward pointers" do
|
51
|
-
0.upto(list.max_height - 1) do |i|
|
52
|
-
head.forward[i].should be_nil
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe " when 1 has been inserted", :deterministic => true do
|
59
|
-
attr_reader :inserted_node, :inserted_nodes
|
60
|
-
|
61
|
-
def expected_node_heights
|
62
|
-
[1]
|
63
|
-
end
|
64
|
-
|
65
|
-
include NextNodeHeightIsDeterministicSharedContext
|
66
|
-
|
67
|
-
before do
|
68
|
-
@inserted_node = list.insert_node(1)
|
69
|
-
@inserted_nodes = [@inserted_node]
|
70
|
-
end
|
71
|
-
|
72
|
-
it_should_behave_like "it is non-empty"
|
73
|
-
it_should_behave_like "#nodes is an array of the three inserted nodes in key order"
|
74
|
-
|
75
|
-
describe "#head" do
|
76
|
-
attr_reader :head
|
77
|
-
|
78
|
-
before do
|
79
|
-
@head = list.head
|
80
|
-
end
|
81
|
-
|
82
|
-
it "has inserted_node.height forward pointers pointing at the inserted node" do
|
83
|
-
0.upto(inserted_node.height - 1) do |i|
|
84
|
-
head.forward[i].should == inserted_node
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
it "has the rest of its forward pointers pointing at nil" do
|
89
|
-
inserted_node.height.upto(list.max_height - 1) do |i|
|
90
|
-
head.forward[i].should == nil
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
describe "the inserted node" do
|
96
|
-
it_should_behave_like "it has nil forward pointers"
|
97
|
-
|
98
|
-
it "has a height of the expected_node_heights.first" do
|
99
|
-
inserted_node.height.should == expected_node_heights.first
|
100
|
-
end
|
101
|
-
|
102
|
-
it "has a key of 1" do
|
103
|
-
inserted_node.key.should == 1
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
describe "and subsequently deleted" do
|
108
|
-
before do
|
109
|
-
list.delete_node(1)
|
110
|
-
end
|
111
|
-
|
112
|
-
specify "#empty? returns true" do
|
113
|
-
list.should be_empty
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
describe " when 1 and 3 have been inserted in order", :deterministic => true do
|
119
|
-
attr_reader :inserted_nodes
|
120
|
-
|
121
|
-
def expected_node_heights
|
122
|
-
[1, 2]
|
123
|
-
end
|
124
|
-
|
125
|
-
include NextNodeHeightIsDeterministicSharedContext
|
126
|
-
|
127
|
-
before do
|
128
|
-
@inserted_nodes = []
|
129
|
-
inserted_nodes << list.insert_node(1)
|
130
|
-
inserted_nodes << list.insert_node(3)
|
131
|
-
end
|
132
|
-
|
133
|
-
it_should_behave_like "it is non-empty"
|
134
|
-
it_should_behave_like "#nodes is an array of the three inserted nodes in key order"
|
135
|
-
|
136
|
-
describe "the first inserted node" do
|
137
|
-
attr_reader :inserted_node
|
138
|
-
|
139
|
-
before do
|
140
|
-
@inserted_node = inserted_nodes[0]
|
141
|
-
end
|
142
|
-
|
143
|
-
it "has a key of 1" do
|
144
|
-
inserted_node.key.should == 1
|
145
|
-
end
|
146
|
-
|
147
|
-
it "has a height of the first expected node height" do
|
148
|
-
inserted_node.height.should == expected_node_heights[0]
|
149
|
-
end
|
150
|
-
|
151
|
-
it "has its single forward pointer pointing at the second inserted node" do
|
152
|
-
inserted_node.forward[0].should == inserted_nodes[1]
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
describe "the second inserted node" do
|
157
|
-
attr_reader :inserted_node
|
158
|
-
|
159
|
-
before do
|
160
|
-
@inserted_node = inserted_nodes[1]
|
161
|
-
end
|
162
|
-
|
163
|
-
it_should_behave_like "it has nil forward pointers"
|
164
|
-
|
165
|
-
it "has a key of 3" do
|
166
|
-
inserted_node.key.should == 3
|
167
|
-
end
|
168
|
-
|
169
|
-
it "has a height of the second expected node height" do
|
170
|
-
inserted_node.height.should == expected_node_heights[1]
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
describe "and 1 is subsequently deleted" do
|
175
|
-
before do
|
176
|
-
list.delete_node(1)
|
177
|
-
end
|
178
|
-
|
179
|
-
describe "the remaining node" do
|
180
|
-
attr_reader :inserted_node
|
181
|
-
|
182
|
-
before do
|
183
|
-
@inserted_node = inserted_nodes[1]
|
184
|
-
end
|
185
|
-
|
186
|
-
it "is the first node in the list" do
|
187
|
-
inserted_node.should == list.nodes[0]
|
188
|
-
end
|
189
|
-
|
190
|
-
it_should_behave_like "it has nil forward pointers"
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
describe "and 3 is subsequently deleted" do
|
195
|
-
before do
|
196
|
-
list.delete_node(3)
|
197
|
-
end
|
198
|
-
|
199
|
-
describe "the remaining node" do
|
200
|
-
attr_reader :inserted_node
|
201
|
-
|
202
|
-
before do
|
203
|
-
@inserted_node = inserted_nodes[0]
|
204
|
-
end
|
205
|
-
|
206
|
-
it "is the first node in the list" do
|
207
|
-
inserted_node.should == list.nodes[0]
|
208
|
-
end
|
209
|
-
|
210
|
-
it_should_behave_like "it has nil forward pointers"
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
describe " when 1, 3 and 7 have been inserted in order", :deterministic => true do
|
216
|
-
attr_reader :inserted_nodes
|
217
|
-
|
218
|
-
def expected_node_heights
|
219
|
-
[1, 2, 1]
|
220
|
-
end
|
221
|
-
|
222
|
-
include NextNodeHeightIsDeterministicSharedContext
|
223
|
-
|
224
|
-
before do
|
225
|
-
@inserted_nodes = []
|
226
|
-
inserted_nodes << list.insert_node(1)
|
227
|
-
inserted_nodes << list.insert_node(3)
|
228
|
-
inserted_nodes << list.insert_node(7)
|
229
|
-
end
|
230
|
-
|
231
|
-
it_should_behave_like "it is non-empty"
|
232
|
-
it_should_behave_like "#nodes is an array of the three inserted nodes in key order"
|
233
|
-
|
234
|
-
describe "the first inserted node" do
|
235
|
-
attr_reader :inserted_node
|
236
|
-
|
237
|
-
before do
|
238
|
-
@inserted_node = inserted_nodes[0]
|
239
|
-
end
|
240
|
-
|
241
|
-
it "has a key of 1" do
|
242
|
-
inserted_node.key.should == 1
|
243
|
-
end
|
244
|
-
|
245
|
-
it "has a height of the first expected node height" do
|
246
|
-
inserted_node.height.should == expected_node_heights[0]
|
247
|
-
end
|
248
|
-
|
249
|
-
it "has its single forward pointer pointing at the second inserted node" do
|
250
|
-
inserted_node.forward[0].should == inserted_nodes[1]
|
251
|
-
end
|
252
|
-
end
|
253
|
-
|
254
|
-
describe "the second inserted node" do
|
255
|
-
attr_reader :inserted_node
|
256
|
-
|
257
|
-
before do
|
258
|
-
@inserted_node = inserted_nodes[1]
|
259
|
-
end
|
260
|
-
|
261
|
-
it "has a key of 3" do
|
262
|
-
inserted_node.key.should == 3
|
263
|
-
end
|
264
|
-
|
265
|
-
it "has a height of the second expected node height" do
|
266
|
-
inserted_node.height.should == expected_node_heights[1]
|
267
|
-
end
|
268
|
-
|
269
|
-
it "has a forward pointer at level 0 pointing to the third inserted node" do
|
270
|
-
inserted_node.forward[0].should == inserted_nodes[2]
|
271
|
-
end
|
272
|
-
|
273
|
-
it "has nil forward pointer at level 1" do
|
274
|
-
inserted_node.forward[1].should be_nil
|
275
|
-
end
|
276
|
-
end
|
277
|
-
|
278
|
-
describe "the third inserted node" do
|
279
|
-
attr_reader :inserted_node
|
280
|
-
|
281
|
-
before do
|
282
|
-
@inserted_node = inserted_nodes[2]
|
283
|
-
end
|
284
|
-
|
285
|
-
it_should_behave_like "it has nil forward pointers"
|
286
|
-
|
287
|
-
it "has a key of 3" do
|
288
|
-
inserted_node.key.should == 7
|
289
|
-
end
|
290
|
-
|
291
|
-
it "has a height of the third expected node height" do
|
292
|
-
inserted_node.height.should == expected_node_heights[2]
|
293
|
-
end
|
294
|
-
end
|
295
|
-
|
296
|
-
describe "and 3 is subsequently deleted" do
|
297
|
-
before do
|
298
|
-
list.delete_node(3)
|
299
|
-
end
|
300
|
-
|
301
|
-
specify "#head points at nil at levels 1 and 2" do
|
302
|
-
list.head.forward[1].should be_nil
|
303
|
-
list.head.forward[2].should be_nil
|
304
|
-
end
|
305
|
-
|
306
|
-
specify "#nodes contains the remaining nodes in order" do
|
307
|
-
list.nodes.should == [inserted_nodes[0], inserted_nodes[2]]
|
308
|
-
end
|
309
|
-
end
|
310
|
-
end
|
311
|
-
|
312
|
-
describe " when 7, 1 and 3 have been inserted in order", :deterministic => true do
|
313
|
-
attr_reader :inserted_nodes
|
314
|
-
|
315
|
-
def expected_node_heights
|
316
|
-
[1, 1, 2]
|
317
|
-
end
|
318
|
-
|
319
|
-
include NextNodeHeightIsDeterministicSharedContext
|
320
|
-
|
321
|
-
before do
|
322
|
-
@inserted_nodes = []
|
323
|
-
inserted_nodes << list.insert_node(7)
|
324
|
-
inserted_nodes << list.insert_node(1)
|
325
|
-
inserted_nodes << list.insert_node(3)
|
326
|
-
end
|
327
|
-
|
328
|
-
it_should_behave_like "it is non-empty"
|
329
|
-
it_should_behave_like "#nodes is an array of the three inserted nodes in key order"
|
330
|
-
|
331
|
-
describe "the first inserted node" do
|
332
|
-
attr_reader :inserted_node
|
333
|
-
|
334
|
-
before do
|
335
|
-
@inserted_node = inserted_nodes[0]
|
336
|
-
end
|
337
|
-
|
338
|
-
it_should_behave_like "it has nil forward pointers"
|
339
|
-
|
340
|
-
it "has a key of 7" do
|
341
|
-
inserted_node.key.should == 7
|
342
|
-
end
|
343
|
-
|
344
|
-
it "has a height of the first expected node height" do
|
345
|
-
inserted_node.height.should == expected_node_heights[0]
|
346
|
-
end
|
347
|
-
end
|
348
|
-
|
349
|
-
describe "the second inserted node" do
|
350
|
-
attr_reader :inserted_node
|
351
|
-
|
352
|
-
before do
|
353
|
-
@inserted_node = inserted_nodes[1]
|
354
|
-
end
|
355
|
-
|
356
|
-
it "has a key of 1" do
|
357
|
-
inserted_node.key.should == 1
|
358
|
-
end
|
359
|
-
|
360
|
-
it "has a height of the second expected node height" do
|
361
|
-
inserted_node.height.should == expected_node_heights[1]
|
362
|
-
end
|
363
|
-
|
364
|
-
it "has a forward pointer at level 0 pointing to the second node in the list" do
|
365
|
-
inserted_node.forward[0].should == list.nodes[1]
|
366
|
-
end
|
367
|
-
end
|
368
|
-
|
369
|
-
describe "the third inserted node" do
|
370
|
-
attr_reader :inserted_node
|
371
|
-
|
372
|
-
before do
|
373
|
-
@inserted_node = inserted_nodes[2]
|
374
|
-
end
|
375
|
-
|
376
|
-
it "has a key of 3" do
|
377
|
-
inserted_node.key.should == 3
|
378
|
-
end
|
379
|
-
|
380
|
-
it "has a height of the third expected node height" do
|
381
|
-
inserted_node.height.should == expected_node_heights[2]
|
382
|
-
end
|
383
|
-
end
|
384
|
-
end
|
385
|
-
end
|