Skip to content

Commit

Permalink
Fix parsing a line comment then EOF
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielMajeri committed Jun 9, 2020
1 parent c9ef6d5 commit 2aad8c9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl<'a, R: Read> Lexer<'a, R> {
fn single_line_comment(&mut self) -> Result<(), ParserError>
{
loop {
if new_line_char!(self.skip_char()?) {
if self.eof()? || new_line_char!(self.skip_char()?) {
break;
}
}
Expand Down Expand Up @@ -872,6 +872,7 @@ impl<'a, R: Read> Lexer<'a, R> {

self.name_token(c)
},
Err(ParserError::UnexpectedEOF) => Ok(Token::End),
Err(e) => Err(e)
}
}
Expand Down
14 changes: 14 additions & 0 deletions tests/parse_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,17 @@ fn char_with_hexseq() -> Result<(), ParserError> {
fn char_with_hexseq_invalid() {
assert!(read_all_tokens(r"'\x\' ").is_err());
}

#[test]
fn empty() -> Result<(), ParserError> {
let tokens = read_all_tokens("")?;
assert!(tokens.is_empty());
Ok(())
}

#[test]
fn comment_then_eof() -> Result<(), ParserError> {
let tokens = read_all_tokens("% only a comment")?;
assert_eq!(tokens, [Token::End]);
Ok(())
}

0 comments on commit 2aad8c9

Please sign in to comment.