diff --git a/src/compilation_error.rs b/src/compilation_error.rs index fc682e5d..b874ab06 100644 --- a/src/compilation_error.rs +++ b/src/compilation_error.rs @@ -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")?; } diff --git a/src/lexer.rs b/src/lexer.rs index 769d1c20..9e726f4c 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -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",