json_select 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,7 @@
1
1
  # Autogenerated from a Treetop grammar. Edits may be lost.
2
2
 
3
3
 
4
- module JSONSelect
5
- module SelectorParser
4
+ module JSONSelect::Selector
6
5
  include Treetop::Runtime
7
6
 
8
7
  def root
@@ -11,18 +10,19 @@ module SelectorParser
11
10
 
12
11
  module SelectorsGroup0
13
12
  def c
14
- elements[1]
13
+ elements[3]
15
14
  end
16
15
  end
17
16
 
18
17
  module SelectorsGroup1
19
18
  def a
20
- elements[0]
19
+ elements[1]
21
20
  end
22
21
 
23
22
  def b
24
- elements[1]
23
+ elements[2]
25
24
  end
25
+
26
26
  end
27
27
 
28
28
  def _nt_selectors_group
@@ -37,39 +37,91 @@ module SelectorParser
37
37
  end
38
38
 
39
39
  i0, s0 = index, []
40
- r1 = _nt_selector
40
+ s1, i1 = [], index
41
+ loop do
42
+ r2 = _nt_ws
43
+ if r2
44
+ s1 << r2
45
+ else
46
+ break
47
+ end
48
+ end
49
+ r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
41
50
  s0 << r1
42
51
  if r1
43
- s2, i2 = [], index
44
- loop do
45
- i3, s3 = index, []
46
- if has_terminal?(',', false, index)
47
- r4 = instantiate_node(SyntaxNode,input, index...(index + 1))
48
- @index += 1
49
- else
50
- terminal_parse_failure(',')
51
- r4 = nil
52
+ r3 = _nt_selector
53
+ s0 << r3
54
+ if r3
55
+ s4, i4 = [], index
56
+ loop do
57
+ i5, s5 = index, []
58
+ s6, i6 = [], index
59
+ loop do
60
+ r7 = _nt_ws
61
+ if r7
62
+ s6 << r7
63
+ else
64
+ break
65
+ end
66
+ end
67
+ r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
68
+ s5 << r6
69
+ if r6
70
+ if has_terminal?(',', false, index)
71
+ r8 = instantiate_node(SyntaxNode,input, index...(index + 1))
72
+ @index += 1
73
+ else
74
+ terminal_parse_failure(',')
75
+ r8 = nil
76
+ end
77
+ s5 << r8
78
+ if r8
79
+ s9, i9 = [], index
80
+ loop do
81
+ r10 = _nt_ws
82
+ if r10
83
+ s9 << r10
84
+ else
85
+ break
86
+ end
87
+ end
88
+ r9 = instantiate_node(SyntaxNode,input, i9...index, s9)
89
+ s5 << r9
90
+ if r9
91
+ r11 = _nt_selector
92
+ s5 << r11
93
+ end
94
+ end
95
+ end
96
+ if s5.last
97
+ r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
98
+ r5.extend(SelectorsGroup0)
99
+ else
100
+ @index = i5
101
+ r5 = nil
102
+ end
103
+ if r5
104
+ s4 << r5
105
+ else
106
+ break
107
+ end
52
108
  end
53
- s3 << r4
109
+ r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
110
+ s0 << r4
54
111
  if r4
55
- r5 = _nt_selector
56
- s3 << r5
57
- end
58
- if s3.last
59
- r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
60
- r3.extend(SelectorsGroup0)
61
- else
62
- @index = i3
63
- r3 = nil
64
- end
65
- if r3
66
- s2 << r3
67
- else
68
- break
112
+ s12, i12 = [], index
113
+ loop do
114
+ r13 = _nt_ws
115
+ if r13
116
+ s12 << r13
117
+ else
118
+ break
119
+ end
120
+ end
121
+ r12 = instantiate_node(SyntaxNode,input, i12...index, s12)
122
+ s0 << r12
69
123
  end
70
124
  end
71
- r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
72
- s0 << r2
73
125
  end
74
126
  if s0.last
75
127
  r0 = instantiate_node(JSONSelect::Ast::SelectorGroup,input, i0...index, s0)
@@ -157,6 +209,9 @@ module SelectorParser
157
209
  r0
158
210
  end
159
211
 
212
+ module Combinator0
213
+ end
214
+
160
215
  def _nt_combinator
161
216
  start_index = index
162
217
  if node_cache[:combinator].has_key?(index)
@@ -169,38 +224,68 @@ module SelectorParser
169
224
  end
170
225
 
171
226
  i0 = index
