Skip to content

Commit

Permalink
fix(parser): Float literals with unexpected char
Browse files Browse the repository at this point in the history
  • Loading branch information
zummenix committed Nov 19, 2017
1 parent 289eb61 commit ea537e1
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion parser/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,14 @@ impl<'input> Tokenizer<'input> {
Some((_, '.')) => {
self.bump(); // Skip '.'
let (end, float) = self.take_while(start, is_digit);
(start, end, Token::FloatLiteral(float.parse().unwrap()))
match self.lookahead {
Some((_, ch)) if is_ident_start(ch) => {
return self.error(end, UnexpectedChar(ch))
}
_ => {
(start, end, Token::FloatLiteral(float.parse().unwrap()))
}
}
}
Some((end, 'x')) => {
self.bump(); // Skip 'x'
Expand Down Expand Up @@ -926,6 +933,14 @@ mod test {
);
}

#[test]
fn float_literals_unexpected_char() {
assert_eq!(
tokenizer(r#"12.3a"#).last(),
Some(error(loc(4), UnexpectedChar('a')))
);
}

#[test]
fn line_comments() {
test(
Expand Down

0 comments on commit ea537e1

Please sign in to comment.