Skip to content

Commit 7747351

Browse files
authored
Merge pull request #7227 from cakebaker/bump_nom
Bump `nom` and adapt `tr` to API changes
2 parents bcc406a + 5efd51b commit 7747351

File tree

4 files changed

+59
-36
lines changed

4 files changed

+59
-36
lines changed

Cargo.lock

Lines changed: 17 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ lscolors = { version = "0.20.0", default-features = false, features = [
308308
memchr = "2.7.2"
309309
memmap2 = "0.9.4"
310310
nix = { version = "0.29", default-features = false }
311-
nom = "7.1.3"
311+
nom = "8.0.0"
312312
notify = { version = "=8.0.0", features = ["macos_kqueue"] }
313313
num-bigint = "0.4.4"
314314
num-prime = "0.4.4"

deny.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ skip = [
9292
{ name = "itertools", version = "0.13.0" },
9393
# indexmap
9494
{ name = "hashbrown", version = "0.14.5" },
95+
# parse_datetime, cexpr (via bindgen)
96+
{ name = "nom", version = "7.1.3" },
9597
]
9698
# spell-checker: enable
9799

src/uu/tr/src/operation.rs

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use nom::{
1313
combinator::{map, map_opt, peek, recognize, value},
1414
multi::{many0, many_m_n},
1515
sequence::{delimited, preceded, separated_pair},
16-
IResult,
16+
IResult, Parser,
1717
};
1818
use std::{
1919
char,
@@ -298,7 +298,8 @@ impl Sequence {
298298
map(Self::parse_backslash_or_char_with_warning, |s| {
299299
Ok(Self::Char(s))
300300
}),
301-
)))(input)
301+
)))
302+
.parse(input)
302303
.map(|(_, r)| r)
303304
.unwrap()
304305
.into_iter()
@@ -308,7 +309,7 @@ impl Sequence {
308309
fn parse_octal(input: &[u8]) -> IResult<&[u8], u8> {
309310
// For `parse_char_range`, `parse_char_star`, `parse_char_repeat`, `parse_char_equal`.
310311
// Because in these patterns, there's no ambiguous cases.
311-
preceded(tag("\\"), Self::parse_octal_up_to_three_digits)(input)
312+
preceded(tag("\\"), Self::parse_octal_up_to_three_digits).parse(input)
312313
}
313314

314315
fn parse_octal_with_warning(input: &[u8]) -> IResult<&[u8], u8> {
@@ -321,7 +322,8 @@ impl Sequence {
321322
// See test `test_multibyte_octal_sequence`
322323
Self::parse_octal_two_digits,
323324
)),
324-
)(input)
325+
)
326+
.parse(input)
325327
}
326328

327329
fn parse_octal_up_to_three_digits(input: &[u8]) -> IResult<&[u8], u8> {
@@ -331,7 +333,8 @@ impl Sequence {
331333
let str_to_parse = std::str::from_utf8(out).unwrap();
332334
u8::from_str_radix(str_to_parse, 8).ok()
333335
},
334-
)(input)
336+
)
337+
.parse(input)
335338
}
336339

337340
fn parse_octal_up_to_three_digits_with_warning(input: &[u8]) -> IResult<&[u8], u8> {
@@ -353,42 +356,46 @@ impl Sequence {
353356
}
354357
result
355358
},
356-
)(input)
359+
).parse(input)
357360
}
358361

359362
fn parse_octal_two_digits(input: &[u8]) -> IResult<&[u8], u8> {
360363
map_opt(
361364
recognize(many_m_n(2, 2, one_of("01234567"))),
362365
|out: &[u8]| u8::from_str_radix(std::str::from_utf8(out).unwrap(), 8).ok(),
363-
)(input)
366+
)
367+
.parse(input)
364368
}
365369

366370
fn parse_backslash(input: &[u8]) -> IResult<&[u8], u8> {
367-
preceded(tag("\\"), Self::single_char)(input).map(|(l, a)| {
368-
let c = match a {
369-
b'a' => unicode_table::BEL,
370-
b'b' => unicode_table::BS,
371-
b'f' => unicode_table::FF,
372-
b'n' => unicode_table::LF,
373-
b'r' => unicode_table::CR,
374-
b't' => unicode_table::HT,
375-
b'v' => unicode_table::VT,
376-
x => x,
377-
};
378-
(l, c)
379-
})
371+
preceded(tag("\\"), Self::single_char)
372+
.parse(input)
373+
.map(|(l, a)| {
374+
let c = match a {
375+
b'a' => unicode_table::BEL,
376+
b'b' => unicode_table::BS,
377+
b'f' => unicode_table::FF,
378+
b'n' => unicode_table::LF,
379+
b'r' => unicode_table::CR,
380+
b't' => unicode_table::HT,
381+
b'v' => unicode_table::VT,
382+
x => x,
383+
};
384+
(l, c)
385+
})
380386
}
381387

382388
fn parse_backslash_or_char(input: &[u8]) -> IResult<&[u8], u8> {
383-
alt((Self::parse_octal, Self::parse_backslash, Self::single_char))(input)
389+
alt((Self::parse_octal, Self::parse_backslash, Self::single_char)).parse(input)
384390
}
385391

386392
fn parse_backslash_or_char_with_warning(input: &[u8]) -> IResult<&[u8], u8> {
387393
alt((
388394
Self::parse_octal_with_warning,
389395
Self::parse_backslash,
390396
Self::single_char,
391-
))(input)
397+
))
398+
.parse(input)
392399
}
393400

394401
fn single_char(input: &[u8]) -> IResult<&[u8], u8> {
@@ -400,7 +407,8 @@ impl Sequence {
400407
Self::parse_backslash_or_char,
401408
tag("-"),
402409
Self::parse_backslash_or_char,
403-
)(input)
410+
)
411+
.parse(input)
404412
.map(|(l, (a, b))| {
405413
(l, {
406414
let (start, end) = (u32::from(a), u32::from(b));
@@ -417,7 +425,8 @@ impl Sequence {
417425
}
418426

419427
fn parse_char_star(input: &[u8]) -> IResult<&[u8], Result<Self, BadSequence>> {
420-
delimited(tag("["), Self::parse_backslash_or_char, tag("*]"))(input)
428+
delimited(tag("["), Self::parse_backslash_or_char, tag("*]"))
429+
.parse(input)
421430
.map(|(l, a)| (l, Ok(Self::CharStar(a))))
422431
}
423432

@@ -433,7 +442,8 @@ impl Sequence {
433442
take_till(|ue| matches!(ue, b']' | b'\\')),
434443
),
435444
tag("]"),
436-
)(input)
445+
)
446+
.parse(input)
437447
.map(|(l, (c, cnt_str))| {
438448
let s = String::from_utf8_lossy(cnt_str);
439449
let result = if cnt_str.starts_with(b"0") {
@@ -477,7 +487,8 @@ impl Sequence {
477487
value(Err(BadSequence::MissingCharClassName), tag("")),
478488
)),
479489
tag(":]"),
480-
)(input)
490+
)
491+
.parse(input)
481492
}
482493

483494
fn parse_char_equal(input: &[u8]) -> IResult<&[u8], Result<Self, BadSequence>> {
@@ -491,7 +502,8 @@ impl Sequence {
491502
map(Self::parse_backslash_or_char, |c| Ok(Self::Char(c))),
492503
)),
493504
tag("=]"),
494-
)(input)
505+
)
506+
.parse(input)
495507
}
496508
}
497509

0 commit comments

Comments
 (0)