logical_query_parser 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +124 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/logical_query.rb +889 -0
- data/lib/logical_query.treetop +62 -0
- data/lib/logical_query_parser/nodes/active_record.rb +73 -0
- data/lib/logical_query_parser/nodes/base.rb +34 -0
- data/lib/logical_query_parser/version.rb +3 -0
- data/lib/logical_query_parser.rb +18 -0
- data/logical_query_parser.gemspec +30 -0
- metadata +160 -0
@@ -0,0 +1,889 @@
|
|
1
|
+
# Autogenerated from a Treetop grammar. Edits may be lost.
|
2
|
+
|
3
|
+
|
4
|
+
module LogicalQuery
|
5
|
+
include Treetop::Runtime
|
6
|
+
|
7
|
+
def root
|
8
|
+
@root ||= :exp
|
9
|
+
end
|
10
|
+
|
11
|
+
module Exp0
|
12
|
+
def any
|
13
|
+
elements[0]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def _nt_exp
|
18
|
+
start_index = index
|
19
|
+
if node_cache[:exp].has_key?(index)
|
20
|
+
cached = node_cache[:exp][index]
|
21
|
+
if cached
|
22
|
+
node_cache[:exp][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
23
|
+
@index = cached.interval.end
|
24
|
+
end
|
25
|
+
return cached
|
26
|
+
end
|
27
|
+
|
28
|
+
i0, s0 = index, []
|
29
|
+
i1 = index
|
30
|
+
r2 = _nt_cond
|
31
|
+
if r2
|
32
|
+
r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
|
33
|
+
r1 = r2
|
34
|
+
else
|
35
|
+
r3 = _nt_exp_paren
|
36
|
+
if r3
|
37
|
+
r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
|
38
|
+
r1 = r3
|
39
|
+
else
|
40
|
+
r4 = _nt_literal_seq
|
41
|
+
if r4
|
42
|
+
r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
|
43
|
+
r1 = r4
|
44
|
+
else
|
45
|
+
r5 = _nt_literal
|
46
|
+
if r5
|
47
|
+
r5 = SyntaxNode.new(input, (index-1)...index) if r5 == true
|
48
|
+
r1 = r5
|
49
|
+
else
|
50
|
+
@index = i1
|
51
|
+
r1 = nil
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
s0 << r1
|
57
|
+
if s0.last
|
58
|
+
r0 = instantiate_node(ExpNode,input, i0...index, s0)
|
59
|
+
r0.extend(Exp0)
|
60
|
+
else
|
61
|
+
@index = i0
|
62
|
+
r0 = nil
|
63
|
+
end
|
64
|
+
|
65
|
+
node_cache[:exp][start_index] = r0
|
66
|
+
|
67
|
+
r0
|
68
|
+
end
|
69
|
+
|
70
|
+
module ExpParen0
|
71
|
+
def lparen
|
72
|
+
elements[0]
|
73
|
+
end
|
74
|
+
|
75
|
+
def exp
|
76
|
+
elements[2]
|
77
|
+
end
|
78
|
+
|
79
|
+
def rparen
|
80
|
+
elements[4]
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def _nt_exp_paren
|
85
|
+
start_index = index
|
86
|
+
if node_cache[:exp_paren].has_key?(index)
|
87
|
+
cached = node_cache[:exp_paren][index]
|
88
|
+
if cached
|
89
|
+
node_cache[:exp_paren][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
90
|
+
@index = cached.interval.end
|
91
|
+
end
|
92
|
+
return cached
|
93
|
+
end
|
94
|
+
|
95
|
+
i0, s0 = index, []
|
96
|
+
r1 = _nt_lparen
|
97
|
+
s0 << r1
|
98
|
+
if r1
|
99
|
+
s2, i2 = [], index
|
100
|
+
loop do
|
101
|
+
r3 = _nt_sp
|
102
|
+
if r3
|
103
|
+
s2 << r3
|
104
|
+
else
|
105
|
+
break
|
106
|
+
end
|
107
|
+
end
|
108
|
+
r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
|
109
|
+
s0 << r2
|
110
|
+
if r2
|
111
|
+
r4 = _nt_exp
|
112
|
+
s0 << r4
|
113
|
+
if r4
|
114
|
+
s5, i5 = [], index
|
115
|
+
loop do
|
116
|
+
r6 = _nt_sp
|
117
|
+
if r6
|
118
|
+
s5 << r6
|
119
|
+
else
|
120
|
+
break
|
121
|
+
end
|
122
|
+
end
|
123
|
+
r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
|
124
|
+
s0 << r5
|
125
|
+
if r5
|
126
|
+
r7 = _nt_rparen
|
127
|
+
s0 << r7
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
if s0.last
|
133
|
+
r0 = instantiate_node(ExpParenNode,input, i0...index, s0)
|
134
|
+
r0.extend(ExpParen0)
|
135
|
+
else
|
136
|
+
@index = i0
|
137
|
+
r0 = nil
|
138
|
+
end
|
139
|
+
|
140
|
+
node_cache[:exp_paren][start_index] = r0
|
141
|
+
|
142
|
+
r0
|
143
|
+
end
|
144
|
+
|
145
|
+
module Cond0
|
146
|
+
def lexp
|
147
|
+
elements[0]
|
148
|
+
end
|
149
|
+
|
150
|
+
def logic
|
151
|
+
elements[2]
|
152
|
+
end
|
153
|
+
|
154
|
+
def rexp
|
155
|
+
elements[4]
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
def _nt_cond
|
160
|
+
start_index = index
|
161
|
+
if node_cache[:cond].has_key?(index)
|
162
|
+
cached = node_cache[:cond][index]
|
163
|
+
if cached
|
164
|
+
node_cache[:cond][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
165
|
+
@index = cached.interval.end
|
166
|
+
end
|
167
|
+
return cached
|
168
|
+
end
|
169
|
+
|
170
|
+
i0, s0 = index, []
|
171
|
+
i1 = index
|
172
|
+
r2 = _nt_exp_paren
|
173
|
+
if r2
|
174
|
+
r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
|
175
|
+
r1 = r2
|
176
|
+
else
|
177
|
+
r3 = _nt_literal
|
178
|
+
if r3
|
179
|
+
r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
|
180
|
+
r1 = r3
|
181
|
+
else
|
182
|
+
@index = i1
|
183
|
+
r1 = nil
|
184
|
+
end
|
185
|
+
end
|
186
|
+
s0 << r1
|
187
|
+
if r1
|
188
|
+
s4, i4 = [], index
|
189
|
+
loop do
|
190
|
+
r5 = _nt_sp
|
191
|
+
if r5
|
192
|
+
s4 << r5
|
193
|
+
else
|
194
|
+
break
|
195
|
+
end
|
196
|
+
end
|
197
|
+
if s4.empty?
|
198
|
+
@index = i4
|
199
|
+
r4 = nil
|
200
|
+
else
|
201
|
+
r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
|
202
|
+
end
|
203
|
+
s0 << r4
|
204
|
+
if r4
|
205
|
+
i6 = index
|
206
|
+
r7 = _nt_land
|
207
|
+
if r7
|
208
|
+
r7 = SyntaxNode.new(input, (index-1)...index) if r7 == true
|
209
|
+
r6 = r7
|
210
|
+
else
|
211
|
+
r8 = _nt_lor
|
212
|
+
if r8
|
213
|
+
r8 = SyntaxNode.new(input, (index-1)...index) if r8 == true
|
214
|
+
r6 = r8
|
215
|
+
else
|
216
|
+
@index = i6
|
217
|
+
r6 = nil
|
218
|
+
end
|
219
|
+
end
|
220
|
+
s0 << r6
|
221
|
+
if r6
|
222
|
+
s9, i9 = [], index
|
223
|
+
loop do
|
224
|
+
r10 = _nt_sp
|
225
|
+
if r10
|
226
|
+
s9 << r10
|
227
|
+
else
|
228
|
+
break
|
229
|
+
end
|
230
|
+
end
|
231
|
+
if s9.empty?
|
232
|
+
@index = i9
|
233
|
+
r9 = nil
|
234
|
+
else
|
235
|
+
r9 = instantiate_node(SyntaxNode,input, i9...index, s9)
|
236
|
+
end
|
237
|
+
s0 << r9
|
238
|
+
if r9
|
239
|
+
r11 = _nt_exp
|
240
|
+
s0 << r11
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
if s0.last
|
246
|
+
r0 = instantiate_node(CondNode,input, i0...index, s0)
|
247
|
+
r0.extend(Cond0)
|
248
|
+
else
|
249
|
+
@index = i0
|
250
|
+
r0 = nil
|
251
|
+
end
|
252
|
+
|
253
|
+
node_cache[:cond][start_index] = r0
|
254
|
+
|
255
|
+
r0
|
256
|
+
end
|
257
|
+
|
258
|
+
module LiteralSeq0
|
259
|
+
def lliteral
|
260
|
+
elements[0]
|
261
|
+
end
|
262
|
+
|
263
|
+
def rliteral
|
264
|
+
elements[2]
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
def _nt_literal_seq
|
269
|
+
start_index = index
|
270
|
+
if node_cache[:literal_seq].has_key?(index)
|
271
|
+
cached = node_cache[:literal_seq][index]
|
272
|
+
if cached
|
273
|
+
node_cache[:literal_seq][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
274
|
+
@index = cached.interval.end
|
275
|
+
end
|
276
|
+
return cached
|
277
|
+
end
|
278
|
+
|
279
|
+
i0, s0 = index, []
|
280
|
+
r1 = _nt_literal
|
281
|
+
s0 << r1
|
282
|
+
if r1
|
283
|
+
s2, i2 = [], index
|
284
|
+
loop do
|
285
|
+
r3 = _nt_sp
|
286
|
+
if r3
|
287
|
+
s2 << r3
|
288
|
+
else
|
289
|
+
break
|
290
|
+
end
|
291
|
+
end
|
292
|
+
if s2.empty?
|
293
|
+
@index = i2
|
294
|
+
r2 = nil
|
295
|
+
else
|
296
|
+
r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
|
297
|
+
end
|
298
|
+
s0 << r2
|
299
|
+
if r2
|
300
|
+
i4 = index
|
301
|
+
r5 = _nt_literal_seq
|
302
|
+
if r5
|
303
|
+
r5 = SyntaxNode.new(input, (index-1)...index) if r5 == true
|
304
|
+
r4 = r5
|
305
|
+
else
|
306
|
+
r6 = _nt_literal
|
307
|
+
if r6
|
308
|
+
r6 = SyntaxNode.new(input, (index-1)...index) if r6 == true
|
309
|
+
r4 = r6
|
310
|
+
else
|
311
|
+
@index = i4
|
312
|
+
r4 = nil
|
313
|
+
end
|
314
|
+
end
|
315
|
+
s0 << r4
|
316
|
+
end
|
317
|
+
end
|
318
|
+
if s0.last
|
319
|
+
r0 = instantiate_node(LiteralSeqNode,input, i0...index, s0)
|
320
|
+
r0.extend(LiteralSeq0)
|
321
|
+
else
|
322
|
+
@index = i0
|
323
|
+
r0 = nil
|
324
|
+
end
|
325
|
+
|
326
|
+
node_cache[:literal_seq][start_index] = r0
|
327
|
+
|
328
|
+
r0
|
329
|
+
end
|
330
|
+
|
331
|
+
module Literal0
|
332
|
+
def negative
|
333
|
+
elements[0]
|
334
|
+
end
|
335
|
+
|
336
|
+
def word
|
337
|
+
elements[1]
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
341
|
+
def _nt_literal
|
342
|
+
start_index = index
|
343
|
+
if node_cache[:literal].has_key?(index)
|
344
|
+
cached = node_cache[:literal][index]
|
345
|
+
if cached
|
346
|
+
node_cache[:literal][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
347
|
+
@index = cached.interval.end
|
348
|
+
end
|
349
|
+
return cached
|
350
|
+
end
|
351
|
+
|
352
|
+
i0, s0 = index, []
|
353
|
+
s1, i1 = [], index
|
354
|
+
loop do
|
355
|
+
r2 = _nt_negative
|
356
|
+
if r2
|
357
|
+
s1 << r2
|
358
|
+
else
|
359
|
+
break
|
360
|
+
end
|
361
|
+
end
|
362
|
+
r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
|
363
|
+
s0 << r1
|
364
|
+
if r1
|
365
|
+
r3 = _nt_word
|
366
|
+
s0 << r3
|
367
|
+
end
|
368
|
+
if s0.last
|
369
|
+
r0 = instantiate_node(LiteralNode,input, i0...index, s0)
|
370
|
+
r0.extend(Literal0)
|
371
|
+
else
|
372
|
+
@index = i0
|
373
|
+
r0 = nil
|
374
|
+
end
|
375
|
+
|
376
|
+
node_cache[:literal][start_index] = r0
|
377
|
+
|
378
|
+
r0
|
379
|
+
end
|
380
|
+
|
381
|
+
def _nt_word
|
382
|
+
start_index = index
|
383
|
+
if node_cache[:word].has_key?(index)
|
384
|
+
cached = node_cache[:word][index]
|
385
|
+
if cached
|
386
|
+
node_cache[:word][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
387
|
+
@index = cached.interval.end
|
388
|
+
end
|
389
|
+
return cached
|
390
|
+
end
|
391
|
+
|
392
|
+
i0 = index
|
393
|
+
r1 = _nt_quoted_word
|
394
|
+
if r1
|
395
|
+
r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
|
396
|
+
r0 = r1
|
397
|
+
r0.extend(WordNode)
|
398
|
+
else
|
399
|
+
r2 = _nt_unquoted_word
|
400
|
+
if r2
|
401
|
+
r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
|
402
|
+
r0 = r2
|
403
|
+
r0.extend(WordNode)
|
404
|
+
else
|
405
|
+
@index = i0
|
406
|
+
r0 = nil
|
407
|
+
end
|
408
|
+
end
|
409
|
+
|
410
|
+
node_cache[:word][start_index] = r0
|
411
|
+
|
412
|
+
r0
|
413
|
+
end
|
414
|
+
|
415
|
+
module QuotedWord0
|
416
|
+
end
|
417
|
+
|
418
|
+
module QuotedWord1
|
419
|
+
end
|
420
|
+
|
421
|
+
def _nt_quoted_word
|
422
|
+
start_index = index
|
423
|
+
if node_cache[:quoted_word].has_key?(index)
|
424
|
+
cached = node_cache[:quoted_word][index]
|
425
|
+
if cached
|
426
|
+
node_cache[:quoted_word][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
427
|
+
@index = cached.interval.end
|
428
|
+
end
|
429
|
+
return cached
|
430
|
+
end
|
431
|
+
|
432
|
+
i0, s0 = index, []
|
433
|
+
if (match_len = has_terminal?('"', false, index))
|
434
|
+
r1 = true
|
435
|
+
@index += match_len
|
436
|
+
else
|
437
|
+
terminal_parse_failure('\'"\'')
|
438
|
+
r1 = nil
|
439
|
+
end
|
440
|
+
s0 << r1
|
441
|
+
if r1
|
442
|
+
s2, i2 = [], index
|
443
|
+
loop do
|
444
|
+
i3 = index
|
445
|
+
if (match_len = has_terminal?('\"', false, index))
|
446
|
+
r4 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
447
|
+
@index += match_len
|
448
|
+
else
|
449
|
+
terminal_parse_failure('\'\\"\'')
|
450
|
+
r4 = nil
|
451
|
+
end
|
452
|
+
if r4
|
453
|
+
r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
|
454
|
+
r3 = r4
|
455
|
+
else
|
456
|
+
i5, s5 = index, []
|
457
|
+
i6 = index
|
458
|
+
if (match_len = has_terminal?('"', false, index))
|
459
|
+
r7 = true
|
460
|
+
@index += match_len
|
461
|
+
else
|
462
|
+
terminal_parse_failure('\'"\'')
|
463
|
+
r7 = nil
|
464
|
+
end
|
465
|
+
if r7
|
466
|
+
@index = i6
|
467
|
+
r6 = nil
|
468
|
+
terminal_parse_failure('\'"\'', true)
|
469
|
+
else
|
470
|
+
@terminal_failures.pop
|
471
|
+
@index = i6
|
472
|
+
r6 = instantiate_node(SyntaxNode,input, index...index)
|
473
|
+
end
|
474
|
+
s5 << r6
|
475
|
+
if r6
|
476
|
+
if index < input_length
|
477
|
+
r8 = true
|
478
|
+
@index += 1
|
479
|
+
else
|
480
|
+
terminal_parse_failure("any character")
|
481
|
+
r8 = nil
|
482
|
+
end
|
483
|
+
s5 << r8
|
484
|
+
end
|
485
|
+
if s5.last
|
486
|
+
r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
|
487
|
+
r5.extend(QuotedWord0)
|
488
|
+
else
|
489
|
+
@index = i5
|
490
|
+
r5 = nil
|
491
|
+
end
|
492
|
+
if r5
|
493
|
+
r5 = SyntaxNode.new(input, (index-1)...index) if r5 == true
|
494
|
+
r3 = r5
|
495
|
+
else
|
496
|
+
@index = i3
|
497
|
+
r3 = nil
|
498
|
+
end
|
499
|
+
end
|
500
|
+
if r3
|
501
|
+
s2 << r3
|
502
|
+
else
|
503
|
+
break
|
504
|
+
end
|
505
|
+
end
|
506
|
+
r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
|
507
|
+
s0 << r2
|
508
|
+
if r2
|
509
|
+
if (match_len = has_terminal?('"', false, index))
|
510
|
+
r9 = true
|
511
|
+
@index += match_len
|
512
|
+
else
|
513
|
+
terminal_parse_failure('\'"\'')
|
514
|
+
r9 = nil
|
515
|
+
end
|
516
|
+
s0 << r9
|
517
|
+
end
|
518
|
+
end
|
519
|
+
if s0.last
|
520
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
521
|
+
r0.extend(QuotedWord1)
|
522
|
+
else
|
523
|
+
@index = i0
|
524
|
+
r0 = nil
|
525
|
+
end
|
526
|
+
|
527
|
+
node_cache[:quoted_word][start_index] = r0
|
528
|
+
|
529
|
+
r0
|
530
|
+
end
|
531
|
+
|
532
|
+
def _nt_unquoted_word
|
533
|
+
start_index = index
|
534
|
+
if node_cache[:unquoted_word].has_key?(index)
|
535
|
+
cached = node_cache[:unquoted_word][index]
|
536
|
+
if cached
|
537
|
+
node_cache[:unquoted_word][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
538
|
+
@index = cached.interval.end
|
539
|
+
end
|
540
|
+
return cached
|
541
|
+
end
|
542
|
+
|
543
|
+
s0, i0 = [], index
|
544
|
+
loop do
|
545
|
+
r1 = _nt_atom
|
546
|
+
if r1
|
547
|
+
s0 << r1
|
548
|
+
else
|
549
|
+
break
|
550
|
+
end
|
551
|
+
end
|
552
|
+
if s0.empty?
|
553
|
+
@index = i0
|
554
|
+
r0 = nil
|
555
|
+
else
|
556
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
557
|
+
end
|
558
|
+
|
559
|
+
node_cache[:unquoted_word][start_index] = r0
|
560
|
+
|
561
|
+
r0
|
562
|
+
end
|
563
|
+
|
564
|
+
def _nt_land
|
565
|
+
start_index = index
|
566
|
+
if node_cache[:land].has_key?(index)
|
567
|
+
cached = node_cache[:land][index]
|
568
|
+
if cached
|
569
|
+
node_cache[:land][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
570
|
+
@index = cached.interval.end
|
571
|
+
end
|
572
|
+
return cached
|
573
|
+
end
|
574
|
+
|
575
|
+
i0 = index
|
576
|
+
if (match_len = has_terminal?('AND', false, index))
|
577
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
578
|
+
@index += match_len
|
579
|
+
else
|
580
|
+
terminal_parse_failure('\'AND\'')
|
581
|
+
r1 = nil
|
582
|
+
end
|
583
|
+
if r1
|
584
|
+
r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
|
585
|
+
r0 = r1
|
586
|
+
r0.extend(AndNode)
|
587
|
+
else
|
588
|
+
if (match_len = has_terminal?('and', false, index))
|
589
|
+
r2 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
590
|
+
@index += match_len
|
591
|
+
else
|
592
|
+
terminal_parse_failure('\'and\'')
|
593
|
+
r2 = nil
|
594
|
+
end
|
595
|
+
if r2
|
596
|
+
r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
|
597
|
+
r0 = r2
|
598
|
+
r0.extend(AndNode)
|
599
|
+
else
|
600
|
+
@index = i0
|
601
|
+
r0 = nil
|
602
|
+
end
|
603
|
+
end
|
604
|
+
|
605
|
+
node_cache[:land][start_index] = r0
|
606
|
+
|
607
|
+
r0
|
608
|
+
end
|
609
|
+
|
610
|
+
def _nt_lor
|
611
|
+
start_index = index
|
612
|
+
if node_cache[:lor].has_key?(index)
|
613
|
+
cached = node_cache[:lor][index]
|
614
|
+
if cached
|
615
|
+
node_cache[:lor][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
616
|
+
@index = cached.interval.end
|
617
|
+
end
|
618
|
+
return cached
|
619
|
+
end
|
620
|
+
|
621
|
+
i0 = index
|
622
|
+
if (match_len = has_terminal?('OR', false, index))
|
623
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
624
|
+
@index += match_len
|
625
|
+
else
|
626
|
+
terminal_parse_failure('\'OR\'')
|
627
|
+
r1 = nil
|
628
|
+
end
|
629
|
+
if r1
|
630
|
+
r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
|
631
|
+
r0 = r1
|
632
|
+
r0.extend(OrNode)
|
633
|
+
else
|
634
|
+
if (match_len = has_terminal?('or', false, index))
|
635
|
+
r2 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
636
|
+
@index += match_len
|
637
|
+
else
|
638
|
+
terminal_parse_failure('\'or\'')
|
639
|
+
r2 = nil
|
640
|
+
end
|
641
|
+
if r2
|
642
|
+
r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
|
643
|
+
r0 = r2
|
644
|
+
r0.extend(OrNode)
|
645
|
+
else
|
646
|
+
@index = i0
|
647
|
+
r0 = nil
|
648
|
+
end
|
649
|
+
end
|
650
|
+
|
651
|
+
node_cache[:lor][start_index] = r0
|
652
|
+
|
653
|
+
r0
|
654
|
+
end
|
655
|
+
|
656
|
+
def _nt_lparen
|
657
|
+
start_index = index
|
658
|
+
if node_cache[:lparen].has_key?(index)
|
659
|
+
cached = node_cache[:lparen][index]
|
660
|
+
if cached
|
661
|
+
node_cache[:lparen][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
662
|
+
@index = cached.interval.end
|
663
|
+
end
|
664
|
+
return cached
|
665
|
+
end
|
666
|
+
|
667
|
+
if (match_len = has_terminal?('(', false, index))
|
668
|
+
r0 = instantiate_node(LParenNode,input, index...(index + match_len))
|
669
|
+
@index += match_len
|
670
|
+
else
|
671
|
+
terminal_parse_failure('\'(\'')
|
672
|
+
r0 = nil
|
673
|
+
end
|
674
|
+
|
675
|
+
node_cache[:lparen][start_index] = r0
|
676
|
+
|
677
|
+
r0
|
678
|
+
end
|
679
|
+
|
680
|
+
def _nt_rparen
|
681
|
+
start_index = index
|
682
|
+
if node_cache[:rparen].has_key?(index)
|
683
|
+
cached = node_cache[:rparen][index]
|
684
|
+
if cached
|
685
|
+
node_cache[:rparen][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
686
|
+
@index = cached.interval.end
|
687
|
+
end
|
688
|
+
return cached
|
689
|
+
end
|
690
|
+
|
691
|
+
if (match_len = has_terminal?(')', false, index))
|
692
|
+
r0 = instantiate_node(RParenNode,input, index...(index + match_len))
|
693
|
+
@index += match_len
|
694
|
+
else
|
695
|
+
terminal_parse_failure('\')\'')
|
696
|
+
r0 = nil
|
697
|
+
end
|
698
|
+
|
699
|
+
node_cache[:rparen][start_index] = r0
|
700
|
+
|
701
|
+
r0
|
702
|
+
end
|
703
|
+
|
704
|
+
def _nt_negative
|
705
|
+
start_index = index
|
706
|
+
if node_cache[:negative].has_key?(index)
|
707
|
+
cached = node_cache[:negative][index]
|
708
|
+
if cached
|
709
|
+
node_cache[:negative][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
710
|
+
@index = cached.interval.end
|
711
|
+
end
|
712
|
+
return cached
|
713
|
+
end
|
714
|
+
|
715
|
+
i0 = index
|
716
|
+
if (match_len = has_terminal?('-', false, index))
|
717
|
+
r1 = true
|
718
|
+
@index += match_len
|
719
|
+
else
|
720
|
+
terminal_parse_failure('\'-\'')
|
721
|
+
r1 = nil
|
722
|
+
end
|
723
|
+
if r1
|
724
|
+
r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
|
725
|
+
r0 = r1
|
726
|
+
r0.extend(NegativeNode)
|
727
|
+
else
|
728
|
+
if (match_len = has_terminal?('-', false, index))
|
729
|
+
r2 = true
|
730
|
+
@index += match_len
|
731
|
+
else
|
732
|
+
terminal_parse_failure('\'-\'')
|
733
|
+
r2 = nil
|
734
|
+
end
|
735
|
+
if r2
|
736
|
+
r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
|
737
|
+
r0 = r2
|
738
|
+
r0.extend(NegativeNode)
|
739
|
+
else
|
740
|
+
if (match_len = has_terminal?('-', false, index))
|
741
|
+
r3 = true
|
742
|
+
@index += match_len
|
743
|
+
else
|
744
|
+
terminal_parse_failure('\'-\'')
|
745
|
+
r3 = nil
|
746
|
+
end
|
747
|
+
if r3
|
748
|
+
r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
|
749
|
+
r0 = r3
|
750
|
+
r0.extend(NegativeNode)
|
751
|
+
else
|
752
|
+
@index = i0
|
753
|
+
r0 = nil
|
754
|
+
end
|
755
|
+
end
|
756
|
+
end
|
757
|
+
|
758
|
+
node_cache[:negative][start_index] = r0
|
759
|
+
|
760
|
+
r0
|
761
|
+
end
|
762
|
+
|
763
|
+
def _nt_sp
|
764
|
+
start_index = index
|
765
|
+
if node_cache[:sp].has_key?(index)
|
766
|
+
cached = node_cache[:sp][index]
|
767
|
+
if cached
|
768
|
+
node_cache[:sp][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
769
|
+
@index = cached.interval.end
|
770
|
+
end
|
771
|
+
return cached
|
772
|
+
end
|
773
|
+
|
774
|
+
i0 = index
|
775
|
+
if (match_len = has_terminal?(' ', false, index))
|
776
|
+
r1 = true
|
777
|
+
@index += match_len
|
778
|
+
else
|
779
|
+
terminal_parse_failure('\' \'')
|
780
|
+
r1 = nil
|
781
|
+
end
|
782
|
+
if r1
|
783
|
+
r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
|
784
|
+
r0 = r1
|
785
|
+
else
|
786
|
+
if (match_len = has_terminal?(' ', false, index))
|
787
|
+
r2 = true
|
788
|
+
@index += match_len
|
789
|
+
else
|
790
|
+
terminal_parse_failure('\' \'')
|
791
|
+
r2 = nil
|
792
|
+
end
|
793
|
+
if r2
|
794
|
+
r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
|
795
|
+
r0 = r2
|
796
|
+
else
|
797
|
+
@index = i0
|
798
|
+
r0 = nil
|
799
|
+
end
|
800
|
+
end
|
801
|
+
|
802
|
+
node_cache[:sp][start_index] = r0
|
803
|
+
|
804
|
+
r0
|
805
|
+
end
|
806
|
+
|
807
|
+
module Atom0
|
808
|
+
end
|
809
|
+
|
810
|
+
def _nt_atom
|
811
|
+
start_index = index
|
812
|
+
if node_cache[:atom].has_key?(index)
|
813
|
+
cached = node_cache[:atom][index]
|
814
|
+
if cached
|
815
|
+
node_cache[:atom][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
816
|
+
@index = cached.interval.end
|
817
|
+
end
|
818
|
+
return cached
|
819
|
+
end
|
820
|
+
|
821
|
+
i0, s0 = index, []
|
822
|
+
i1 = index
|
823
|
+
i2 = index
|
824
|
+
r3 = _nt_lparen
|
825
|
+
if r3
|
826
|
+
r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
|
827
|
+
r2 = r3
|
828
|
+
else
|
829
|
+
r4 = _nt_rparen
|
830
|
+
if r4
|
831
|
+
r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
|
832
|
+
r2 = r4
|
833
|
+
else
|
834
|
+
r5 = _nt_negative
|
835
|
+
if r5
|
836
|
+
r5 = SyntaxNode.new(input, (index-1)...index) if r5 == true
|
837
|
+
r2 = r5
|
838
|
+
else
|
839
|
+
r6 = _nt_sp
|
840
|
+
if r6
|
841
|
+
r6 = SyntaxNode.new(input, (index-1)...index) if r6 == true
|
842
|
+
r2 = r6
|
843
|
+
else
|
844
|
+
@index = i2
|
845
|
+
r2 = nil
|
846
|
+
end
|
847
|
+
end
|
848
|
+
end
|
849
|
+
end
|
850
|
+
if r2
|
851
|
+
@index = i1
|
852
|
+
r1 = nil
|
853
|
+
terminal_parse_failure("(any alternative)", true)
|
854
|
+
else
|
855
|
+
@terminal_failures.pop
|
856
|
+
@index = i1
|
857
|
+
r1 = instantiate_node(SyntaxNode,input, index...index)
|
858
|
+
end
|
859
|
+
s0 << r1
|
860
|
+
if r1
|
861
|
+
if index < input_length
|
862
|
+
r7 = true
|
863
|
+
@index += 1
|
864
|
+
else
|
865
|
+
terminal_parse_failure("any character")
|
866
|
+
r7 = nil
|
867
|
+
end
|
868
|
+
s0 << r7
|
869
|
+
end
|
870
|
+
if s0.last
|
871
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
872
|
+
r0.extend(Atom0)
|
873
|
+
else
|
874
|
+
@index = i0
|
875
|
+
r0 = nil
|
876
|
+
end
|
877
|
+
|
878
|
+
node_cache[:atom][start_index] = r0
|
879
|
+
|
880
|
+
r0
|
881
|
+
end
|
882
|
+
|
883
|
+
end
|
884
|
+
|
885
|
+
class LogicalQueryParser < Treetop::Runtime::CompiledParser
|
886
|
+
include LogicalQuery
|
887
|
+
end
|
888
|
+
|
889
|
+
|