Make EOL after interpolation a proper error (#279)
This commit is contained in:
parent
661342bb11
commit
9a56e27e18
@ -37,6 +37,7 @@ pub enum CompilationErrorKind<'a> {
|
|||||||
UnknownDependency{recipe: &'a str, unknown: &'a str},
|
UnknownDependency{recipe: &'a str, unknown: &'a str},
|
||||||
UnknownFunction{function: &'a str},
|
UnknownFunction{function: &'a str},
|
||||||
UnknownStartOfToken,
|
UnknownStartOfToken,
|
||||||
|
UnterminatedInterpolation,
|
||||||
UnterminatedString,
|
UnterminatedString,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,6 +131,9 @@ impl<'a> Display for CompilationError<'a> {
|
|||||||
UnknownStartOfToken => {
|
UnknownStartOfToken => {
|
||||||
writeln!(f, "Unknown start of token:")?;
|
writeln!(f, "Unknown start of token:")?;
|
||||||
}
|
}
|
||||||
|
UnterminatedInterpolation => {
|
||||||
|
writeln!(f, "Unterminated interpolation")?;
|
||||||
|
}
|
||||||
UnterminatedString => {
|
UnterminatedString => {
|
||||||
writeln!(f, "Unterminated string")?;
|
writeln!(f, "Unterminated string")?;
|
||||||
}
|
}
|
||||||
|
15
src/lexer.rs
15
src/lexer.rs
@ -200,9 +200,7 @@ impl<'a> Lexer<'a> {
|
|||||||
(captures.get(1).unwrap().as_str(), captures.get(2).unwrap().as_str(), Name)
|
(captures.get(1).unwrap().as_str(), captures.get(2).unwrap().as_str(), Name)
|
||||||
} else if let Some(captures) = EOL.captures(self.rest) {
|
} else if let Some(captures) = EOL.captures(self.rest) {
|
||||||
if self.state.last().unwrap() == &State::Interpolation {
|
if self.state.last().unwrap() == &State::Interpolation {
|
||||||
return Err(self.error(Internal {
|
return Err(self.error(UnterminatedInterpolation));
|
||||||
message: "hit EOL while still in interpolation state".to_string()
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
(captures.get(1).unwrap().as_str(), captures.get(2).unwrap().as_str(), Eol)
|
(captures.get(1).unwrap().as_str(), captures.get(2).unwrap().as_str(), Eol)
|
||||||
} else if let Some(captures) = BACKTICK.captures(self.rest) {
|
} else if let Some(captures) = BACKTICK.captures(self.rest) {
|
||||||
@ -602,6 +600,17 @@ c: b
|
|||||||
kind: UnterminatedString,
|
kind: UnterminatedString,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
error_test! {
|
||||||
|
name: unterminated_interpolation,
|
||||||
|
input: "foo:\n echo {{
|
||||||
|
",
|
||||||
|
index: 13,
|
||||||
|
line: 1,
|
||||||
|
column: 8,
|
||||||
|
width: None,
|
||||||
|
kind: UnterminatedInterpolation,
|
||||||
|
}
|
||||||
|
|
||||||
error_test! {
|
error_test! {
|
||||||
name: mixed_leading_whitespace,
|
name: mixed_leading_whitespace,
|
||||||
input: "a:\n\t echo hello",
|
input: "a:\n\t echo hello",
|
||||||
|
Loading…
Reference in New Issue
Block a user