siren 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +16 -0
- data/Manifest.txt +22 -0
- data/README.txt +318 -0
- data/Rakefile +19 -0
- data/lib/siren.rb +76 -0
- data/lib/siren/json.rb +1039 -0
- data/lib/siren/json.tt +86 -0
- data/lib/siren/json_query.rb +2414 -0
- data/lib/siren/json_query.tt +184 -0
- data/lib/siren/json_query_nodes.rb +333 -0
- data/lib/siren/node.rb +37 -0
- data/lib/siren/parser.rb +205 -0
- data/lib/siren/reference.rb +30 -0
- data/lib/siren/walker.rb +33 -0
- data/test/fixtures/beatles.json +11 -0
- data/test/fixtures/car.rb +14 -0
- data/test/fixtures/names.json +7 -0
- data/test/fixtures/people.json +34 -0
- data/test/fixtures/person.rb +15 -0
- data/test/fixtures/refs.json +26 -0
- data/test/fixtures/store.json +32 -0
- data/test/test_siren.rb +181 -0
- metadata +109 -0
data/lib/siren/json.rb
ADDED
@@ -0,0 +1,1039 @@
|
|
1
|
+
module Siren
|
2
|
+
module Json
|
3
|
+
include Treetop::Runtime
|
4
|
+
|
5
|
+
def root
|
6
|
+
@root || :value
|
7
|
+
end
|
8
|
+
|
9
|
+
module Value0
|
10
|
+
def space
|
11
|
+
elements[0]
|
12
|
+
end
|
13
|
+
|
14
|
+
def data
|
15
|
+
elements[1]
|
16
|
+
end
|
17
|
+
|
18
|
+
def space
|
19
|
+
elements[2]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module Value1
|
24
|
+
def value
|
25
|
+
data.value
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def _nt_value
|
30
|
+
start_index = index
|
31
|
+
if node_cache[:value].has_key?(index)
|
32
|
+
cached = node_cache[:value][index]
|
33
|
+
@index = cached.interval.end if cached
|
34
|
+
return cached
|
35
|
+
end
|
36
|
+
|
37
|
+
i0, s0 = index, []
|
38
|
+
r1 = _nt_space
|
39
|
+
s0 << r1
|
40
|
+
if r1
|
41
|
+
i2 = index
|
42
|
+
r3 = _nt_object
|
43
|
+
if r3
|
44
|
+
r2 = r3
|
45
|
+
else
|
46
|
+
r4 = _nt_array
|
47
|
+
if r4
|
48
|
+
r2 = r4
|
49
|
+
else
|
50
|
+
r5 = _nt_string
|
51
|
+
if r5
|
52
|
+
r2 = r5
|
53
|
+
else
|
54
|
+
r6 = _nt_number
|
55
|
+
if r6
|
56
|
+
r2 = r6
|
57
|
+
else
|
58
|
+
r7 = _nt_true
|
59
|
+
if r7
|
60
|
+
r2 = r7
|
61
|
+
else
|
62
|
+
r8 = _nt_false
|
63
|
+
if r8
|
64
|
+
r2 = r8
|
65
|
+
else
|
66
|
+
r9 = _nt_null
|
67
|
+
if r9
|
68
|
+
r2 = r9
|
69
|
+
else
|
70
|
+
self.index = i2
|
71
|
+
r2 = nil
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
s0 << r2
|
80
|
+
if r2
|
81
|
+
r10 = _nt_space
|
82
|
+
s0 << r10
|
83
|
+
end
|
84
|
+
end
|
85
|
+
if s0.last
|
86
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
87
|
+
r0.extend(Value0)
|
88
|
+
r0.extend(Value1)
|
89
|
+
else
|
90
|
+
self.index = i0
|
91
|
+
r0 = nil
|
92
|
+
end
|
93
|
+
|
94
|
+
node_cache[:value][start_index] = r0
|
95
|
+
|
96
|
+
return r0
|
97
|
+
end
|
98
|
+
|
99
|
+
module Object0
|
100
|
+
def key_value_pair
|
101
|
+
elements[1]
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
module Object1
|
106
|
+
def first
|
107
|
+
elements[0]
|
108
|
+
end
|
109
|
+
|
110
|
+
def others
|
111
|
+
elements[1]
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
module Object2
|
116
|
+
def space
|
117
|
+
elements[1]
|
118
|
+
end
|
119
|
+
|
120
|
+
def list
|
121
|
+
elements[2]
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
module Object3
|
127
|
+
def value
|
128
|
+
pairs = [list.first] + list.others.elements.map { |e| e.key_value_pair }
|
129
|
+
pairs.inject({}) do |hash, pair|
|
130
|
+
hash[pair.string.value] = pair.value.value
|
131
|
+
hash
|
132
|
+
end
|
133
|
+
rescue
|
134
|
+
{}
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def _nt_object
|
139
|
+
start_index = index
|
140
|
+
if node_cache[:object].has_key?(index)
|
141
|
+
cached = node_cache[:object][index]
|
142
|
+
@index = cached.interval.end if cached
|
143
|
+
return cached
|
144
|
+
end
|
145
|
+
|
146
|
+
i0, s0 = index, []
|
147
|
+
if input.index("{", index) == index
|
148
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
149
|
+
@index += 1
|
150
|
+
else
|
151
|
+
terminal_parse_failure("{")
|
152
|
+
r1 = nil
|
153
|
+
end
|
154
|
+
s0 << r1
|
155
|
+
if r1
|
156
|
+
r2 = _nt_space
|
157
|
+
s0 << r2
|
158
|
+
if r2
|
159
|
+
i4, s4 = index, []
|
160
|
+
r5 = _nt_key_value_pair
|
161
|
+
s4 << r5
|
162
|
+
if r5
|
163
|
+
s6, i6 = [], index
|
164
|
+
loop do
|
165
|
+
i7, s7 = index, []
|
166
|
+
if input.index(",", index) == index
|
167
|
+
r8 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
168
|
+
@index += 1
|
169
|
+
else
|
170
|
+
terminal_parse_failure(",")
|
171
|
+
r8 = nil
|
172
|
+
end
|
173
|
+
s7 << r8
|
174
|
+
if r8
|
175
|
+
r9 = _nt_key_value_pair
|
176
|
+
s7 << r9
|
177
|
+
end
|
178
|
+
if s7.last
|
179
|
+
r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
|
180
|
+
r7.extend(Object0)
|
181
|
+
else
|
182
|
+
self.index = i7
|
183
|
+
r7 = nil
|
184
|
+
end
|
185
|
+
if r7
|
186
|
+
s6 << r7
|
187
|
+
else
|
188
|
+
break
|
189
|
+
end
|
190
|
+
end
|
191
|
+
r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
|
192
|
+
s4 << r6
|
193
|
+
end
|
194
|
+
if s4.last
|
195
|
+
r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
|
196
|
+
r4.extend(Object1)
|
197
|
+
else
|
198
|
+
self.index = i4
|
199
|
+
r4 = nil
|
200
|
+
end
|
201
|
+
if r4
|
202
|
+
r3 = r4
|
203
|
+
else
|
204
|
+
r3 = instantiate_node(SyntaxNode,input, index...index)
|
205
|
+
end
|
206
|
+
s0 << r3
|
207
|
+
if r3
|
208
|
+
if input.index("}", index) == index
|
209
|
+
r10 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
210
|
+
@index += 1
|
211
|
+
else
|
212
|
+
terminal_parse_failure("}")
|
213
|
+
r10 = nil
|
214
|
+
end
|
215
|
+
s0 << r10
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
if s0.last
|
220
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
221
|
+
r0.extend(Object2)
|
222
|
+
r0.extend(Object3)
|
223
|
+
else
|
224
|
+
self.index = i0
|
225
|
+
r0 = nil
|
226
|
+
end
|
227
|
+
|
228
|
+
node_cache[:object][start_index] = r0
|
229
|
+
|
230
|
+
return r0
|
231
|
+
end
|
232
|
+
|
233
|
+
module KeyValuePair0
|
234
|
+
def space
|
235
|
+
elements[0]
|
236
|
+
end
|
237
|
+
|
238
|
+
def string
|
239
|
+
elements[1]
|
240
|
+
end
|
241
|
+
|
242
|
+
def space
|
243
|
+
elements[2]
|
244
|
+
end
|
245
|
+
|
246
|
+
def value
|
247
|
+
elements[4]
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
def _nt_key_value_pair
|
252
|
+
start_index = index
|
253
|
+
if node_cache[:key_value_pair].has_key?(index)
|
254
|
+
cached = node_cache[:key_value_pair][index]
|
255
|
+
@index = cached.interval.end if cached
|
256
|
+
return cached
|
257
|
+
end
|
258
|
+
|
259
|
+
i0, s0 = index, []
|
260
|
+
r1 = _nt_space
|
261
|
+
s0 << r1
|
262
|
+
if r1
|
263
|
+
r2 = _nt_string
|
264
|
+
s0 << r2
|
265
|
+
if r2
|
266
|
+
r3 = _nt_space
|
267
|
+
s0 << r3
|
268
|
+
if r3
|
269
|
+
if input.index(":", index) == index
|
270
|
+
r4 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
271
|
+
@index += 1
|
272
|
+
else
|
273
|
+
terminal_parse_failure(":")
|
274
|
+
r4 = nil
|
275
|
+
end
|
276
|
+
s0 << r4
|
277
|
+
if r4
|
278
|
+
r5 = _nt_value
|
279
|
+
s0 << r5
|
280
|
+
end
|
281
|
+
end
|
282
|
+
end
|
283
|
+
end
|
284
|
+
if s0.last
|
285
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
286
|
+
r0.extend(KeyValuePair0)
|
287
|
+
else
|
288
|
+
self.index = i0
|
289
|
+
r0 = nil
|
290
|
+
end
|
291
|
+
|
292
|
+
node_cache[:key_value_pair][start_index] = r0
|
293
|
+
|
294
|
+
return r0
|
295
|
+
end
|
296
|
+
|
297
|
+
module Array0
|
298
|
+
def value
|
299
|
+
elements[1]
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
module Array1
|
304
|
+
def first
|
305
|
+
elements[0]
|
306
|
+
end
|
307
|
+
|
308
|
+
def others
|
309
|
+
elements[1]
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
module Array2
|
314
|
+
def space
|
315
|
+
elements[1]
|
316
|
+
end
|
317
|
+
|
318
|
+
def list
|
319
|
+
elements[2]
|
320
|
+
end
|
321
|
+
|
322
|
+
end
|
323
|
+
|
324
|
+
module Array3
|
325
|
+
def value
|
326
|
+
[list.first.value] + list.others.elements.map { |v| v.value.value }
|
327
|
+
rescue
|
328
|
+
[]
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
332
|
+
def _nt_array
|
333
|
+
start_index = index
|
334
|
+
if node_cache[:array].has_key?(index)
|
335
|
+
cached = node_cache[:array][index]
|
336
|
+
@index = cached.interval.end if cached
|
337
|
+
return cached
|
338
|
+
end
|
339
|
+
|
340
|
+
i0, s0 = index, []
|
341
|
+
if input.index("[", index) == index
|
342
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
343
|
+
@index += 1
|
344
|
+
else
|
345
|
+
terminal_parse_failure("[")
|
346
|
+
r1 = nil
|
347
|
+
end
|
348
|
+
s0 << r1
|
349
|
+
if r1
|
350
|
+
r2 = _nt_space
|
351
|
+
s0 << r2
|
352
|
+
if r2
|
353
|
+
i4, s4 = index, []
|
354
|
+
r5 = _nt_value
|
355
|
+
s4 << r5
|
356
|
+
if r5
|
357
|
+
s6, i6 = [], index
|
358
|
+
loop do
|
359
|
+
i7, s7 = index, []
|
360
|
+
if input.index(",", index) == index
|
361
|
+
r8 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
362
|
+
@index += 1
|
363
|
+
else
|
364
|
+
terminal_parse_failure(",")
|
365
|
+
r8 = nil
|
366
|
+
end
|
367
|
+
s7 << r8
|
368
|
+
if r8
|
369
|
+
r9 = _nt_value
|
370
|
+
s7 << r9
|
371
|
+
end
|
372
|
+
if s7.last
|
373
|
+
r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
|
374
|
+
r7.extend(Array0)
|
375
|
+
else
|
376
|
+
self.index = i7
|
377
|
+
r7 = nil
|
378
|
+
end
|
379
|
+
if r7
|
380
|
+
s6 << r7
|
381
|
+
else
|
382
|
+
break
|
383
|
+
end
|
384
|
+
end
|
385
|
+
r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
|
386
|
+
s4 << r6
|
387
|
+
end
|
388
|
+
if s4.last
|
389
|
+
r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
|
390
|
+
r4.extend(Array1)
|
391
|
+
else
|
392
|
+
self.index = i4
|
393
|
+
r4 = nil
|
394
|
+
end
|
395
|
+
if r4
|
396
|
+
r3 = r4
|
397
|
+
else
|
398
|
+
r3 = instantiate_node(SyntaxNode,input, index...index)
|
399
|
+
end
|
400
|
+
s0 << r3
|
401
|
+
if r3
|
402
|
+
if input.index("]", index) == index
|
403
|
+
r10 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
404
|
+
@index += 1
|
405
|
+
else
|
406
|
+
terminal_parse_failure("]")
|
407
|
+
r10 = nil
|
408
|
+
end
|
409
|
+
s0 << r10
|
410
|
+
end
|
411
|
+
end
|
412
|
+
end
|
413
|
+
if s0.last
|
414
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
415
|
+
r0.extend(Array2)
|
416
|
+
r0.extend(Array3)
|
417
|
+
else
|
418
|
+
self.index = i0
|
419
|
+
r0 = nil
|
420
|
+
end
|
421
|
+
|
422
|
+
node_cache[:array][start_index] = r0
|
423
|
+
|
424
|
+
return r0
|
425
|
+
end
|
426
|
+
|
427
|
+
module String0
|
428
|
+
def hex
|
429
|
+
elements[1]
|
430
|
+
end
|
431
|
+
|
432
|
+
def hex
|
433
|
+
elements[2]
|
434
|
+
end
|
435
|
+
|
436
|
+
def hex
|
437
|
+
elements[3]
|
438
|
+
end
|
439
|
+
|
440
|
+
def hex
|
441
|
+
elements[4]
|
442
|
+
end
|
443
|
+
end
|
444
|
+
|
445
|
+
module String1
|
446
|
+
end
|
447
|
+
|
448
|
+
module String2
|
449
|
+
end
|
450
|
+
|
451
|
+
module String3
|
452
|
+
def value
|
453
|
+
eval(text_value)
|
454
|
+
end
|
455
|
+
end
|
456
|
+
|
457
|
+
def _nt_string
|
458
|
+
start_index = index
|
459
|
+
if node_cache[:string].has_key?(index)
|
460
|
+
cached = node_cache[:string][index]
|
461
|
+
@index = cached.interval.end if cached
|
462
|
+
return cached
|
463
|
+
end
|
464
|
+
|
465
|
+
i0, s0 = index, []
|
466
|
+
if input.index('"', index) == index
|
467
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
468
|
+
@index += 1
|
469
|
+
else
|
470
|
+
terminal_parse_failure('"')
|
471
|
+
r1 = nil
|
472
|
+
end
|
473
|
+
s0 << r1
|
474
|
+
if r1
|
475
|
+
s2, i2 = [], index
|
476
|
+
loop do
|
477
|
+
i3 = index
|
478
|
+
i4, s4 = index, []
|
479
|
+
if input.index('\\', index) == index
|
480
|
+
r5 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
481
|
+
@index += 1
|
482
|
+
else
|
483
|
+
terminal_parse_failure('\\')
|
484
|
+
r5 = nil
|
485
|
+
end
|
486
|
+
s4 << r5
|
487
|
+
if r5
|
488
|
+
i6 = index
|
489
|
+
if input.index('"', index) == index
|
490
|
+
r7 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
491
|
+
@index += 1
|
492
|
+
else
|
493
|
+
terminal_parse_failure('"')
|
494
|
+
r7 = nil
|
495
|
+
end
|
496
|
+
if r7
|
497
|
+
r6 = r7
|
498
|
+
else
|
499
|
+
if input.index('\\', index) == index
|
500
|
+
r8 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
501
|
+
@index += 1
|
502
|
+
else
|
503
|
+
terminal_parse_failure('\\')
|
504
|
+
r8 = nil
|
505
|
+
end
|
506
|
+
if r8
|
507
|
+
r6 = r8
|
508
|
+
else
|
509
|
+
if input.index('/', index) == index
|
510
|
+
r9 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
511
|
+
@index += 1
|
512
|
+
else
|
513
|
+
terminal_parse_failure('/')
|
514
|
+
r9 = nil
|
515
|
+
end
|
516
|
+
if r9
|
517
|
+
r6 = r9
|
518
|
+
else
|
519
|
+
if input.index('b', index) == index
|
520
|
+
r10 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
521
|
+
@index += 1
|
522
|
+
else
|
523
|
+
terminal_parse_failure('b')
|
524
|
+
r10 = nil
|
525
|
+
end
|
526
|
+
if r10
|
527
|
+
r6 = r10
|
528
|
+
else
|
529
|
+
if input.index('f', index) == index
|
530
|
+
r11 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
531
|
+
@index += 1
|
532
|
+
else
|
533
|
+
terminal_parse_failure('f')
|
534
|
+
r11 = nil
|
535
|
+
end
|
536
|
+
if r11
|
537
|
+
r6 = r11
|
538
|
+
else
|
539
|
+
if input.index('n', index) == index
|
540
|
+
r12 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
541
|
+
@index += 1
|
542
|
+
else
|
543
|
+
terminal_parse_failure('n')
|
544
|
+
r12 = nil
|
545
|
+
end
|
546
|
+
if r12
|
547
|
+
r6 = r12
|
548
|
+
else
|
549
|
+
if input.index('r', index) == index
|
550
|
+
r13 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
551
|
+
@index += 1
|
552
|
+
else
|
553
|
+
terminal_parse_failure('r')
|
554
|
+
r13 = nil
|
555
|
+
end
|
556
|
+
if r13
|
557
|
+
r6 = r13
|
558
|
+
else
|
559
|
+
if input.index('t', index) == index
|
560
|
+
r14 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
561
|
+
@index += 1
|
562
|
+
else
|
563
|
+
terminal_parse_failure('t')
|
564
|
+
r14 = nil
|
565
|
+
end
|
566
|
+
if r14
|
567
|
+
r6 = r14
|
568
|
+
else
|
569
|
+
i15, s15 = index, []
|
570
|
+
if input.index('u', index) == index
|
571
|
+
r16 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
572
|
+
@index += 1
|
573
|
+
else
|
574
|
+
terminal_parse_failure('u')
|
575
|
+
r16 = nil
|
576
|
+
end
|
577
|
+
s15 << r16
|
578
|
+
if r16
|
579
|
+
r17 = _nt_hex
|
580
|
+
s15 << r17
|
581
|
+
if r17
|
582
|
+
r18 = _nt_hex
|
583
|
+
s15 << r18
|
584
|
+
if r18
|
585
|
+
r19 = _nt_hex
|
586
|
+
s15 << r19
|
587
|
+
if r19
|
588
|
+
r20 = _nt_hex
|
589
|
+
s15 << r20
|
590
|
+
end
|
591
|
+
end
|
592
|
+
end
|
593
|
+
end
|
594
|
+
if s15.last
|
595
|
+
r15 = instantiate_node(SyntaxNode,input, i15...index, s15)
|
596
|
+
r15.extend(String0)
|
597
|
+
else
|
598
|
+
self.index = i15
|
599
|
+
r15 = nil
|
600
|
+
end
|
601
|
+
if r15
|
602
|
+
r6 = r15
|
603
|
+
else
|
604
|
+
self.index = i6
|
605
|
+
r6 = nil
|
606
|
+
end
|
607
|
+
end
|
608
|
+
end
|
609
|
+
end
|
610
|
+
end
|
611
|
+
end
|
612
|
+
end
|
613
|
+
end
|
614
|
+
end
|
615
|
+
s4 << r6
|
616
|
+
end
|
617
|
+
if s4.last
|
618
|
+
r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
|
619
|
+
r4.extend(String1)
|
620
|
+
else
|
621
|
+
self.index = i4
|
622
|
+
r4 = nil
|
623
|
+
end
|
624
|
+
if r4
|
625
|
+
r3 = r4
|
626
|
+
else
|
627
|
+
if input.index(Regexp.new('[^\\"\\\\]'), index) == index
|
628
|
+
r21 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
629
|
+
@index += 1
|
630
|
+
else
|
631
|
+
r21 = nil
|
632
|
+
end
|
633
|
+
if r21
|
634
|
+
r3 = r21
|
635
|
+
else
|
636
|
+
self.index = i3
|
637
|
+
r3 = nil
|
638
|
+
end
|
639
|
+
end
|
640
|
+
if r3
|
641
|
+
s2 << r3
|
642
|
+
else
|
643
|
+
break
|
644
|
+
end
|
645
|
+
end
|
646
|
+
r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
|
647
|
+
s0 << r2
|
648
|
+
if r2
|
649
|
+
if input.index('"', index) == index
|
650
|
+
r22 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
651
|
+
@index += 1
|
652
|
+
else
|
653
|
+
terminal_parse_failure('"')
|
654
|
+
r22 = nil
|
655
|
+
end
|
656
|
+
s0 << r22
|
657
|
+
end
|
658
|
+
end
|
659
|
+
if s0.last
|
660
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
661
|
+
r0.extend(String2)
|
662
|
+
r0.extend(String3)
|
663
|
+
else
|
664
|
+
self.index = i0
|
665
|
+
r0 = nil
|
666
|
+
end
|
667
|
+
|
668
|
+
node_cache[:string][start_index] = r0
|
669
|
+
|
670
|
+
return r0
|
671
|
+
end
|
672
|
+
|
673
|
+
module Number0
|
674
|
+
end
|
675
|
+
|
676
|
+
module Number1
|
677
|
+
end
|
678
|
+
|
679
|
+
module Number2
|
680
|
+
end
|
681
|
+
|
682
|
+
module Number3
|
683
|
+
end
|
684
|
+
|
685
|
+
module Number4
|
686
|
+
def value
|
687
|
+
eval(text_value)
|
688
|
+
end
|
689
|
+
end
|
690
|
+
|
691
|
+
def _nt_number
|
692
|
+
start_index = index
|
693
|
+
if node_cache[:number].has_key?(index)
|
694
|
+
cached = node_cache[:number][index]
|
695
|
+
@index = cached.interval.end if cached
|
696
|
+
return cached
|
697
|
+
end
|
698
|
+
|
699
|
+
i0, s0 = index, []
|
700
|
+
if input.index("-", index) == index
|
701
|
+
r2 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
702
|
+
@index += 1
|
703
|
+
else
|
704
|
+
terminal_parse_failure("-")
|
705
|
+
r2 = nil
|
706
|
+
end
|
707
|
+
if r2
|
708
|
+
r1 = r2
|
709
|
+
else
|
710
|
+
r1 = instantiate_node(SyntaxNode,input, index...index)
|
711
|
+
end
|
712
|
+
s0 << r1
|
713
|
+
if r1
|
714
|
+
i3 = index
|
715
|
+
if input.index("0", index) == index
|
716
|
+
r4 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
717
|
+
@index += 1
|
718
|
+
else
|
719
|
+
terminal_parse_failure("0")
|
720
|
+
r4 = nil
|
721
|
+
end
|
722
|
+
if r4
|
723
|
+
r3 = r4
|
724
|
+
else
|
725
|
+
i5, s5 = index, []
|
726
|
+
if input.index(Regexp.new('[1-9]'), index) == index
|
727
|
+
r6 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
728
|
+
@index += 1
|
729
|
+
else
|
730
|
+
r6 = nil
|
731
|
+
end
|
732
|
+
s5 << r6
|
733
|
+
if r6
|
734
|
+
s7, i7 = [], index
|
735
|
+
loop do
|
736
|
+
r8 = _nt_digit
|
737
|
+
if r8
|
738
|
+
s7 << r8
|
739
|
+
else
|
740
|
+
break
|
741
|
+
end
|
742
|
+
end
|
743
|
+
r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
|
744
|
+
s5 << r7
|
745
|
+
end
|
746
|
+
if s5.last
|
747
|
+
r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
|
748
|
+
r5.extend(Number0)
|
749
|
+
else
|
750
|
+
self.index = i5
|
751
|
+
r5 = nil
|
752
|
+
end
|
753
|
+
if r5
|
754
|
+
r3 = r5
|
755
|
+
else
|
756
|
+
self.index = i3
|
757
|
+
r3 = nil
|
758
|
+
end
|
759
|
+
end
|
760
|
+
s0 << r3
|
761
|
+
if r3
|
762
|
+
i10, s10 = index, []
|
763
|
+
if input.index(".", index) == index
|
764
|
+
r11 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
765
|
+
@index += 1
|
766
|
+
else
|
767
|
+
terminal_parse_failure(".")
|
768
|
+
r11 = nil
|
769
|
+
end
|
770
|
+
s10 << r11
|
771
|
+
if r11
|
772
|
+
s12, i12 = [], index
|
773
|
+
loop do
|
774
|
+
r13 = _nt_digit
|
775
|
+
if r13
|
776
|
+
s12 << r13
|
777
|
+
else
|
778
|
+
break
|
779
|
+
end
|
780
|
+
end
|
781
|
+
if s12.empty?
|
782
|
+
self.index = i12
|
783
|
+
r12 = nil
|
784
|
+
else
|
785
|
+
r12 = instantiate_node(SyntaxNode,input, i12...index, s12)
|
786
|
+
end
|
787
|
+
s10 << r12
|
788
|
+
end
|
789
|
+
if s10.last
|
790
|
+
r10 = instantiate_node(SyntaxNode,input, i10...index, s10)
|
791
|
+
r10.extend(Number1)
|
792
|
+
else
|
793
|
+
self.index = i10
|
794
|
+
r10 = nil
|
795
|
+
end
|
796
|
+
if r10
|
797
|
+
r9 = r10
|
798
|
+
else
|
799
|
+
r9 = instantiate_node(SyntaxNode,input, index...index)
|
800
|
+
end
|
801
|
+
s0 << r9
|
802
|
+
if r9
|
803
|
+
i15, s15 = index, []
|
804
|
+
if input.index(Regexp.new('[eE]'), index) == index
|
805
|
+
r16 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
806
|
+
@index += 1
|
807
|
+
else
|
808
|
+
r16 = nil
|
809
|
+
end
|
810
|
+
s15 << r16
|
811
|
+
if r16
|
812
|
+
if input.index(Regexp.new('[+-]'), index) == index
|
813
|
+
r18 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
814
|
+
@index += 1
|
815
|
+
else
|
816
|
+
r18 = nil
|
817
|
+
end
|
818
|
+
if r18
|
819
|
+
r17 = r18
|
820
|
+
else
|
821
|
+
r17 = instantiate_node(SyntaxNode,input, index...index)
|
822
|
+
end
|
823
|
+
s15 << r17
|
824
|
+
if r17
|
825
|
+
s19, i19 = [], index
|
826
|
+
loop do
|
827
|
+
r20 = _nt_digit
|
828
|
+
if r20
|
829
|
+
s19 << r20
|
830
|
+
else
|
831
|
+
break
|
832
|
+
end
|
833
|
+
end
|
834
|
+
if s19.empty?
|
835
|
+
self.index = i19
|
836
|
+
r19 = nil
|
837
|
+
else
|
838
|
+
r19 = instantiate_node(SyntaxNode,input, i19...index, s19)
|
839
|
+
end
|
840
|
+
s15 << r19
|
841
|
+
end
|
842
|
+
end
|
843
|
+
if s15.last
|
844
|
+
r15 = instantiate_node(SyntaxNode,input, i15...index, s15)
|
845
|
+
r15.extend(Number2)
|
846
|
+
else
|
847
|
+
self.index = i15
|
848
|
+
r15 = nil
|
849
|
+
end
|
850
|
+
if r15
|
851
|
+
r14 = r15
|
852
|
+
else
|
853
|
+
r14 = instantiate_node(SyntaxNode,input, index...index)
|
854
|
+
end
|
855
|
+
s0 << r14
|
856
|
+
end
|
857
|
+
end
|
858
|
+
end
|
859
|
+
if s0.last
|
860
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
861
|
+
r0.extend(Number3)
|
862
|
+
r0.extend(Number4)
|
863
|
+
else
|
864
|
+
self.index = i0
|
865
|
+
r0 = nil
|
866
|
+
end
|
867
|
+
|
868
|
+
node_cache[:number][start_index] = r0
|
869
|
+
|
870
|
+
return r0
|
871
|
+
end
|
872
|
+
|
873
|
+
def _nt_digit
|
874
|
+
start_index = index
|
875
|
+
if node_cache[:digit].has_key?(index)
|
876
|
+
cached = node_cache[:digit][index]
|
877
|
+
@index = cached.interval.end if cached
|
878
|
+
return cached
|
879
|
+
end
|
880
|
+
|
881
|
+
if input.index(Regexp.new('[0-9]'), index) == index
|
882
|
+
r0 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
883
|
+
@index += 1
|
884
|
+
else
|
885
|
+
r0 = nil
|
886
|
+
end
|
887
|
+
|
888
|
+
node_cache[:digit][start_index] = r0
|
889
|
+
|
890
|
+
return r0
|
891
|
+
end
|
892
|
+
|
893
|
+
def _nt_hex
|
894
|
+
start_index = index
|
895
|
+
if node_cache[:hex].has_key?(index)
|
896
|
+
cached = node_cache[:hex][index]
|
897
|
+
@index = cached.interval.end if cached
|
898
|
+
return cached
|
899
|
+
end
|
900
|
+
|
901
|
+
i0 = index
|
902
|
+
if input.index(Regexp.new('[a-f]'), index) == index
|
903
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
904
|
+
@index += 1
|
905
|
+
else
|
906
|
+
r1 = nil
|
907
|
+
end
|
908
|
+
if r1
|
909
|
+
r0 = r1
|
910
|
+
else
|
911
|
+
r2 = _nt_digit
|
912
|
+
if r2
|
913
|
+
r0 = r2
|
914
|
+
else
|
915
|
+
self.index = i0
|
916
|
+
r0 = nil
|
917
|
+
end
|
918
|
+
end
|
919
|
+
|
920
|
+
node_cache[:hex][start_index] = r0
|
921
|
+
|
922
|
+
return r0
|
923
|
+
end
|
924
|
+
|
925
|
+
module True0
|
926
|
+
def value; true; end
|
927
|
+
end
|
928
|
+
|
929
|
+
def _nt_true
|
930
|
+
start_index = index
|
931
|
+
if node_cache[:true].has_key?(index)
|
932
|
+
cached = node_cache[:true][index]
|
933
|
+
@index = cached.interval.end if cached
|
934
|
+
return cached
|
935
|
+
end
|
936
|
+
|
937
|
+
if input.index("true", index) == index
|
938
|
+
r0 = instantiate_node(SyntaxNode,input, index...(index + 4))
|
939
|
+
r0.extend(True0)
|
940
|
+
@index += 4
|
941
|
+
else
|
942
|
+
terminal_parse_failure("true")
|
943
|
+
r0 = nil
|
944
|
+
end
|
945
|
+
|
946
|
+
node_cache[:true][start_index] = r0
|
947
|
+
|
948
|
+
return r0
|
949
|
+
end
|
950
|
+
|
951
|
+
module False0
|
952
|
+
def value; false; end
|
953
|
+
end
|
954
|
+
|
955
|
+
def _nt_false
|
956
|
+
start_index = index
|
957
|
+
if node_cache[:false].has_key?(index)
|
958
|
+
cached = node_cache[:false][index]
|
959
|
+
@index = cached.interval.end if cached
|
960
|
+
return cached
|
961
|
+
end
|
962
|
+
|
963
|
+
if input.index("false", index) == index
|
964
|
+
r0 = instantiate_node(SyntaxNode,input, index...(index + 5))
|
965
|
+
r0.extend(False0)
|
966
|
+
@index += 5
|
967
|
+
else
|
968
|
+
terminal_parse_failure("false")
|
969
|
+
r0 = nil
|
970
|
+
end
|
971
|
+
|
972
|
+
node_cache[:false][start_index] = r0
|
973
|
+
|
974
|
+
return r0
|
975
|
+
end
|
976
|
+
|
977
|
+
module Null0
|
978
|
+
def value; nil; end
|
979
|
+
end
|
980
|
+
|
981
|
+
def _nt_null
|
982
|
+
start_index = index
|
983
|
+
if node_cache[:null].has_key?(index)
|
984
|
+
cached = node_cache[:null][index]
|
985
|
+
@index = cached.interval.end if cached
|
986
|
+
return cached
|
987
|
+
end
|
988
|
+
|
989
|
+
if input.index("null", index) == index
|
990
|
+
r0 = instantiate_node(SyntaxNode,input, index...(index + 4))
|
991
|
+
r0.extend(Null0)
|
992
|
+
@index += 4
|
993
|
+
else
|
994
|
+
terminal_parse_failure("null")
|
995
|
+
r0 = nil
|
996
|
+
end
|
997
|
+
|
998
|
+
node_cache[:null][start_index] = r0
|
999
|
+
|
1000
|
+
return r0
|
1001
|
+
end
|
1002
|
+
|
1003
|
+
def _nt_space
|
1004
|
+
start_index = index
|
1005
|
+
if node_cache[:space].has_key?(index)
|
1006
|
+
cached = node_cache[:space][index]
|
1007
|
+
@index = cached.interval.end if cached
|
1008
|
+
return cached
|
1009
|
+
end
|
1010
|
+
|
1011
|
+
s0, i0 = [], index
|
1012
|
+
loop do
|
1013
|
+
if input.index(Regexp.new('[\\s\\n\\t]'), index) == index
|
1014
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
1015
|
+
@index += 1
|
1016
|
+
else
|
1017
|
+
r1 = nil
|
1018
|
+
end
|
1019
|
+
if r1
|
1020
|
+
s0 << r1
|
1021
|
+
else
|
1022
|
+
break
|
1023
|
+
end
|
1024
|
+
end
|
1025
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
1026
|
+
|
1027
|
+
node_cache[:space][start_index] = r0
|
1028
|
+
|
1029
|
+
return r0
|
1030
|
+
end
|
1031
|
+
|
1032
|
+
end
|
1033
|
+
|
1034
|
+
class JsonParser < Treetop::Runtime::CompiledParser
|
1035
|
+
include Json
|
1036
|
+
end
|
1037
|
+
|
1038
|
+
end
|
1039
|
+
|