Skip to content

Commit d5b6578

Browse files
authored
chore: Bump nom 8.0.0 (#84)
* chore: bump nom 8.0.0 * fix * fix
1 parent c1bd9dc commit d5b6578

File tree

6 files changed

+418
-412
lines changed

6 files changed

+418
-412
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ rust-version = "1.80"
2929
byteorder = "1.5.0"
3030
fast-float2 = "0.2.3"
3131
itoa = "1.0"
32-
nom = "7.1.3"
32+
nom = "8.0.0"
3333
num-traits = "0.2.19"
3434
ordered-float = { version = "5.0", default-features = false }
3535
rand = { version = "0.9.0", features = ["small_rng"] }

src/jsonpath/parser.rs

Lines changed: 77 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ use nom::sequence::pair;
3838
use nom::sequence::preceded;
3939
use nom::sequence::separated_pair;
4040
use nom::sequence::terminated;
41-
use nom::sequence::tuple;
4241
use nom::IResult;
42+
use nom::Parser;
4343

4444
use crate::constants::UNICODE_LEN;
4545
use crate::error::Error;
@@ -65,7 +65,8 @@ fn json_path(input: &[u8]) -> IResult<&[u8], JsonPath<'_>> {
6565
map(
6666
delimited(multispace0, expr_or_paths, multispace0),
6767
|paths| JsonPath { paths },
68-
)(input)
68+
)
69+
.parse(input)
6970
}
7071

7172
fn check_escaped(input: &[u8], i: &mut usize) -> bool {
@@ -177,11 +178,12 @@ fn bracket_wildcard(input: &[u8]) -> IResult<&[u8], ()> {
177178
delimited(multispace0, char('*'), multispace0),
178179
char(']'),
179180
),
180-
)(input)
181+
)
182+
.parse(input)
181183
}
182184

183185
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)
185187
}
186188

187189
fn recursive_level(input: &[u8]) -> IResult<&[u8], RecursiveLevel> {
@@ -202,7 +204,8 @@ fn recursive_level(input: &[u8]) -> IResult<&[u8], RecursiveLevel> {
202204
end: None,
203205
},
204206
),
205-
))(input)
207+
))
208+
.parse(input)
206209
}
207210

208211
fn recursive_level_range(input: &[u8]) -> IResult<&[u8], RecursiveLevel> {
@@ -229,44 +232,47 @@ fn recursive_level_range(input: &[u8]) -> IResult<&[u8], RecursiveLevel> {
229232
end: Some(RecursiveLevelEnd::Last),
230233
},
231234
),
232-
))(input)
235+
))
236+
.parse(input)
233237
}
234238

235239
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)
237241
}
238242

239243
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)
241245
}
242246

243247
fn object_field(input: &[u8]) -> IResult<&[u8], Cow<'_, str>> {
244248
delimited(
245249
terminated(char('['), multispace0),
246250
string,
247251
preceded(multispace0, char(']')),
248-
)(input)
252+
)
253+
.parse(input)
249254
}
250255

251256
fn index(input: &[u8]) -> IResult<&[u8], Index> {
252257
alt((
253258
map(i32, Index::Index),
254259
map(
255260
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),
258263
),
259264
|v| Index::LastIndex(v.saturating_neg()),
260265
),
261266
map(
262267
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),
265270
),
266271
Index::LastIndex,
267272
),
268273
map(tag_no_case("last"), |_| Index::LastIndex(0)),
269-
))(input)
274+
))
275+
.parse(input)
270276
}
271277

272278
fn array_index(input: &[u8]) -> IResult<&[u8], ArrayIndex> {
@@ -280,15 +286,17 @@ fn array_index(input: &[u8]) -> IResult<&[u8], ArrayIndex> {
280286
|(s, e)| ArrayIndex::Slice((s, e)),
281287
),
282288
map(index, ArrayIndex::Index),
283-
))(input)
289+
))
290+
.parse(input)
284291
}
285292

286293
fn array_indices(input: &[u8]) -> IResult<&[u8], Vec<ArrayIndex>> {
287294
delimited(
288295
char('['),
289296
separated_list1(char(','), delimited(multispace0, array_index, multispace0)),
290297
char(']'),
291-
)(input)
298+
)
299+
.parse(input)
292300
}
293301

294302
fn inner_path(input: &[u8]) -> IResult<&[u8], Path<'_>> {
@@ -300,7 +308,8 @@ fn inner_path(input: &[u8]) -> IResult<&[u8], Path<'_>> {
300308
map(dot_field, Path::DotField),
301309
map(array_indices, Path::ArrayIndices),
302310
map(object_field, Path::ObjectField),
303-
))(input)
311+
))
312+
.parse(input)
304313
}
305314

306315
// 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<'_>> {
310319
map(delimited(multispace0, raw_string, multispace0), |v| {
311320
Path::DotField(v)
312321
}),
313-
))(input)
322+
))
323+
.parse(input)
314324
}
315325

316326
fn path(input: &[u8]) -> IResult<&[u8], Path<'_>> {
@@ -319,18 +329,20 @@ fn path(input: &[u8]) -> IResult<&[u8], Path<'_>> {
319329
map(delimited(multispace0, filter_expr, multispace0), |v| {
320330
Path::FilterExpr(Box::new(v))
321331
}),
322-
))(input)
332+
))
333+
.parse(input)
323334
}
324335

