Fix tab-indented lines in shebang recipes

Fixed a precedence bug in the recipe parser where tab-indented
lines in a shebang recipe would trigger an ExtraLeadingWhitespace
error.
This commit is contained in:
Casey Rodarmor 2016-11-02 22:01:38 -07:00
parent ac996f8940
commit 9f2568c461
2 changed files with 22 additions and 2 deletions

View File

@ -988,7 +988,7 @@ impl<'a> Display for RunError<'a> {
match *self {
RunError::UnknownRecipes{ref recipes} => {
if recipes.len() == 1 {
try!(write!(f, "Justfile does not contain recipe: {}", recipes[0]));
try!(write!(f, "Justfile does not contain recipe `{}`", recipes[0]));
} else {
try!(write!(f, "Justfile does not contain recipes: {}", recipes.join(" ")));
};
@ -1528,7 +1528,8 @@ impl<'a> Parser<'a> {
if token.lexeme.starts_with("#!") {
shebang = true;
}
} else if !shebang && token.lexeme.starts_with(' ') || token.lexeme.starts_with('\t') {
} else if !shebang && (token.lexeme.starts_with(' ') ||
token.lexeme.starts_with('\t')) {
return Err(token.error(ErrorKind::ExtraLeadingWhitespace));
}
}

View File

@ -302,6 +302,25 @@ y:
z:");
}
#[test]
fn parse_shebang() {
parse_summary("
practicum = 'hello'
install:
\t#!/bin/sh
\tif [[ -f {{practicum}} ]]; then
\t\treturn
\tfi
", "practicum = \"hello\"
install:
#!/bin/sh
if [[ -f {{practicum}} ]]; then
\treturn
fi"
);
}
#[test]
fn parse_assignments() {
parse_summary(