issue an imcomplete reduction error if stream ends with tokens remaining to be parsed
@@ -199,15 +199,23 @@ fn read_tokens<R: Read>(lexer: &mut Lexer<R>) -> Result<Vec<Token>, ParserError>
let mut tokens = vec![];
loop {
- let token = lexer.next_token()?;
+ match lexer.next_token() {
+ Ok(token) => {
let at_end = token.is_end();
-
tokens.push(token);
if at_end {
break;
}
}
+ Err(ParserError::UnexpectedEOF) if !tokens.is_empty() => {
+ return Err(ParserError::IncompleteReduction(lexer.line_num, lexer.col_num));
+ }
+ Err(e) => {
+ return Err(e);
+ }
+ }
+ }
tokens.reverse();