325336
fn expr_or_paths(input: &[u8]) -> IResult<&[u8], Vec<Path<'_>>> {
326-
alt((root_expr, paths))(input)
337+
alt((root_expr, paths)).parse(input)
327338
}
328339

329340
fn root_expr(input: &[u8]) -> IResult<&[u8], Vec<Path<'_>>> {
330341
map(
331342
delimited(multispace0, |i| expr_or(i, true), multispace0),
332343
|v| vec![Path::Expr(Box::new(v))],
333-
)(input)
344+
)
345+
.parse(input)
334346
}
335347

336348
fn paths(input: &[u8]) -> IResult<&[u8], Vec<Path<'_>>> {
@@ -342,7 +354,8 @@ fn paths(input: &[u8]) -> IResult<&[u8], Vec<Path<'_>>> {
342354
}
343355
paths
344356
},
345-
)(input)
357+
)
358+
.parse(input)
346359
}
347360

348361
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<'_>>>
362375
paths.insert(0, pre_path);
363376
paths
364377
},
365-
)(input)
378+
)
379+
.parse(input)
366380
}
367381

368382
fn filter_expr(input: &[u8]) -> IResult<&[u8], Expr<'_>> {
@@ -373,7 +387,8 @@ fn filter_expr(input: &[u8]) -> IResult<&[u8], Expr<'_>> {
373387
char(')'),
374388
),
375389
|v| v,
376-
)(input)
390+
)
391+
.parse(input)
377392
}
378393

379394
fn op(input: &[u8]) -> IResult<&[u8], BinaryOperator> {
@@ -386,24 +401,21 @@ fn op(input: &[u8]) -> IResult<&[u8], BinaryOperator> {
386401
value(BinaryOperator::Gte, tag(">=")),
387402
value(BinaryOperator::Gt, char('>')),
388403
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)
390411
}
391412

392-
fn unary_arith_op(input: &[u8]) -> IResult<&[u8], UnaryArithmeticOperator> {
413+
fn unary_arith_op(input: &[u8]) -> IResult<&[u8], UnaryOperator> {
393414
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)
407419
}
408420

409421
fn path_value(input: &[u8]) -> IResult<&[u8], PathValue<'_>> {
@@ -415,51 +427,39 @@ fn path_value(input: &[u8]) -> IResult<&[u8], PathValue<'_>> {
415427
map(i64, |v| PathValue::Number(Number::Int64(v))),
416428
map(double, |v| PathValue::Number(Number::Float64(v))),
417429
map(string, PathValue::String),
418-
))(input)
430+
))
431+
.parse(input)
419432
}
420433

421434
fn inner_expr(input: &[u8], is_root_expr: bool) -> IResult<&[u8], Expr<'_>> {
422435
alt((
423436
map(|i| expr_paths(i, is_root_expr), Expr::Paths),
424437
map(path_value, |v| Expr::Value(Box::new(v))),
425-
))(input)
438+
))
439+
.parse(input)
426440
}
427441

428442
fn expr_atom(input: &[u8], is_root_expr: bool) -> IResult<&[u8], Expr<'_>> {
429443
alt((
430444
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(
446446
unary_arith_op,
447447
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),
454452
},
455453
),
456454
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+
),
460460
delimited(multispace0, |i| inner_expr(i, is_root_expr), multispace0),
461-
)),
462-
|(left, op, right)| Expr::BinaryOp {
461+
),
462+
|((left, op), right)| Expr::BinaryOp {
463463
op,
464464
left: Box::new(left),
465465
right: Box::new(right),
@@ -474,7 +474,8 @@ fn expr_atom(input: &[u8], is_root_expr: bool) -> IResult<&[u8], Expr<'_>> {
474474
|expr| expr,
475475
),
476476
map(exists_func, Expr::ExistsFunc),
477-
))(input)
477+
))
478+
.parse(input)
478479
}
479480

480481
fn exists_func(input: &[u8]) -> IResult<&[u8], Vec<Path<'_>>> {
@@ -488,7 +489,8 @@ fn exists_func(input: &[u8]) -> IResult<&[u8], Vec<Path<'_>>> {
488489
preceded(multispace0, char(')')),
489490
),
490491
),
491-
)(input)
492+
)
493+
.parse(input)
492494
}
493495

494496
fn exists_paths(input: &[u8]) -> IResult<&[u8], Vec<Path<'_>>> {
@@ -504,7 +506,8 @@ fn exists_paths(input: &[u8]) -> IResult<&[u8], Vec<Path<'_>>> {
504506
paths.insert(0, pre);
505507
paths
506508
},
507-
)(input)
509+
)
510+
.parse(input)
508511
}
509512

510513
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<'_>> {
523526
}
524527
expr
525528
},
526-
)(input)
529+
)
530+
.parse(input)
527531
}
528532

529533
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<'_>> {
542546
}
543547
expr
544548
},
545-
)(input)
549+
)
550+
.parse(input)
546551
}

0 commit comments

Comments
 (0)