172
- if has_terminal?('>', false, index)
173
- r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
174
- @index += 1
227
+ i1, s1 = index, []
228
+ s2, i2 = [], index
229
+ loop do
230
+ r3 = _nt_ws
231
+ if r3
232
+ s2 << r3
233
+ else
234
+ break
235
+ end
236
+ end
237
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
238
+ s1 << r2
239
+ if r2
240
+ if has_terminal?('>', false, index)
241
+ r4 = instantiate_node(SyntaxNode,input, index...(index + 1))
242
+ @index += 1
243
+ else
244
+ terminal_parse_failure('>')
245
+ r4 = nil
246
+ end
247
+ s1 << r4
248
+ if r4
249
+ s5, i5 = [], index
250
+ loop do
251
+ r6 = _nt_ws
252
+ if r6
253
+ s5 << r6
254
+ else
255
+ break
256
+ end
257
+ end
258
+ r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
259
+ s1 << r5
260
+ end
261
+ end
262
+ if s1.last
263
+ r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
264
+ r1.extend(Combinator0)
175
265
  else
176
- terminal_parse_failure('>')
266
+ @index = i1
177
267
  r1 = nil
178
268
  end
179
269
  if r1
180
270
  r0 = r1
181
271
  else
182
- s2, i2 = [], index
272
+ s7, i7 = [], index
183
273
  loop do
184
- if has_terminal?('\G[\\s]', true, index)
185
- r3 = true
186
- @index += 1
187
- else
188
- r3 = nil
189
- end
190
- if r3
191
- s2 << r3
274
+ r8 = _nt_ws
275
+ if r8
276
+ s7 << r8
192
277
  else
193
278
  break
194
279
  end
195
280
  end
196
- if s2.empty?
197
- @index = i2
198
- r2 = nil
281
+ if s7.empty?
282
+ @index = i7
283
+ r7 = nil
199
284
  else
200
- r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
285
+ r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
201
286
  end
202
- if r2
203
- r0 = r2
287
+ if r7
288
+ r0 = r7
204
289
  else
205
290
  @index = i0
206
291
  r0 = nil
@@ -534,7 +619,7 @@ module SelectorParser
534
619
  end
535
620
 
536
621
  def e
537
- elements[3]
622
+ elements[4]
538
623
  end
539
624
 
540
625
  end
@@ -596,17 +681,43 @@ module SelectorParser
596
681
  end
597
682
  s4 << r7
598
683
  if r7
599
- r8 = _nt_expression
684
+ s8, i8 = [], index
685
+ loop do
686
+ r9 = _nt_ws
687
+ if r9
688
+ s8 << r9
689
+ else
690
+ break
691
+ end
692
+ end
693
+ r8 = instantiate_node(SyntaxNode,input, i8...index, s8)
600
694
  s4 << r8
601
695
  if r8
602
- if has_terminal?(')', false, index)
603
- r9 = instantiate_node(SyntaxNode,input, index...(index + 1))
604
- @index += 1
605
- else
606
- terminal_parse_failure(')')
607
- r9 = nil
696
+ r10 = _nt_expression
697
+ s4 << r10
698
+ if r10
699
+ s11, i11 = [], index
700
+ loop do
701
+ r12 = _nt_ws
702
+ if r12
703
+ s11 << r12
704
+ else
705
+ break
706
+ end
707
+ end
708
+ r11 = instantiate_node(SyntaxNode,input, i11...index, s11)
709
+ s4 << r11
710
+ if r11
711
+ if has_terminal?(')', false, index)
712
+ r13 = instantiate_node(SyntaxNode,input, index...(index + 1))
713
+ @index += 1
714
+ else
715
+ terminal_parse_failure(')')
716
+ r13 = nil
717
+ end
718
+ s4 << r13
719
+ end
608
720
  end
609
- s4 << r9
610
721
  end
611
722
  end
612
723
  end
@@ -750,7 +861,7 @@ module SelectorParser
750
861
  end
751
862
 
752
863
  def c
753
- elements[3]
864
+ elements[4]
754
865
  end
755
866
  end
756
867
 
@@ -829,36 +940,62 @@ module SelectorParser
829
940
  end
830
941
  s3 << r8
831
942
  if r8
832
- i10, s10 = index, []
833
- if has_terminal?('\G[+-]', true, index)
834
- r11 = true
835
- @index += 1
836
- else
837
- r11 = nil
943
+ s9, i9 = [], index
944
+ loop do
945
+ r10 = _nt_ws
946
+ if r10
947
+ s9 << r10
948
+ else
949
+ break
950
+ end
838
951
  end
839
- s10 << r11
840
- if r11
841
- if has_terminal?('\G[0-9]', true, index)
842
- r12 = true
952
+ r9 = instantiate_node(SyntaxNode,input, i9...index, s9)
953
+ s3 << r9
954
+ if r9
955
+ i12, s12 = index, []
956
+ if has_terminal?('\G[+-]', true, index)
957
+ r13 = true
843
958
  @index += 1
844
959
  else
