Make EOL after interpolation a proper error (#279)

This commit is contained in:
Casey Rodarmor 2017-12-02 21:49:31 +01:00 committed by GitHub
parent 661342bb11
commit 9a56e27e18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View File

@ -37,6 +37,7 @@ pub enum CompilationErrorKind<'a> {
UnknownDependency{recipe: &'a str, unknown: &'a str},
UnknownFunction{function: &'a str},
UnknownStartOfToken,
UnterminatedInterpolation,
UnterminatedString,
}
@ -130,6 +131,9 @@ impl<'a> Display for CompilationError<'a> {
UnknownStartOfToken => {
writeln!(f, "Unknown start of token:")?;
}
UnterminatedInterpolation => {
writeln!(f, "Unterminated interpolation")?;
}
UnterminatedString => {
writeln!(f, "Unterminated string")?;
}

View File

@ -200,9 +200,7 @@ impl<'a> Lexer<'a> {
(captures.get(1).unwrap().as_str(), captures.get(2).unwrap().as_str(), Name)
} else if let Some(captures) = EOL.captures(self.rest) {
if self.state.last().unwrap() == &State::Interpolation {
return Err(self.error(Internal {
message: "hit EOL while still in interpolation state".to_string()
}));
return Err(self.error(UnterminatedInterpolation));
}
(captures.get(1).unwrap().as_str(), captures.get(2).unwrap().as_str(), Eol)
} else if let Some(captures) = BACKTICK.captures(self.rest) {
@ -602,6 +600,17 @@ c: b
kind: UnterminatedString,
}
error_test! {
name: unterminated_interpolation,
input: "foo:\n echo {{
",
index: 13,
line: 1,
column: 8,
width: None,
kind: UnterminatedInterpolation,
}
error_test! {
name: mixed_leading_whitespace,
input: "a:\n\t echo hello",