Skip to content

Commit

Permalink
Allow outer shebangs so justfiles can be used as scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Apr 8, 2019
1 parent cee9ac2 commit 023b051
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 40 deletions.
4 changes: 4 additions & 0 deletions justfile
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#!/usr/bin/env just --justfile
# ^ This isn't required, but allows a justfile to be executed
# like a script, with `./justfile test`, for example.

bt='0'

export RUST_BACKTRACE=bt
Expand Down
4 changes: 0 additions & 4 deletions src/compilation_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ pub enum CompilationErrorKind<'a> {
MixedLeadingWhitespace {
whitespace: &'a str,
},
OuterShebang,
ParameterFollowsVariadicParameter {
parameter: &'a str,
},
Expand Down Expand Up @@ -229,9 +228,6 @@ impl<'a> Display for CompilationError<'a> {
show_whitespace(found)
)?;
}
OuterShebang => {
writeln!(f, "`#!` is reserved syntax outside of recipes")?;
}
UnknownDependency { recipe, unknown } => {
writeln!(
f,
Expand Down
16 changes: 2 additions & 14 deletions src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl<'a> Lexer<'a> {
static ref BACKTICK: Regex = token(r"`[^`\n\r]*`");
static ref COLON: Regex = token(r":");
static ref COMMA: Regex = token(r",");
static ref COMMENT: Regex = token(r"#([^!\n\r][^\n\r]*)?\r?$");
static ref COMMENT: Regex = token(r"#([^\n\r][^\n\r]*)?\r?$");
static ref EOF: Regex = token(r"\z");
static ref EOL: Regex = token(r"\n|\r\n");
static ref EQUALS: Regex = token(r"=");
Expand Down Expand Up @@ -322,8 +322,6 @@ impl<'a> Lexer<'a> {
return Err(self.error(UnterminatedString));
}
(prefix, &self.rest[start..content_end + 1], StringToken)
} else if self.rest.starts_with("#!") {
return Err(self.error(OuterShebang));
} else {
return Err(self.error(UnknownStartOfToken));
};
Expand All @@ -340,7 +338,7 @@ impl<'a> Lexer<'a> {
_ => {
return Err(last.error(Internal {
message: format!("zero length token: {:?}", last),
}))
}));
}
}
}
Expand Down Expand Up @@ -647,16 +645,6 @@ c: b
kind: InconsistentLeadingWhitespace{expected: "\t\t", found: "\t "},
}

error_test! {
name: tokenize_outer_shebang,
input: "#!/usr/bin/env bash",
index: 0,
line: 0,
column: 0,
width: None,
kind: OuterShebang,
}

error_test! {
name: tokenize_unknown,
input: "~",
Expand Down
22 changes: 0 additions & 22 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,28 +578,6 @@ wut:
status: EXIT_SUCCESS,
}

integration_test! {
name: outer_shebang,
justfile: r#"#!/lol/wut
export FOO = "a"
baz = "c"
export BAR = "b"
export ABC = FOO + BAR + baz
wut:
#!/bin/sh
echo $FOO $BAR $ABC
"#,
args: (),
stdout: "",
stderr: "error: `#!` is reserved syntax outside of recipes
|
1 | #!/lol/wut
| ^
",
status: EXIT_FAILURE,
}

integration_test! {
name: export_shebang,
justfile: r#"
Expand Down

0 comments on commit 023b051

Please sign in to comment.