jpt 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/jpt.gemspec +1 -1
  3. data/lib/jpt.rb +20 -8
  4. data/lib/parser/jptgrammar.rb +355 -323
  5. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 11f0008d935a2ce891b13af68fe35da1984c733c6d36cc03a3490749ac5deaa6
4
- data.tar.gz: fbe7f467057066b07c70fb6f37628f0b105b08e8da560af4f99f3a94aa3336d8
3
+ metadata.gz: b5cd5e1be60d226440d14670f9fc40383d68ce388e9e7cef676912959024a58d
4
+ data.tar.gz: 774cd3d70e96d9bc57cf1b55549a71cba3f3cebd084e90c8ccc28cb89562e620
5
5
  SHA512:
6
- metadata.gz: ecc6e9084048e7d9253fd14c175acc83e932caad33817790579d1f53000bca8efc89cf350fead4255b27fa9b72ec1fd67a6b67c9f0ccfbee4b1c9a23ee40b11e
7
- data.tar.gz: 4a7a95f87230e35d9c5437aba5da7593f9a08bdbedabc09d56d4143dd72254e1c224c06f9fbc725d64a75a68c286db44ae601bb358af4926c8ac1c56c8708e23
6
+ metadata.gz: 0a304a2b0562e0ccb5553fc28d3dea48714bed50c5c6bdaae37ebf2577d5eae9b5c55937b91fba3dc9571146e7371aba7850f97ae00727b9ff5d9e1db77f0eb1
7
+ data.tar.gz: 718acc8d15e8a56fb23f3147adf8c68ab6ef40710df1bda90e29c4ed323d29d810a8cebfa20f1197078d56e04351f49194e3614e42139cd16b646517544aa758
data/jpt.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "jpt"
3
- s.version = "0.1.0"
3
+ s.version = "0.1.2"
4
4
  s.summary = "JSONPath tools"
5
5
  s.description = %q{jpt implements converters and miscellaneous tools for JSONPath}
6
6
  s.author = "Carsten Bormann"
data/lib/jpt.rb CHANGED
@@ -15,6 +15,13 @@ module JPTType
15
15
  FUNCTABLE[name] = sig.chars.map {FUNCSIG_CHARS[_1]}
16
16
  end
17
17
 
18
+ def query_singular?(ast)
19
+ case ast
20
+ in [("@" | "$"), *segments]
21
+ ! segments.any? {|segment| Array === segment}
22
+ end
23
+ end
24
+
18
25
  def declared_type(ast)
19
26
  case ast
20
27
  in Numeric | String | false | true | nil
@@ -39,7 +46,9 @@ module JPTType
39
46
  case [dt, rt]
40
47
  in a, b if a == b
41
48
  true
42
- in [:nodes, :value] | [:nodes, :logical]
49
+ in [:nodes, :value]
50
+ query_singular?(ast)
51
+ in [:nodes, :logical]
43
52
  true
44
53
  else
45
54
  warn "*** Cannot use #{ast} with declared_type #{dt||:undefined} for required type #{rt}#{s}"
@@ -216,7 +225,7 @@ class JPT
216
225
 
217
226
  def filt_to_logical(val)
218
227
  case val
219
- in [:nodes, v]
228
+ in [(:nodes|:onenode), v]
220
229
  v != []
221
230
  in [:logical, v]
222
231
  v
@@ -225,10 +234,11 @@ class JPT
225
234
 
226
235
  def filt_to_value(val)
227
236
  case val
228
- in [:nodes, v]
229
- if v.length == 1
237
+ in [:onenode, v]
238
+ case v.length
239
+ in 1
230
240
  v[0]
231
- else
241
+ in 0
232
242
  :nothing
233
243
  end
234
244
  in [:value, v]
@@ -242,9 +252,11 @@ class JPT
242
252
  # warn "***B #{logexp.inspect} #{root_node.inspect} #{curr_node.inspect}"
243
253
  case logexp
244
254
  in ["@", *]
245
- [:nodes, select_query(logexp, curr_node, root_node, curr_node)]
255
+ rt = query_singular?(logexp) ? :onenode : :nodes
256
+ [rt, select_query(logexp, curr_node, root_node, curr_node)]
246
257
  in ["$", *]
247
- [:nodes, select_query(logexp, root_node, root_node, curr_node)]
258
+ rt = query_singular?(logexp) ? :onenode : :nodes
259
+ [rt, select_query(logexp, root_node, root_node, curr_node)]
248
260
  in [("==" | "!=" | "<" | ">" | "<=" | ">="), a, b]
249
261
  lhs = filt_to_value(filt_apply(a, root_node, curr_node)) rescue :nothing
250
262
  rhs = filt_to_value(filt_apply(b, root_node, curr_node)) rescue :nothing
@@ -299,7 +311,7 @@ class JPT
299
311
  in ["func", "count", nodes]
300
312
  ty, nodes = filt_apply(nodes, root_node, curr_node)
301
313
  [:value,
302
- if ty != :nodes
314
+ if ty != :nodes && ty != :onenode
303
315
  warn "*** func count ty #{ty.inspect}"
304
316
  0
305
317
  else
@@ -10,7 +10,7 @@ module JPTGRAMMAR
10
10
  end
11
11
 
12
12
  module Jptgrammar0
13
- def json_path
13
+ def jsonpath_query
14
14
  elements[0]
15
15
  end
16
16
 
@@ -21,7 +21,7 @@ module JPTGRAMMAR
21
21
 
22
22
  module Jptgrammar1
23
23
  def ast
24
- json_path.ast
24
+ jsonpath_query.ast
25
25
  end
26
26
  end
27
27
 
@@ -37,7 +37,7 @@ module JPTGRAMMAR
37
37
  end
38
38
 
39
39
  i0, s0 = index, []
40
- r1 = _nt_json_path
40
+ r1 = _nt_jsonpath_query
41
41
  s0 << r1
42
42
  if r1
43
43
  r2 = _nt_S
@@ -57,7 +57,7 @@ module JPTGRAMMAR
57
57
  r0
58
58
  end
59
59
 
60
- module JsonPath0
60
+ module JsonpathQuery0
61
61
  def root_identifier
62
62
  elements[0]
63
63
  end
@@ -67,18 +67,18 @@ module JPTGRAMMAR
67
67
  end
68
68
  end
69
69
 
70
- module JsonPath1
70
+ module JsonpathQuery1
71
71
  def ast
72
72
  ["$", *segments.ast]
73
73
  end
74
74
  end
75
75
 
76
- def _nt_json_path
76
+ def _nt_jsonpath_query
77
77
  start_index = index
78
- if node_cache[:json_path].has_key?(index)
79
- cached = node_cache[:json_path][index]
78
+ if node_cache[:jsonpath_query].has_key?(index)
79
+ cached = node_cache[:jsonpath_query][index]
80
80
  if cached
81
- node_cache[:json_path][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
81
+ node_cache[:jsonpath_query][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
82
82
  @index = cached.interval.end
83
83
  end
84
84
  return cached
@@ -93,14 +93,14 @@ module JPTGRAMMAR
93
93
  end
94
94
  if s0.last
95
95
  r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
96
- r0.extend(JsonPath0)
97
- r0.extend(JsonPath1)
96
+ r0.extend(JsonpathQuery0)
97
+ r0.extend(JsonpathQuery1)
98
98
  else
99
99
  @index = i0
100
100
  r0 = nil
101
101
  end
102
102
 
103
- node_cache[:json_path][start_index] = r0
103
+ node_cache[:jsonpath_query][start_index] = r0
104
104
 
105
105
  r0
106
106
  end
@@ -163,6 +163,101 @@ module JPTGRAMMAR
163
163
  r0
164
164
  end
165
165
 
166
+ def _nt_B
167
+ start_index = index
168
+ if node_cache[:B].has_key?(index)
169
+ cached = node_cache[:B][index]
170
+ if cached
171
+ node_cache[:B][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
172
+ @index = cached.interval.end
173
+ end
174
+ return cached
175
+ end
176
+
177
+ i0 = index
178
+ if (match_len = has_terminal?(" ", false, index))
179
+ r1 = true
180
+ @index += match_len
181
+ else
182
+ terminal_parse_failure('" "')
183
+ r1 = nil
184
+ end
185
+ if r1
186
+ r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
187
+ r0 = r1
188
+ else
189
+ if (match_len = has_terminal?("\t", false, index))
190
+ r2 = true
191
+ @index += match_len
192
+ else
193
+ terminal_parse_failure('"\\t"')
194
+ r2 = nil
195
+ end
196
+ if r2
197
+ r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
198
+ r0 = r2
199
+ else
200
+ if (match_len = has_terminal?("\n", false, index))
201
+ r3 = true
202
+ @index += match_len
203
+ else
204
+ terminal_parse_failure('"\\n"')
205
+ r3 = nil
206
+ end
207
+ if r3
208
+ r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
209
+ r0 = r3
210
+ else
211
+ if (match_len = has_terminal?("\r", false, index))
212
+ r4 = true
213
+ @index += match_len
214
+ else
215
+ terminal_parse_failure('"\\r"')
216
+ r4 = nil
217
+ end
218
+ if r4
219
+ r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
220
+ r0 = r4
221
+ else
222
+ @index = i0
223
+ r0 = nil
224
+ end
225
+ end
226
+ end
227
+ end
228
+
229
+ node_cache[:B][start_index] = r0
230
+
231
+ r0
232
+ end
233
+
234
+ def _nt_S
235
+ start_index = index
236
+ if node_cache[:S].has_key?(index)
237
+ cached = node_cache[:S][index]
238
+ if cached
239
+ node_cache[:S][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
240
+ @index = cached.interval.end
241
+ end
242
+ return cached
243
+ end
244
+
245
+ s0, i0 = [], index
246
+ loop do
247
+ r1 = _nt_B
248
+ if r1
249
+ s0 << r1
250
+ else
251
+ break
252
+ end
253
+ end
254
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
255
+
256
+ node_cache[:S][start_index] = r0
257
+
258
+ r0
259
+ end
260
+
166
261
  def _nt_root_identifier
167
262
  start_index = index
168
263
  if node_cache[:root_identifier].has_key?(index)
@@ -692,11 +787,11 @@ module JPTGRAMMAR
692
787
  r0.extend(Unescaped0)
693
788
  r0.extend(Unescaped0)
694
789
  else
695
- if has_terminal?(@regexps[gr = '\A[\\]-􏿿]'] ||= Regexp.new(gr), :regexp, index)
790
+ if has_terminal?(@regexps[gr = '\A[\\]-퟿]'] ||= Regexp.new(gr), :regexp, index)
696
791
  r4 = true
697
792
  @index += 1
698
793
  else
699
- terminal_parse_failure('[\\]-􏿿]')
794
+ terminal_parse_failure('[\\]-퟿]')
700
795
  r4 = nil
701
796
  end
702
797
  if r4
@@ -705,8 +800,22 @@ module JPTGRAMMAR
705
800
  r0.extend(Unescaped0)
706
801
  r0.extend(Unescaped0)
707
802
  else
708
- @index = i0
709
- r0 = nil
803
+ if has_terminal?(@regexps[gr = '\A[-􏿿]'] ||= Regexp.new(gr), :regexp, index)
804
+ r5 = true
805
+ @index += 1
806
+ else
807
+ terminal_parse_failure('[-􏿿]')
808
+ r5 = nil
809
+ end
810
+ if r5
811
+ r5 = SyntaxNode.new(input, (index-1)...index) if r5 == true
812
+ r0 = r5
813
+ r0.extend(Unescaped0)
814
+ r0.extend(Unescaped0)
815
+ else
816
+ @index = i0
817
+ r0 = nil
818
+ end
710
819
  end
711
820
  end
712
821
  end
@@ -1887,114 +1996,19 @@ module JPTGRAMMAR
1887
1996
  r0
1888
1997
  end
1889
1998
 
1890
- def _nt_B
1891
- start_index = index
1892
- if node_cache[:B].has_key?(index)
1893
- cached = node_cache[:B][index]
1894
- if cached
1895
- node_cache[:B][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
1896
- @index = cached.interval.end
1897
- end
1898
- return cached
1899
- end
1900
-
1901
- i0 = index
1902
- if (match_len = has_terminal?(" ", false, index))
1903
- r1 = true
1904
- @index += match_len
1905
- else
1906
- terminal_parse_failure('" "')
1907
- r1 = nil
1908
- end
1909
- if r1
1910
- r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
1911
- r0 = r1
1912
- else
1913
- if (match_len = has_terminal?("\t", false, index))
1914
- r2 = true
1915
- @index += match_len
1916
- else
1917
- terminal_parse_failure('"\\t"')
1918
- r2 = nil
1919
- end
1920
- if r2
1921
- r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
1922
- r0 = r2
1923
- else
1924
- if (match_len = has_terminal?("\n", false, index))
1925
- r3 = true
1926
- @index += match_len
1927
- else
1928
- terminal_parse_failure('"\\n"')
1929
- r3 = nil
1930
- end
1931
- if r3
1932
- r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
1933
- r0 = r3
1934
- else
1935
- if (match_len = has_terminal?("\r", false, index))
1936
- r4 = true
1937
- @index += match_len
1938
- else
1939
- terminal_parse_failure('"\\r"')
1940
- r4 = nil
1941
- end
1942
- if r4
1943
- r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
1944
- r0 = r4
1945
- else
1946
- @index = i0
1947
- r0 = nil
1948
- end
1949
- end
1950
- end
1951
- end
1952
-
1953
- node_cache[:B][start_index] = r0
1954
-
1955
- r0
1956
- end
1957
-
1958
- def _nt_S
1959
- start_index = index
1960
- if node_cache[:S].has_key?(index)
1961
- cached = node_cache[:S][index]
1962
- if cached
1963
- node_cache[:S][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
1964
- @index = cached.interval.end
1965
- end
1966
- return cached
1967
- end
1968
-
1969
- s0, i0 = [], index
1970
- loop do
1971
- r1 = _nt_B
1972
- if r1
1973
- s0 << r1
1974
- else
1975
- break
1976
- end
1977
- end
1978
- r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
1979
-
1980
- node_cache[:S][start_index] = r0
1981
-
1982
- r0
1983
- end
1984
-
1985
1999
  module FilterSelector0
1986
2000
  def S
1987
2001
  elements[1]
1988
2002
  end
1989
2003
 
1990
- def boolean_expr
2004
+ def logical_expr
1991
2005
  elements[2]
1992
2006
  end
1993
2007
  end
1994
2008
 
1995
2009
  module FilterSelector1
1996
2010
  def ast
1997
- ["filt", boolean_expr.ast]
2011
+ ["filt", logical_expr.ast]
1998
2012
  end
1999
2013
  end
2000
2014
 
@@ -2022,7 +2036,7 @@ module JPTGRAMMAR
2022
2036
  r2 = _nt_S
2023
2037
  s0 << r2
2024
2038
  if r2
2025
- r3 = _nt_boolean_expr
2039
+ r3 = _nt_logical_expr
2026
2040
  s0 << r3
2027
2041
  end
2028
2042
  end
@@ -2040,12 +2054,12 @@ module JPTGRAMMAR
2040
2054
  r0
2041
2055
  end
2042
2056
 
2043
- def _nt_boolean_expr
2057
+ def _nt_logical_expr
2044
2058
  start_index = index
2045
- if node_cache[:boolean_expr].has_key?(index)
2046
- cached = node_cache[:boolean_expr][index]
2059
+ if node_cache[:logical_expr].has_key?(index)
2060
+ cached = node_cache[:logical_expr][index]
2047
2061
  if cached
2048
- node_cache[:boolean_expr][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
2062
+ node_cache[:logical_expr][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
2049
2063
  @index = cached.interval.end
2050
2064
  end
2051
2065
  return cached
@@ -2053,7 +2067,7 @@ module JPTGRAMMAR
2053
2067
 
2054
2068
  r0 = _nt_logical_or_expr
2055
2069
 
2056
- node_cache[:boolean_expr][start_index] = r0
2070
+ node_cache[:logical_expr][start_index] = r0
2057
2071
 
2058
2072
  r0
2059
2073
  end
@@ -2294,6 +2308,143 @@ module JPTGRAMMAR
2294
2308
  r0
2295
2309
  end
2296
2310
 
2311
+ module ParenExpr0
2312
+ def logical_not_op
2313
+ elements[0]
2314
+ end
2315
+
2316
+ def S
2317
+ elements[1]
2318
+ end
2319
+ end
2320
+
2321
+ module ParenExpr1
2322
+ def S1
2323
+ elements[2]
2324
+ end
2325
+
2326
+ def logical_expr
2327
+ elements[3]
2328
+ end
2329
+
2330
+ def S2
2331
+ elements[4]
2332
+ end
2333
+
2334
+ end
2335
+
2336
+ module ParenExpr2
2337
+ def ast
2338
+ if elements[0].text_value == ''
2339
+ elements[3].ast
2340
+ else
2341
+ ["not", elements[3].ast]
2342
+ end
2343
+ end
2344
+ end
2345
+
2346
+ def _nt_paren_expr
2347
+ start_index = index
2348
+ if node_cache[:paren_expr].has_key?(index)
2349
+ cached = node_cache[:paren_expr][index]
2350
+ if cached
2351
+ node_cache[:paren_expr][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
2352
+ @index = cached.interval.end
2353
+ end
2354
+ return cached
2355
+ end
2356
+
2357
+ i0, s0 = index, []
2358
+ i2, s2 = index, []
2359
+ r3 = _nt_logical_not_op
2360
+ s2 << r3
2361
+ if r3
2362
+ r4 = _nt_S
2363
+ s2 << r4
2364
+ end
2365
+ if s2.last
2366
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
2367
+ r2.extend(ParenExpr0)
2368
+ else
2369
+ @index = i2
2370
+ r2 = nil
2371
+ end
2372
+ if r2
2373
+ r1 = r2
2374
+ else
2375
+ r1 = instantiate_node(SyntaxNode,input, index...index)
2376
+ end
2377
+ s0 << r1
2378
+ if r1
2379
+ if (match_len = has_terminal?("(", false, index))
2380
+ r5 = true
2381
+ @index += match_len
2382
+ else
2383
+ terminal_parse_failure('"("')
2384
+ r5 = nil
2385
+ end
2386
+ s0 << r5
2387
+ if r5
2388
+ r6 = _nt_S
2389
+ s0 << r6
2390
+ if r6
2391
+ r7 = _nt_logical_expr
2392
+ s0 << r7
2393
+ if r7
2394
+ r8 = _nt_S
2395
+ s0 << r8
2396
+ if r8
2397
+ if (match_len = has_terminal?(")", false, index))
2398
+ r9 = true
2399
+ @index += match_len
2400
+ else
2401
+ terminal_parse_failure('")"')
2402
+ r9 = nil
2403
+ end
2404
+ s0 << r9
2405
+ end
2406
+ end
2407
+ end
2408
+ end
2409
+ end
2410
+ if s0.last
2411
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
2412
+ r0.extend(ParenExpr1)
2413
+ r0.extend(ParenExpr2)
2414
+ else
2415
+ @index = i0
2416
+ r0 = nil
2417
+ end
2418
+
2419
+ node_cache[:paren_expr][start_index] = r0
2420
+
2421
+ r0
2422
+ end
2423
+
2424
+ def _nt_logical_not_op
2425
+ start_index = index
2426
+ if node_cache[:logical_not_op].has_key?(index)
2427
+ cached = node_cache[:logical_not_op][index]
2428
+ if cached
2429
+ node_cache[:logical_not_op][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
2430
+ @index = cached.interval.end
2431
+ end
2432
+ return cached
2433
+ end
2434
+
2435
+ if (match_len = has_terminal?("!", false, index))
2436
+ r0 = instantiate_node(SyntaxNode,input, index...(index + match_len))
2437
+ @index += match_len
2438
+ else
2439
+ terminal_parse_failure('"!"')
2440
+ r0 = nil
2441
+ end
2442
+
2443
+ node_cache[:logical_not_op][start_index] = r0
2444
+
2445
+ r0
2446
+ end
2447
+
2297
2448
  module TestExpr0
2298
2449
  def logical_not_op
2299
2450
  elements[0]
@@ -2355,7 +2506,7 @@ module JPTGRAMMAR
2355
2506
  s0 << r1
2356
2507
  if r1
2357
2508
  i5 = index
2358
- r6 = _nt_filter_path
2509
+ r6 = _nt_filter_query
2359
2510
  if r6
2360
2511
  r6 = SyntaxNode.new(input, (index-1)...index) if r6 == true
2361
2512
  r5 = r6
@@ -2385,24 +2536,24 @@ module JPTGRAMMAR
2385
2536
  r0
2386
2537
  end
2387
2538
 
2388
- def _nt_filter_path
2539
+ def _nt_filter_query
2389
2540
  start_index = index
2390
- if node_cache[:filter_path].has_key?(index)
2391
- cached = node_cache[:filter_path][index]
2541
+ if node_cache[:filter_query].has_key?(index)
2542
+ cached = node_cache[:filter_query][index]
2392
2543
  if cached
2393
- node_cache[:filter_path][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
2544
+ node_cache[:filter_query][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
2394
2545
  @index = cached.interval.end
2395
2546
  end
2396
2547
  return cached
2397
2548
  end
2398
2549
 
2399
2550
  i0 = index
2400
- r1 = _nt_rel_path
2551
+ r1 = _nt_rel_query
2401
2552
  if r1
2402
2553
  r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
2403
2554
  r0 = r1
2404
2555
  else
2405
- r2 = _nt_json_path
2556
+ r2 = _nt_jsonpath_query
2406
2557
  if r2
2407
2558
  r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
2408
2559
  r0 = r2
@@ -2412,12 +2563,12 @@ module JPTGRAMMAR
2412
2563
  end
2413
2564
  end
2414
2565
 
2415
- node_cache[:filter_path][start_index] = r0
2566
+ node_cache[:filter_query][start_index] = r0
2416
2567
 
2417
2568
  r0
2418
2569
  end
2419
2570
 
2420
- module RelPath0
2571
+ module RelQuery0
2421
2572
  def current_node_identifier
2422
2573
  elements[0]
2423
2574
  end
@@ -2427,18 +2578,18 @@ module JPTGRAMMAR
2427
2578
  end
2428
2579
  end
2429
2580
 
2430
- module RelPath1
2581
+ module RelQuery1
2431
2582
  def ast
2432
2583
  ["@", *segments.ast]
2433
2584
  end
2434
2585
  end
2435
2586
 
2436
- def _nt_rel_path
2587
+ def _nt_rel_query
2437
2588
  start_index = index
2438
- if node_cache[:rel_path].has_key?(index)
2439
- cached = node_cache[:rel_path][index]
2589
+ if node_cache[:rel_query].has_key?(index)
2590
+ cached = node_cache[:rel_query][index]
2440
2591
  if cached
2441
- node_cache[:rel_path][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
2592
+ node_cache[:rel_query][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
2442
2593
  @index = cached.interval.end
2443
2594
  end
2444
2595
  return cached
@@ -2453,14 +2604,14 @@ module JPTGRAMMAR
2453
2604
  end
2454
2605
  if s0.last
2455
2606
  r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
2456
- r0.extend(RelPath0)
2457
- r0.extend(RelPath1)
2607
+ r0.extend(RelQuery0)
2608
+ r0.extend(RelQuery1)
2458
2609
  else
2459
2610
  @index = i0
2460
2611
  r0 = nil
2461
2612
  end
2462
2613
 
2463
- node_cache[:rel_path][start_index] = r0
2614
+ node_cache[:rel_query][start_index] = r0
2464
2615
 
2465
2616
  r0
2466
2617
  end
@@ -2489,143 +2640,6 @@ module JPTGRAMMAR
2489
2640
  r0
2490
2641
  end
2491
2642
 
2492
- module ParenExpr0
2493
- def logical_not_op
2494
- elements[0]
2495
- end
2496
-
2497
- def S
2498
- elements[1]
2499
- end
2500
- end
2501
-
2502
- module ParenExpr1
2503
- def S1
2504
- elements[2]
2505
- end
2506
-
2507
- def boolean_expr
2508
- elements[3]
2509
- end
2510
-
2511
- def S2
2512
- elements[4]
2513
- end
2514
-
2515
- end
2516
-
2517
- module ParenExpr2
2518
- def ast
2519
- if elements[0].text_value == ''
2520
- elements[3].ast
2521
- else
2522
- ["not", elements[3].ast]
2523
- end
2524
- end
2525
- end
2526
-
2527
- def _nt_paren_expr
2528
- start_index = index
2529
- if node_cache[:paren_expr].has_key?(index)
2530
- cached = node_cache[:paren_expr][index]
2531
- if cached
2532
- node_cache[:paren_expr][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
2533
- @index = cached.interval.end
2534
- end
2535
- return cached
2536
- end
2537
-
2538
- i0, s0 = index, []
2539
- i2, s2 = index, []
2540
- r3 = _nt_logical_not_op
2541
- s2 << r3
2542
- if r3
2543
- r4 = _nt_S
2544
- s2 << r4
2545
- end
2546
- if s2.last
2547
- r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
2548
- r2.extend(ParenExpr0)
2549
- else
2550
- @index = i2
2551
- r2 = nil
2552
- end
2553
- if r2
2554
- r1 = r2
2555
- else
2556
- r1 = instantiate_node(SyntaxNode,input, index...index)
2557
- end
2558
- s0 << r1
2559
- if r1
2560
- if (match_len = has_terminal?("(", false, index))
2561
- r5 = true
2562
- @index += match_len
2563
- else
2564
- terminal_parse_failure('"("')
2565
- r5 = nil
2566
- end
2567
- s0 << r5
2568
- if r5
2569
- r6 = _nt_S
2570
- s0 << r6
2571
- if r6
2572
- r7 = _nt_boolean_expr
2573
- s0 << r7
2574
- if r7
2575
- r8 = _nt_S
2576
- s0 << r8
2577
- if r8
2578
- if (match_len = has_terminal?(")", false, index))
2579
- r9 = true
2580
- @index += match_len
2581
- else
2582
- terminal_parse_failure('")"')
2583
- r9 = nil
2584
- end
2585
- s0 << r9
2586
- end
2587
- end
2588
- end
2589
- end
2590
- end
2591
- if s0.last
2592
- r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
2593
- r0.extend(ParenExpr1)
2594
- r0.extend(ParenExpr2)
2595
- else
2596
- @index = i0
2597
- r0 = nil
2598
- end
2599
-
2600
- node_cache[:paren_expr][start_index] = r0
2601
-
2602
- r0
2603
- end
2604
-
2605
- def _nt_logical_not_op
2606
- start_index = index
2607
- if node_cache[:logical_not_op].has_key?(index)
2608
- cached = node_cache[:logical_not_op][index]
2609
- if cached
2610
- node_cache[:logical_not_op][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
2611
- @index = cached.interval.end
2612
- end
2613
- return cached
2614
- end
2615
-
2616
- if (match_len = has_terminal?("!", false, index))
2617
- r0 = instantiate_node(SyntaxNode,input, index...(index + match_len))
2618
- @index += match_len
2619
- else
2620
- terminal_parse_failure('"!"')
2621
- r0 = nil
2622
- end
2623
-
2624
- node_cache[:logical_not_op][start_index] = r0
2625
-
2626
- r0
2627
- end
2628
-
2629
2643
  module ComparisonExpr0
2630
2644
  def comparable1
2631
2645
  elements[0]
@@ -2769,7 +2783,7 @@ module JPTGRAMMAR
2769
2783
  r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
2770
2784
  r0 = r1
2771
2785
  else
2772
- r2 = _nt_singular_path
2786
+ r2 = _nt_singular_query
2773
2787
  if r2
2774
2788
  r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
2775
2789
  r0 = r2
@@ -2882,24 +2896,24 @@ module JPTGRAMMAR
2882
2896
  r0
2883
2897
  end
2884
2898
 
2885
- def _nt_singular_path
2899
+ def _nt_singular_query
2886
2900
  start_index = index
2887
- if node_cache[:singular_path].has_key?(index)
2888
- cached = node_cache[:singular_path][index]
2901
+ if node_cache[:singular_query].has_key?(index)
2902
+ cached = node_cache[:singular_query][index]
2889
2903
  if cached
2890
- node_cache[:singular_path][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
2904
+ node_cache[:singular_query][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
2891
2905
  @index = cached.interval.end
2892
2906
  end
2893
2907
  return cached
2894
2908
  end
2895
2909
 
2896
2910
  i0 = index
2897
- r1 = _nt_rel_singular_path
2911
+ r1 = _nt_rel_singular_query
2898
2912
  if r1
2899
2913
  r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
2900
2914
  r0 = r1
2901
2915
  else
2902
- r2 = _nt_abs_singular_path
2916
+ r2 = _nt_abs_singular_query
2903
2917
  if r2
2904
2918
  r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
2905
2919
  r0 = r2
@@ -2909,33 +2923,33 @@ module JPTGRAMMAR
2909
2923
  end
2910
2924
  end
2911
2925
 
2912
- node_cache[:singular_path][start_index] = r0
2926
+ node_cache[:singular_query][start_index] = r0
2913
2927
 
2914
2928
  r0
2915
2929
  end
2916
2930
 
2917
- module RelSingularPath0
2931
+ module RelSingularQuery0
2918
2932
  def current_node_identifier
2919
2933
  elements[0]
2920
2934
  end
2921
2935
 
2922
- def singular_path_segments
2936
+ def singular_query_segments
2923
2937
  elements[1]
2924
2938
  end
2925
2939
  end
2926
2940
 
2927
- module RelSingularPath1
2941
+ module RelSingularQuery1
2928
2942
  def ast
2929
- ["@", *singular_path_segments.ast]
2943
+ ["@", *singular_query_segments.ast]
2930
2944
  end
2931
2945
  end
2932
2946
 
2933
- def _nt_rel_singular_path
2947
+ def _nt_rel_singular_query
2934
2948
  start_index = index
2935
- if node_cache[:rel_singular_path].has_key?(index)
2936
- cached = node_cache[:rel_singular_path][index]
2949
+ if node_cache[:rel_singular_query].has_key?(index)
2950
+ cached = node_cache[:rel_singular_query][index]
2937
2951
  if cached
2938
- node_cache[:rel_singular_path][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
2952
+ node_cache[:rel_singular_query][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
2939
2953
  @index = cached.interval.end
2940
2954
  end
2941
2955
  return cached
@@ -2945,45 +2959,45 @@ module JPTGRAMMAR
2945
2959
  r1 = _nt_current_node_identifier
2946
2960
  s0 << r1
2947
2961
  if r1
2948
- r2 = _nt_singular_path_segments
2962
+ r2 = _nt_singular_query_segments
2949
2963
  s0 << r2
2950
2964
  end
2951
2965
  if s0.last
2952
2966
  r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
2953
- r0.extend(RelSingularPath0)
2954
- r0.extend(RelSingularPath1)
2967
+ r0.extend(RelSingularQuery0)
2968
+ r0.extend(RelSingularQuery1)
2955
2969
  else
2956
2970
  @index = i0
2957
2971
  r0 = nil
2958
2972
  end
2959
2973
 
2960
- node_cache[:rel_singular_path][start_index] = r0
2974
+ node_cache[:rel_singular_query][start_index] = r0
2961
2975
 
2962
2976
  r0
2963
2977
  end
2964
2978
 
2965
- module AbsSingularPath0
2979
+ module AbsSingularQuery0
2966
2980
  def root_identifier
2967
2981
  elements[0]
2968
2982
  end
2969
2983
 
2970
- def singular_path_segments
2984
+ def singular_query_segments
2971
2985
  elements[1]
2972
2986
  end
2973
2987
  end
2974
2988
 
2975
- module AbsSingularPath1
2989
+ module AbsSingularQuery1
2976
2990
  def ast
2977
- ["$", *singular_path_segments.ast]
2991
+ ["$", *singular_query_segments.ast]
2978
2992
  end
2979
2993
  end
2980
2994
 
2981
- def _nt_abs_singular_path
2995
+ def _nt_abs_singular_query
2982
2996
  start_index = index
2983
- if node_cache[:abs_singular_path].has_key?(index)
2984
- cached = node_cache[:abs_singular_path][index]
2997
+ if node_cache[:abs_singular_query].has_key?(index)
2998
+ cached = node_cache[:abs_singular_query][index]
2985
2999
  if cached
2986
- node_cache[:abs_singular_path][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
3000
+ node_cache[:abs_singular_query][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
2987
3001
  @index = cached.interval.end
2988
3002
  end
2989
3003
  return cached
@@ -2993,42 +3007,42 @@ module JPTGRAMMAR
2993
3007
  r1 = _nt_root_identifier
2994
3008
  s0 << r1
2995
3009
  if r1
2996
- r2 = _nt_singular_path_segments
3010
+ r2 = _nt_singular_query_segments
2997
3011
  s0 << r2
2998
3012
  end
2999
3013
  if s0.last
3000
3014
  r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
3001
- r0.extend(AbsSingularPath0)
3002
- r0.extend(AbsSingularPath1)
3015
+ r0.extend(AbsSingularQuery0)
3016
+ r0.extend(AbsSingularQuery1)
3003
3017
  else
3004
3018
  @index = i0
3005
3019
  r0 = nil
3006
3020
  end
3007
3021
 
3008
- node_cache[:abs_singular_path][start_index] = r0
3022
+ node_cache[:abs_singular_query][start_index] = r0
3009
3023
 
3010
3024
  r0
3011
3025
  end
3012
3026
 
3013
- module SingularPathSegments0
3027
+ module SingularQuerySegments0
3014
3028
  def S
3015
3029
  elements[0]
3016
3030
  end
3017
3031
 
3018
3032
  end
3019
3033
 
3020
- module SingularPathSegments1
3034
+ module SingularQuerySegments1
3021
3035
  def ast
3022
3036
  elements.map{|el| el.elements[1]}.map(&:ast)
3023
3037
  end
3024
3038
  end
3025
3039
 
3026
- def _nt_singular_path_segments
3040
+ def _nt_singular_query_segments
3027
3041
  start_index = index
3028
- if node_cache[:singular_path_segments].has_key?(index)
3029
- cached = node_cache[:singular_path_segments][index]
3042
+ if node_cache[:singular_query_segments].has_key?(index)
3043
+ cached = node_cache[:singular_query_segments][index]
3030
3044
  if cached
3031
- node_cache[:singular_path_segments][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
3045
+ node_cache[:singular_query_segments][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
3032
3046
  @index = cached.interval.end
3033
3047
  end
3034
3048
  return cached
@@ -3059,7 +3073,7 @@ module JPTGRAMMAR
3059
3073
  end
3060
3074
  if s1.last
3061
3075
  r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
3062
- r1.extend(SingularPathSegments0)
3076
+ r1.extend(SingularQuerySegments0)
3063
3077
  else
3064
3078
  @index = i1
3065
3079
  r1 = nil
@@ -3071,10 +3085,10 @@ module JPTGRAMMAR
3071
3085
  end
3072
3086
  end
3073
3087
  r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
3074
- r0.extend(SingularPathSegments1)
3075
- r0.extend(SingularPathSegments1)
3088
+ r0.extend(SingularQuerySegments1)
3089
+ r0.extend(SingularQuerySegments1)
3076
3090
 
3077
- node_cache[:singular_path_segments][start_index] = r0
3091
+ node_cache[:singular_query_segments][start_index] = r0
3078
3092
 
3079
3093
  r0
3080
3094
  end
@@ -3869,18 +3883,24 @@ module JPTGRAMMAR
3869
3883
  r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
3870
3884
  r0 = r1
3871
3885
  else
3872
- r2 = _nt_filter_path
3886
+ r2 = _nt_filter_query
3873
3887
  if r2
3874
3888
  r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
3875
3889
  r0 = r2
3876
3890
  else
3877
- r3 = _nt_function_expr
3891
+ r3 = _nt_logical_expr
3878
3892
  if r3
3879
3893
  r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
3880
3894
  r0 = r3
3881
3895
  else
3882
- @index = i0
3883
- r0 = nil
3896
+ r4 = _nt_function_expr
3897
+ if r4
3898
+ r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
3899
+ r0 = r4
3900
+ else
3901
+ @index = i0
3902
+ r0 = nil
3903
+ end
3884
3904
  end
3885
3905
  end
3886
3906
  end
@@ -4215,19 +4235,31 @@ module JPTGRAMMAR
4215
4235
  r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
4216
4236
  r0 = r2
4217
4237
  else
4218
- if has_terminal?(@regexps[gr = '\A[€-􏿿]'] ||= Regexp.new(gr), :regexp, index)
4238
+ if has_terminal?(@regexps[gr = '\A[€-퟿]'] ||= Regexp.new(gr), :regexp, index)
4219
4239
  r3 = true
4220
4240
  @index += 1
4221
4241
  else
4222
- terminal_parse_failure('[€-􏿿]')
4242
+ terminal_parse_failure('[€-퟿]')
4223
4243
  r3 = nil
4224
4244
  end
4225
4245
  if r3
4226
4246
  r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
4227
4247
  r0 = r3
4228
4248
  else
4229
- @index = i0
4230
- r0 = nil
4249
+ if has_terminal?(@regexps[gr = '\A[-􏿿]'] ||= Regexp.new(gr), :regexp, index)
4250
+ r4 = true
4251
+ @index += 1
4252
+ else
4253
+ terminal_parse_failure('[-􏿿]')
4254
+ r4 = nil
4255
+ end
4256
+ if r4
4257
+ r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
4258
+ r0 = r4
4259
+ else
4260
+ @index = i0
4261
+ r0 = nil
4262
+ end
4231
4263
  end
4232
4264
  end
4233
4265
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jpt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Bormann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-23 00:00:00.000000000 Z
11
+ date: 2023-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
85
  requirements: []
86
- rubygems_version: 3.4.2
86
+ rubygems_version: 3.4.10
87
87
  signing_key:
88
88
  specification_version: 4
89
89
  summary: JSONPath tools