From 37639d68d740a887a5aec58c79441fb6b10546f0 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 8 Apr 2019 14:28:17 -0700 Subject: [PATCH] Allow shebang lines so justfiles can be used as scripts (#393) --- README.adoc | 21 +++++++++++++++++++++ justfile | 4 ++++ src/compilation_error.rs | 4 ---- src/lexer.rs | 16 ++-------------- tests/integration.rs | 22 ---------------------- 5 files changed, 27 insertions(+), 40 deletions(-) mode change 100644 => 100755 justfile diff --git a/README.adoc b/README.adoc index ba48c288..fa2b7b47 100644 --- a/README.adoc +++ b/README.adoc @@ -653,6 +653,27 @@ $ just foo/build $ just foo/ ``` +=== Just Scripts + +By adding a shebang line to the top of a justfile and making it executable, `just` can be used as an interpreter for scripts: + +```sh +$ cat > script < { MixedLeadingWhitespace { whitespace: &'a str, }, - OuterShebang, ParameterFollowsVariadicParameter { parameter: &'a str, }, @@ -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, diff --git a/src/lexer.rs b/src/lexer.rs index 018cb744..abc2ea02 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -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"="); @@ -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)); }; @@ -340,7 +338,7 @@ impl<'a> Lexer<'a> { _ => { return Err(last.error(Internal { message: format!("zero length token: {:?}", last), - })) + })); } } } @@ -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: "~", diff --git a/tests/integration.rs b/tests/integration.rs index 400b40e9..044c848d 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -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#"