You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Try to parse an overflowing integer (also works with any input that makes from_str fail).
nitro>>> 11111111111111111111111
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ParseIntError { kind: Overflow }'...
Fix
The action code must be able to return a ParseError when i64::from_str(<>) fails.
This is possible using LALRPOP; however, it is impossible to return a ParseError::User with a useful error message AND use the match keyword. This is because "match and extern definitions are mutually exclusive," as reported by LALRPOP.
With match, but without extern and a custom ParseError::User type:
match {...}
pub Int: i64 = {
INT =>? match i64::from_str(<>) {
Ok(i) => Ok(i),
// Don't panic on overflow or other parse error
Err(e) => Err(ParseError::User { error: () })
}
};
With extern, but without match:
extern {
Error = useful ParseError::User type
}
pub Int: i64 = {
INT =>? match i64::from_str(<>) {
Ok(i) => Ok(i),
// Don't panic on overflow or other parse error
Err(e) => Err(ParseError::User { error: /*useful info (your integer's too big!)*/ })
}
};
Replicate
Try to parse an overflowing integer (also works with any input that makes
from_str
fail).Fix
The action code must be able to return a ParseError when
i64::from_str(<>)
fails.This is possible using LALRPOP; however, it is impossible to return a
ParseError::User
with a useful error message AND use thematch
keyword. This is because "match and extern definitions are mutually exclusive," as reported by LALRPOP.With
match
, but withoutextern
and a customParseError::User
type:With
extern
, but withoutmatch
:See how LALRPOP parses itself:
https://github.com/nikomatsakis/lalrpop/blob/f934229ed76f123a1d4c190edd4d05cf5cc4ff2d/lalrpop/src/p
Simple example of using
extern { Error = /*custom parse error type*/ }
https://github.com/nikomatsakis/lalrpop/blob/master/lalrpop-test/src/error.lalrpop
The text was updated successfully, but these errors were encountered: