From 9a56e27e183efdb56bfc9d57ab5da1890eb3e6fe Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Sat, 2 Dec 2017 21:49:31 +0100 Subject: [PATCH] Make EOL after interpolation a proper error (#279) --- src/compilation_error.rs | 4 ++++ src/lexer.rs | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/compilation_error.rs b/src/compilation_error.rs index fc682e5..b874ab0 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 769d1c2..9e726f4 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",