960
+ r13 = nil
961
+ end
962
+ s12 << r13
963
+ if r13
964
+ s14, i14 = [], index
965
+ loop do
966
+ r15 = _nt_ws
967
+ if r15
968
+ s14 << r15
969
+ else
970
+ break
971
+ end
972
+ end
973
+ r14 = instantiate_node(SyntaxNode,input, i14...index, s14)
974
+ s12 << r14
975
+ if r14
976
+ if has_terminal?('\G[0-9]', true, index)
977
+ r16 = true
978
+ @index += 1
979
+ else
980
+ r16 = nil
981
+ end
982
+ s12 << r16
983
+ end
984
+ end
985
+ if s12.last
986
+ r12 = instantiate_node(SyntaxNode,input, i12...index, s12)
987
+ r12.extend(Expression0)
988
+ else
989
+ @index = i12
845
990
  r12 = nil
846
991
  end
847
- s10 << r12
848
- end
849
- if s10.last
850
- r10 = instantiate_node(SyntaxNode,input, i10...index, s10)
851
- r10.extend(Expression0)
852
- else
853
- @index = i10
854
- r10 = nil
855
- end
856
- if r10
857
- r9 = r10
858
- else
859
- r9 = instantiate_node(SyntaxNode,input, index...index)
992
+ if r12
993
+ r11 = r12
994
+ else
995
+ r11 = instantiate_node(SyntaxNode,input, index...index)
996
+ end
997
+ s3 << r11
860
998
  end
861
- s3 << r9
862
999
  end
863
1000
  end
864
1001
  end
@@ -872,51 +1009,51 @@ module SelectorParser
872
1009
  if r3
873
1010
  r0 = r3
874
1011
  else
875
- i13, s13 = index, []
1012
+ i17, s17 = index, []
876
1013
  if has_terminal?('\G[+-]', true, index)
877
- r15 = true
1014
+ r19 = true
878
1015
  @index += 1
879
1016
  else
880
- r15 = nil
1017
+ r19 = nil
881
1018
  end
882
- if r15
883
- r14 = r15
1019
+ if r19
1020
+ r18 = r19
884
1021
  else
885
- r14 = instantiate_node(SyntaxNode,input, index...index)
1022
+ r18 = instantiate_node(SyntaxNode,input, index...index)
886
1023
  end
887
- s13 << r14
888
- if r14
889
- s16, i16 = [], index
1024
+ s17 << r18
1025
+ if r18
1026
+ s20, i20 = [], index
890
1027
  loop do
891
1028
  if has_terminal?('\G[0-9]', true, index)
892
- r17 = true
1029
+ r21 = true
893
1030
  @index += 1
894
1031
  else
895
- r17 = nil
1032
+ r21 = nil
896
1033
  end
897
- if r17
898
- s16 << r17
1034
+ if r21
1035
+ s20 << r21
899
1036
  else
900
1037
  break
901
1038
  end
902
1039
  end
903
- if s16.empty?
904
- @index = i16
905
- r16 = nil
1040
+ if s20.empty?
1041
+ @index = i20
1042
+ r20 = nil
906
1043
  else
907
- r16 = instantiate_node(SyntaxNode,input, i16...index, s16)
1044
+ r20 = instantiate_node(SyntaxNode,input, i20...index, s20)
908
1045
  end
909
- s13 << r16
1046
+ s17 << r20
910
1047
  end
911
- if s13.last
912
- r13 = instantiate_node(JSONSelect::Ast::SimpleExpr,input, i13...index, s13)
913
- r13.extend(Expression2)
1048
+ if s17.last
1049
+ r17 = instantiate_node(JSONSelect::Ast::SimpleExpr,input, i17...index, s17)
1050
+ r17.extend(Expression2)
914
1051
  else
915
- @index = i13
916
- r13 = nil
1052
+ @index = i17
1053
+ r17 = nil
917
1054
  end
918
- if r13
919
- r0 = r13
1055
+ if r17
1056
+ r0 = r17
920
1057
  else
921
1058
  @index = i0
922
1059
  r0 = nil
@@ -1242,10 +1379,32 @@ module SelectorParser
1242
1379
  r0
1243
1380
  end
1244
1381
 
1245
- end
1382
+ def _nt_ws
1383
+ start_index = index
1384
+ if node_cache[:ws].has_key?(index)
1385
+ cached = node_cache[:ws][index]
1386
+ if cached
1387
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
1388
+ @index = cached.interval.end
1389
+ end
1390
+ return cached
1391
+ end
1392
+
1393
+ if has_terminal?('\G[ \\t\\r\\n]', true, index)
1394
+ r0 = instantiate_node(SyntaxNode,input, index...(index + 1))
1395
+ @index += 1
1396
+ else
1397
+ r0 = nil
1398
+ end
1399
+
1400
+ node_cache[:ws][start_index] = r0
1401
+
1402
+ r0
1403
+ end
1246
1404
 
1247
- class SelectorParserParser < Treetop::Runtime::CompiledParser
1248
- include SelectorParser
1249
1405
  end
1250
1406
 
1407
+ class JSONSelect::SelectorParser < Treetop::Runtime::CompiledParser
1408
+ include JSONSelect::Selector
1251
1409
  end
1410
+