allow trailing semicolon

This commit is contained in:
Robin Appelman 2021-02-15 15:38:39 +01:00
commit 688f4fb6f4
4 changed files with 26 additions and 17 deletions

View file

@ -27,6 +27,8 @@ pub enum Token {
Float,
#[regex("-?(0|[1-9][0-9]*(_[0-9]+)*|0[xX][0-9a-fA-F]+(_[0-9a-fA-F]+)*|0[0-7]+(_[0-7]+)*|0[bB][01]+(_[01]+)*)")]
Integer,
#[token(";")]
SemiColon,
#[error]
#[regex(r"[ \t\n\f]+", logos::skip)]
Error,

View file

@ -52,10 +52,13 @@ where
{
let mut deserializer = Deserializer::from_str(s);
let t = T::deserialize(&mut deserializer)?;
if deserializer.next_token().is_none() {
Ok(t)
} else {
Err(RawParseError::TrailingCharacters.into())
match deserializer.next_token() {
None
| Some(SpannedToken {
token: Token::SemiColon,
..
}) => Ok(t),
Some(_) => Err(RawParseError::TrailingCharacters.into()),
}
}