@@ -55,8 +55,8 @@ makeItemString(string *s)
55
55
else
56
56
{
57
57
v = makeItemType (jpiString);
58
- v->string .val = s->val ;
59
- v->string .len = s->len ;
58
+ v->value . string .val = s->val ;
59
+ v->value . string .len = s->len ;
60
60
}
61
61
62
62
return v;
@@ -68,8 +68,8 @@ makeItemVariable(string *s)
68
68
JsonPathParseItem *v;
69
69
70
70
v = makeItemType (jpiVariable);
71
- v->string .val = s->val ;
72
- v->string .len = s->len ;
71
+ v->value . string .val = s->val ;
72
+ v->value . string .len = s->len ;
73
73
74
74
return v;
75
75
}
@@ -91,7 +91,8 @@ makeItemNumeric(string *s)
91
91
JsonPathParseItem *v;
92
92
93
93
v = makeItemType (jpiNumeric);
94
- v->numeric = DatumGetNumeric (DirectFunctionCall3 (numeric_in, CStringGetDatum (s->val ), 0 , -1 ));
94
+ v->value .numeric =
95
+ DatumGetNumeric (DirectFunctionCall3 (numeric_in, CStringGetDatum (s->val ), 0 , -1 ));
95
96
96
97
return v;
97
98
}
@@ -100,7 +101,7 @@ static JsonPathParseItem*
100
101
makeItemBool (bool val) {
101
102
JsonPathParseItem *v = makeItemType (jpiBool);
102
103
103
- v->boolean = val;
104
+ v->value . boolean = val;
104
105
105
106
return v;
106
107
}
@@ -110,8 +111,8 @@ makeItemBinary(int type, JsonPathParseItem* la, JsonPathParseItem *ra)
110
111
{
111
112
JsonPathParseItem *v = makeItemType (type);
112
113
113
- v->args .left = la;
114
- v->args .right = ra;
114
+ v->value . args .left = la;
115
+ v->value . args .right = ra;
115
116
116
117
return v;
117
118
}
@@ -127,15 +128,15 @@ makeItemUnary(int type, JsonPathParseItem* a)
127
128
if (type == jpiMinus && a->type == jpiNumeric && !a->next )
128
129
{
129
130
v = makeItemType (jpiNumeric);
130
- v->numeric =
131
+ v->value . numeric =
131
132
DatumGetNumeric (DirectFunctionCall1 (numeric_uminus,
132
- NumericGetDatum (a->numeric )));
133
+ NumericGetDatum (a->value . numeric )));
133
134
return v;
134
135
}
135
136
136
137
v = makeItemType (type);
137
138
138
- v->arg = a;
139
+ v->value . arg = a;
139
140
140
141
return v;
141
142
}
@@ -169,12 +170,12 @@ makeIndexArray(List *list)
169
170
int i = 0 ;
170
171
171
172
Assert (list_length (list) > 0 );
172
- v->array .nelems = list_length (list);
173
+ v->value . array .nelems = list_length (list);
173
174
174
- v->array .elems = palloc (sizeof (v->array .elems [0 ]) * v->array .nelems );
175
+ v->value . array .elems = palloc (sizeof (v->value . array .elems [0 ]) * v->value . array .nelems );
175
176
176
177
foreach (cell, list)
177
- v->array .elems [i++] = lfirst_int (cell);
178
+ v->value . array .elems [i++] = lfirst_int (cell);
178
179
179
180
return v;
180
181
}
@@ -184,8 +185,8 @@ makeAny(int first, int last)
184
185
{
185
186
JsonPathParseItem *v = makeItemType (jpiAny);
186
187
187
- v->anybounds .first = (first > 0 ) ? first : 0 ;
188
- v->anybounds .last = (last >= 0 ) ? last : PG_UINT32_MAX;
188
+ v->value . anybounds .first = (first > 0 ) ? first : 0 ;
189
+ v->value . anybounds .last = (last >= 0 ) ? last : PG_UINT32_MAX;
189
190
190
191
return v;
191
192
}
@@ -202,7 +203,7 @@ makeAny(int first, int last)
202
203
%union {
203
204
string str;
204
205
List *elems; /* list of JsonPathParseItem */
205
- List *indexs;
206
+ List *indexs; /* list of integers */
206
207
JsonPathParseItem *value;
207
208
int optype;
208
209
}
@@ -213,11 +214,10 @@ makeAny(int first, int last)
213
214
%token <str> LESS_P LESSEQUAL_P EQUAL_P NOTEQUAL_P GREATEREQUAL_P GREATER_P
214
215
%token <str> ANY_P
215
216
216
- %type <value> result jsonpath scalar_value path_primary expr pexpr
217
- array_accessor any_path accessor_op key
218
- predicate delimited_predicate
217
+ %type <value> result scalar_value path_primary expr pexpr array_accessor
218
+ any_path accessor_op key predicate delimited_predicate
219
219
220
- %type <elems> accessor_expr /* path absolute_path relative_path */
220
+ %type <elems> accessor_expr
221
221
222
222
%type <indexs> index_elem index_list
223
223
@@ -235,7 +235,7 @@ makeAny(int first, int last)
235
235
%%
236
236
237
237
result :
238
- jsonpath { *result = $1 ; }
238
+ expr { *result = $1 ; }
239
239
| /* EMPTY */ { *result = NULL ; }
240
240
;
241
241
@@ -249,10 +249,6 @@ scalar_value:
249
249
| VARIABLE_P { $$ = makeItemVariable(&$1 ); }
250
250
;
251
251
252
- jsonpath :
253
- expr
254
- ;
255
-
256
252
comp_op :
257
253
EQUAL_P { $$ = jpiEqual; }
258
254
| NOTEQUAL_P { $$ = jpiNotEqual; }
@@ -269,16 +265,18 @@ delimited_predicate:
269
265
270
266
predicate :
271
267
delimited_predicate { $$ = $1 ; }
272
- | pexpr comp_op pexpr { $$ = makeItemBinary($2 , $1 , $3 ); }
273
- // | expr LIKE_REGEX pattern { $$ = ...; }
274
- // | expr STARTS WITH STRING_P { $$ = ...; }
275
- // | expr STARTS WITH ' $' STRING_P { $$ = ...; }
276
- // | expr STARTS WITH ' $' STRING_P { $$ = ...; }
277
- // | ' .' any_key right_expr { $$ = makeItemList(list_make2($2 , $3 )); }
278
- | ' (' predicate ' )' IS_P UNKNOWN_P { $$ = makeItemUnary(jpiIsUnknown, $2 ); }
268
+ | pexpr comp_op pexpr { $$ = makeItemBinary($2 , $1 , $3 ); }
279
269
| predicate AND_P predicate { $$ = makeItemBinary(jpiAnd, $1 , $3 ); }
280
270
| predicate OR_P predicate { $$ = makeItemBinary(jpiOr, $1 , $3 ); }
281
271
| NOT_P delimited_predicate { $$ = makeItemUnary(jpiNot, $2 ); }
272
+ | ' (' predicate ' )' IS_P UNKNOWN_P { $$ = makeItemUnary(jpiIsUnknown, $2 ); }
273
+ /*
274
+ Left for the future
275
+ | pexpr LIKE_REGEX pattern { $$ = ...; }
276
+ | pexpr STARTS WITH STRING_P { $$ = ...; }
277
+ | pexpr STARTS WITH '$' STRING_P { $$ = ...; }
278
+ | pexpr STARTS WITH '$' STRING_P { $$ = ...; }
279
+ */
282
280
;
283
281
284
282
path_primary :
@@ -363,23 +361,5 @@ key:
363
361
| UNKNOWN_P { $$ = makeItemKey(&$1 ); }
364
362
| EXISTS_P { $$ = makeItemKey(&$1 ); }
365
363
;
366
- /*
367
- absolute_path:
368
- '$' { $$ = list_make1(makeItemType(jpiRoot)); }
369
- | '$' path { $$ = lcons(makeItemType(jpiRoot), $2); }
370
- ;
371
-
372
- relative_path:
373
- key { $$ = list_make1(makeItemType(jpiCurrent), $1); }
374
- | key path { $$ = lcons(makeItemType(jpiCurrent), lcons($1, $2)); }
375
- | '@' { $$ = list_make1(makeItemType(jpiCurrent)); }
376
- | '@' path { $$ = lcons(makeItemType(jpiCurrent), $2); }
377
- ;
378
-
379
- path:
380
- accessor_op { $$ = list_make($1); }
381
- | path accessor_op { $$ = lappend($1, $2); }
382
- ;
383
- */
384
364
%%
385
365
0 commit comments