@@ -38,8 +38,8 @@ use nom::sequence::pair;
38
38
use nom:: sequence:: preceded;
39
39
use nom:: sequence:: separated_pair;
40
40
use nom:: sequence:: terminated;
41
- use nom:: sequence:: tuple;
42
41
use nom:: IResult ;
42
+ use nom:: Parser ;
43
43
44
44
use crate :: constants:: UNICODE_LEN ;
45
45
use crate :: error:: Error ;
@@ -65,7 +65,8 @@ fn json_path(input: &[u8]) -> IResult<&[u8], JsonPath<'_>> {
65
65
map (
66
66
delimited ( multispace0, expr_or_paths, multispace0) ,
67
67
|paths| JsonPath { paths } ,
68
- ) ( input)
68
+ )
69
+ . parse ( input)
69
70
}
70
71
71
72
fn check_escaped ( input : & [ u8 ] , i : & mut usize ) -> bool {
@@ -177,11 +178,12 @@ fn bracket_wildcard(input: &[u8]) -> IResult<&[u8], ()> {
177
178
delimited ( multispace0, char ( '*' ) , multispace0) ,
178
179
char ( ']' ) ,
179
180
) ,
180
- ) ( input)
181
+ )
182
+ . parse ( input)
181
183
}
182
184
183
185
fn recursive_dot_wildcard ( input : & [ u8 ] ) -> IResult < & [ u8 ] , Option < RecursiveLevel > > {
184
- preceded ( tag ( ".**" ) , opt ( recursive_level) ) ( input)
186
+ preceded ( tag ( ".**" ) , opt ( recursive_level) ) . parse ( input)
185
187
}
186
188
187
189
fn recursive_level ( input : & [ u8 ] ) -> IResult < & [ u8 ] , RecursiveLevel > {
@@ -202,7 +204,8 @@ fn recursive_level(input: &[u8]) -> IResult<&[u8], RecursiveLevel> {
202
204
end : None ,
203
205
} ,
204
206
) ,
205
- ) ) ( input)
207
+ ) )
208
+ . parse ( input)
206
209
}
207
210
208
211
fn recursive_level_range ( input : & [ u8 ] ) -> IResult < & [ u8 ] , RecursiveLevel > {
@@ -229,44 +232,47 @@ fn recursive_level_range(input: &[u8]) -> IResult<&[u8], RecursiveLevel> {
229
232
end : Some ( RecursiveLevelEnd :: Last ) ,
230
233
} ,
231
234
) ,
232
- ) ) ( input)
235
+ ) )
236
+ . parse ( input)
233
237
}
234
238
235
239
fn colon_field ( input : & [ u8 ] ) -> IResult < & [ u8 ] , Cow < ' _ , str > > {
236
- alt ( ( preceded ( char ( ':' ) , string) , preceded ( char ( ':' ) , raw_string) ) ) ( input)
240
+ alt ( ( preceded ( char ( ':' ) , string) , preceded ( char ( ':' ) , raw_string) ) ) . parse ( input)
237
241
}
238
242
239
243
fn dot_field ( input : & [ u8 ] ) -> IResult < & [ u8 ] , Cow < ' _ , str > > {
240
- alt ( ( preceded ( char ( '.' ) , string) , preceded ( char ( '.' ) , raw_string) ) ) ( input)
244
+ alt ( ( preceded ( char ( '.' ) , string) , preceded ( char ( '.' ) , raw_string) ) ) . parse ( input)
241
245
}
242
246
243
247
fn object_field ( input : & [ u8 ] ) -> IResult < & [ u8 ] , Cow < ' _ , str > > {
244
248
delimited (
245
249
terminated ( char ( '[' ) , multispace0) ,
246
250
string,
247
251
preceded ( multispace0, char ( ']' ) ) ,
248
- ) ( input)
252
+ )
253
+ . parse ( input)
249
254
}
250
255
251
256
fn index ( input : & [ u8 ] ) -> IResult < & [ u8 ] , Index > {
252
257
alt ( (
253
258
map ( i32, Index :: Index ) ,
254
259
map (
255
260
preceded (
256
- tuple ( ( tag_no_case ( "last" ) , multispace0, char ( '-' ) , multispace0 ) ) ,
257
- i32,
261
+ separated_pair ( tag_no_case ( "last" ) , multispace0, char ( '-' ) ) ,
262
+ preceded ( multispace0 , i32) ,
258
263
) ,
259
264
|v| Index :: LastIndex ( v. saturating_neg ( ) ) ,
260
265
) ,
261
266
map (
262
267
preceded (
263
- tuple ( ( tag_no_case ( "last" ) , multispace0, char ( '+' ) , multispace0 ) ) ,
264
- i32,
268
+ separated_pair ( tag_no_case ( "last" ) , multispace0, char ( '+' ) ) ,
269
+ preceded ( multispace0 , i32) ,
265
270
) ,
266
271
Index :: LastIndex ,
267
272
) ,
268
273
map ( tag_no_case ( "last" ) , |_| Index :: LastIndex ( 0 ) ) ,
269
- ) ) ( input)
274
+ ) )
275
+ . parse ( input)
270
276
}
271
277
272
278
fn array_index ( input : & [ u8 ] ) -> IResult < & [ u8 ] , ArrayIndex > {
@@ -280,15 +286,17 @@ fn array_index(input: &[u8]) -> IResult<&[u8], ArrayIndex> {
280
286
|( s, e) | ArrayIndex :: Slice ( ( s, e) ) ,
281
287
) ,
282
288
map ( index, ArrayIndex :: Index ) ,
283
- ) ) ( input)
289
+ ) )
290
+ . parse ( input)
284
291
}
285
292
286
293
fn array_indices ( input : & [ u8 ] ) -> IResult < & [ u8 ] , Vec < ArrayIndex > > {
287
294
delimited (
288
295
char ( '[' ) ,
289
296
separated_list1 ( char ( ',' ) , delimited ( multispace0, array_index, multispace0) ) ,
290
297
char ( ']' ) ,
291
- ) ( input)
298
+ )
299
+ . parse ( input)
292
300
}
293
301
294
302
fn inner_path ( input : & [ u8 ] ) -> IResult < & [ u8 ] , Path < ' _ > > {
@@ -300,7 +308,8 @@ fn inner_path(input: &[u8]) -> IResult<&[u8], Path<'_>> {
300
308
map ( dot_field, Path :: DotField ) ,
301
309
map ( array_indices, Path :: ArrayIndices ) ,
302
310
map ( object_field, Path :: ObjectField ) ,
303
- ) ) ( input)
311
+ ) )
312
+ . parse ( input)
304
313
}
305
314
306
315
// Compatible with Snowflake query syntax, the first field name does not require the leading period
@@ -310,7 +319,8 @@ fn pre_path(input: &[u8]) -> IResult<&[u8], Path<'_>> {
310
319
map ( delimited ( multispace0, raw_string, multispace0) , |v| {
311
320
Path :: DotField ( v)
312
321
} ) ,
313
- ) ) ( input)
322
+ ) )
323
+ . parse ( input)
314
324
}
315
325
316
326
fn path ( input : & [ u8 ] ) -> IResult < & [ u8 ] , Path < ' _ > > {
@@ -319,18 +329,20 @@ fn path(input: &[u8]) -> IResult<&[u8], Path<'_>> {
319
329
map ( delimited ( multispace0, filter_expr, multispace0) , |v| {
320
330
Path :: FilterExpr ( Box :: new ( v) )
321
331
} ) ,
322
- ) ) ( input)
332
+ ) )
333
+ . parse ( input)
323
334
}
324
335
325
336
fn expr_or_paths ( input : & [ u8 ] ) -> IResult < & [ u8 ] , Vec < Path < ' _ > > > {
326
- alt ( ( root_expr, paths) ) ( input)
337
+ alt ( ( root_expr, paths) ) . parse ( input)
327
338
}
328
339
329
340
fn root_expr ( input : & [ u8 ] ) -> IResult < & [ u8 ] , Vec < Path < ' _ > > > {
330
341
map (
331
342
delimited ( multispace0, |i| expr_or ( i, true ) , multispace0) ,
332
343
|v| vec ! [ Path :: Expr ( Box :: new( v) ) ] ,
333
- ) ( input)
344
+ )
345
+ . parse ( input)
334
346
}
335
347
336
348
fn paths ( input : & [ u8 ] ) -> IResult < & [ u8 ] , Vec < Path < ' _ > > > {
@@ -342,7 +354,8 @@ fn paths(input: &[u8]) -> IResult<&[u8], Vec<Path<'_>>> {
342
354
}
343
355
paths
344
356
} ,
345
- ) ( input)
357
+ )
358
+ . parse ( input)
346
359
}
347
360
348
361
fn expr_paths ( input : & [ u8 ] , is_root_expr : bool ) -> IResult < & [ u8 ] , Vec < Path < ' _ > > > {
@@ -362,7 +375,8 @@ fn expr_paths(input: &[u8], is_root_expr: bool) -> IResult<&[u8], Vec<Path<'_>>>
362
375
paths. insert ( 0 , pre_path) ;
363
376
paths
364
377
} ,
365
- ) ( input)
378
+ )
379
+ . parse ( input)
366
380
}
367
381
368
382
fn filter_expr ( input : & [ u8 ] ) -> IResult < & [ u8 ] , Expr < ' _ > > {
@@ -373,7 +387,8 @@ fn filter_expr(input: &[u8]) -> IResult<&[u8], Expr<'_>> {
373
387
char ( ')' ) ,
374
388
) ,
375
389
|v| v,
376
- ) ( input)
390
+ )
391
+ . parse ( input)
377
392
}
378
393
379
394
fn op ( input : & [ u8 ] ) -> IResult < & [ u8 ] , BinaryOperator > {
@@ -386,24 +401,21 @@ fn op(input: &[u8]) -> IResult<&[u8], BinaryOperator> {
386
401
value ( BinaryOperator :: Gte , tag ( ">=" ) ) ,
387
402
value ( BinaryOperator :: Gt , char ( '>' ) ) ,
388
403
value ( BinaryOperator :: StartsWith , tag ( "starts with" ) ) ,
389
- ) ) ( input)
404
+ value ( BinaryOperator :: Add , char ( '+' ) ) ,
405
+ value ( BinaryOperator :: Subtract , char ( '-' ) ) ,
406
+ value ( BinaryOperator :: Multiply , char ( '*' ) ) ,
407
+ value ( BinaryOperator :: Divide , char ( '/' ) ) ,
408
+ value ( BinaryOperator :: Modulo , char ( '%' ) ) ,
409
+ ) )
410
+ . parse ( input)
390
411
}
391
412
392
- fn unary_arith_op ( input : & [ u8 ] ) -> IResult < & [ u8 ] , UnaryArithmeticOperator > {
413
+ fn unary_arith_op ( input : & [ u8 ] ) -> IResult < & [ u8 ] , UnaryOperator > {
393
414
alt ( (
394
- value ( UnaryArithmeticOperator :: Add , char ( '+' ) ) ,
395
- value ( UnaryArithmeticOperator :: Subtract , char ( '-' ) ) ,
396
- ) ) ( input)
397
- }
398
-
399
- fn binary_arith_op ( input : & [ u8 ] ) -> IResult < & [ u8 ] , BinaryArithmeticOperator > {
400
- alt ( (
401
- value ( BinaryArithmeticOperator :: Add , char ( '+' ) ) ,
402
- value ( BinaryArithmeticOperator :: Subtract , char ( '-' ) ) ,
403
- value ( BinaryArithmeticOperator :: Multiply , char ( '*' ) ) ,
404
- value ( BinaryArithmeticOperator :: Divide , char ( '/' ) ) ,
405
- value ( BinaryArithmeticOperator :: Modulo , char ( '%' ) ) ,
406
- ) ) ( input)
415
+ value ( UnaryOperator :: Add , char ( '+' ) ) ,
416
+ value ( UnaryOperator :: Subtract , char ( '-' ) ) ,
417
+ ) )
418
+ . parse ( input)
407
419
}
408
420
409
421
fn path_value ( input : & [ u8 ] ) -> IResult < & [ u8 ] , PathValue < ' _ > > {
@@ -415,51 +427,39 @@ fn path_value(input: &[u8]) -> IResult<&[u8], PathValue<'_>> {
415
427
map ( i64, |v| PathValue :: Number ( Number :: Int64 ( v) ) ) ,
416
428
map ( double, |v| PathValue :: Number ( Number :: Float64 ( v) ) ) ,
417
429
map ( string, PathValue :: String ) ,
418
- ) ) ( input)
430
+ ) )
431
+ . parse ( input)
419
432
}
420
433
421
434
fn inner_expr ( input : & [ u8 ] , is_root_expr : bool ) -> IResult < & [ u8 ] , Expr < ' _ > > {
422
435
alt ( (
423
436
map ( |i| expr_paths ( i, is_root_expr) , Expr :: Paths ) ,
424
437
map ( path_value, |v| Expr :: Value ( Box :: new ( v) ) ) ,
425
- ) ) ( input)
438
+ ) )
439
+ . parse ( input)
426
440
}
427
441
428
442
fn expr_atom ( input : & [ u8 ] , is_root_expr : bool ) -> IResult < & [ u8 ] , Expr < ' _ > > {
429
443
alt ( (
430
444
map (
431
- tuple ( (
432
- delimited ( multispace0, |i| inner_expr ( i, is_root_expr) , multispace0) ,
433
- binary_arith_op,
434
- delimited ( multispace0, |i| inner_expr ( i, is_root_expr) , multispace0) ,
435
- ) ) ,
436
- |( left, op, right) | {
437
- Expr :: ArithmeticFunc ( ArithmeticFunc :: Binary {
438
- op,
439
- left : Box :: new ( left) ,
440
- right : Box :: new ( right) ,
441
- } )
442
- } ,
443
- ) ,
444
- map (
445
- tuple ( (
445
+ pair (
446
446
unary_arith_op,
447
447
delimited ( multispace0, |i| inner_expr ( i, is_root_expr) , multispace0) ,
448
- ) ) ,
449
- |( op, operand) | {
450
- Expr :: ArithmeticFunc ( ArithmeticFunc :: Unary {
451
- op,
452
- operand : Box :: new ( operand) ,
453
- } )
448
+ ) ,
449
+ |( op, operand) | Expr :: UnaryOp {
450
+ op,
451
+ operand : Box :: new ( operand) ,
454
452
} ,
455
453
) ,
456
454
map (
457
- tuple ( (
458
- delimited ( multispace0, |i| inner_expr ( i, is_root_expr) , multispace0) ,
459
- op,
455
+ pair (
456
+ pair (
457
+ delimited ( multispace0, |i| inner_expr ( i, is_root_expr) , multispace0) ,
458
+ op,
459
+ ) ,
460
460
delimited ( multispace0, |i| inner_expr ( i, is_root_expr) , multispace0) ,
461
- ) ) ,
462
- |( left, op, right) | Expr :: BinaryOp {
461
+ ) ,
462
+ |( ( left, op) , right) | Expr :: BinaryOp {
463
463
op,
464
464
left : Box :: new ( left) ,
465
465
right : Box :: new ( right) ,
@@ -474,7 +474,8 @@ fn expr_atom(input: &[u8], is_root_expr: bool) -> IResult<&[u8], Expr<'_>> {
474
474
|expr| expr,
475
475
) ,
476
476
map ( exists_func, Expr :: ExistsFunc ) ,
477
- ) ) ( input)
477
+ ) )
478
+ . parse ( input)
478
479
}
479
480
480
481
fn exists_func ( input : & [ u8 ] ) -> IResult < & [ u8 ] , Vec < Path < ' _ > > > {
@@ -488,7 +489,8 @@ fn exists_func(input: &[u8]) -> IResult<&[u8], Vec<Path<'_>>> {
488
489
preceded ( multispace0, char ( ')' ) ) ,
489
490
) ,
490
491
) ,
491
- ) ( input)
492
+ )
493
+ . parse ( input)
492
494
}
493
495
494
496
fn exists_paths ( input : & [ u8 ] ) -> IResult < & [ u8 ] , Vec < Path < ' _ > > > {
@@ -504,7 +506,8 @@ fn exists_paths(input: &[u8]) -> IResult<&[u8], Vec<Path<'_>>> {
504
506
paths. insert ( 0 , pre) ;
505
507
paths
506
508
} ,
507
- ) ( input)
509
+ )
510
+ . parse ( input)
508
511
}
509
512
510
513
fn expr_and ( input : & [ u8 ] , is_root_expr : bool ) -> IResult < & [ u8 ] , Expr < ' _ > > {
@@ -523,7 +526,8 @@ fn expr_and(input: &[u8], is_root_expr: bool) -> IResult<&[u8], Expr<'_>> {
523
526
}
524
527
expr
525
528
} ,
526
- ) ( input)
529
+ )
530
+ . parse ( input)
527
531
}
528
532
529
533
fn expr_or ( input : & [ u8 ] , is_root_expr : bool ) -> IResult < & [ u8 ] , Expr < ' _ > > {
@@ -542,5 +546,6 @@ fn expr_or(input: &[u8], is_root_expr: bool) -> IResult<&[u8], Expr<'_>> {
542
546
}
543
547
expr
544
548
} ,
545
- ) ( input)
549
+ )
550
+ . parse ( input)
546
551
}
0 commit comments