feat(argus): don't just panic on failed number parsing
This commit is contained in:
parent
141f7d3983
commit
a7431ce424
2 changed files with 17 additions and 3 deletions
|
|
@ -98,15 +98,27 @@ pub fn lexer<'src>() -> impl Parser<'src, &'src str, Output<'src>, Error<'src>>
|
||||||
// .then(frac.or_not())
|
// .then(frac.or_not())
|
||||||
// .then(exp.or_not())
|
// .then(exp.or_not())
|
||||||
.to_slice()
|
.to_slice()
|
||||||
.map(|s: &str| Token::Float(s.parse().unwrap()))
|
.try_map_with(|s: &str, e| {
|
||||||
|
s.parse()
|
||||||
|
.map(Token::Float)
|
||||||
|
.map_err(|err| Rich::custom(e.span(), format!("Unable to parse as 64-bit float: {}", err)))
|
||||||
|
})
|
||||||
.boxed();
|
.boxed();
|
||||||
|
|
||||||
let signed_int = one_of("+-")
|
let signed_int = one_of("+-")
|
||||||
// .or_not()
|
// .or_not()
|
||||||
.then(digits)
|
.then(digits)
|
||||||
.to_slice()
|
.to_slice()
|
||||||
.map(|s: &str| Token::Int(s.parse().unwrap()));
|
.try_map_with(|s: &str, e| {
|
||||||
let unsigned_int = digits.to_slice().map(|s: &str| Token::UInt(s.parse().unwrap()));
|
s.parse()
|
||||||
|
.map(Token::Int)
|
||||||
|
.map_err(|err| Rich::custom(e.span(), format!("Unable to parse as 64-bit signed int: {}", err)))
|
||||||
|
});
|
||||||
|
let unsigned_int = digits.to_slice().try_map_with(|s: &str, e| {
|
||||||
|
s.parse()
|
||||||
|
.map(Token::UInt)
|
||||||
|
.map_err(|err| Rich::custom(e.span(), format!("Unable to parse as 64-bit unsigned int: {}", err)))
|
||||||
|
});
|
||||||
|
|
||||||
let number = choice((floating_number, signed_int, unsigned_int));
|
let number = choice((floating_number, signed_int, unsigned_int));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ def test_correct_expr(data: st.DataObject) -> None:
|
||||||
try:
|
try:
|
||||||
_ = argus.parse_expr(spec)
|
_ = argus.parse_expr(spec)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
|
if "Unable to parse as 64-bit" in str(e):
|
||||||
|
return
|
||||||
logging.critical(f"unable to parse expr: {spec}")
|
logging.critical(f"unable to parse expr: {spec}")
|
||||||
raise e
|
raise e
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue