Use PutBackN instead of PutBack in parser (#364)

The parser could be confused into calling `PutBack::put_back` twice in a row, and thus dropping tokens. This commit switches to `PutBackN`, which allows any number of put backs in a row.
This commit is contained in:
Casey Rodarmor 2018-10-13 18:39:26 +09:00 committed by GitHub
parent 8371adab24
commit bcfd47dcbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,7 +6,7 @@ use CompilationErrorKind::*;
pub struct Parser<'a> { pub struct Parser<'a> {
text: &'a str, text: &'a str,
tokens: itertools::PutBack<vec::IntoIter<Token<'a>>>, tokens: itertools::PutBackN<vec::IntoIter<Token<'a>>>,
recipes: Map<&'a str, Recipe<'a>>, recipes: Map<&'a str, Recipe<'a>>,
assignments: Map<&'a str, Expression<'a>>, assignments: Map<&'a str, Expression<'a>>,
assignment_tokens: Map<&'a str, Token<'a>>, assignment_tokens: Map<&'a str, Token<'a>>,
@ -22,7 +22,7 @@ impl<'a> Parser<'a> {
pub fn new(text: &'a str, tokens: Vec<Token<'a>>) -> Parser<'a> { pub fn new(text: &'a str, tokens: Vec<Token<'a>>) -> Parser<'a> {
Parser { Parser {
tokens: itertools::put_back(tokens), tokens: itertools::put_back_n(tokens),
recipes: empty(), recipes: empty(),
assignments: empty(), assignments: empty(),
assignment_tokens: empty(), assignment_tokens: empty(),
@ -849,6 +849,16 @@ a:
kind: UnexpectedToken{expected: vec![Name], found: Plus}, kind: UnexpectedToken{expected: vec![Name], found: Plus},
} }
compilation_error_test! {
name: bad_export,
input: "export a",
index: 8,
line: 0,
column: 8,
width: Some(0),
kind: UnexpectedToken{expected: vec![Name, Plus, Colon], found: Eof},
}
#[test] #[test]
fn readme_test() { fn readme_test() {
let mut justfiles = vec![]; let mut justfiles = vec![];