Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow newlines when parsing recipes #1272

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,9 +677,14 @@ impl<'run, 'src> Parser<'run, 'src> {
let name = self.parse_name()?;

let mut positional = Vec::new();

while self.next_is(Identifier) || self.next_is(Dollar) {
positional.push(self.parse_parameter(ParameterKind::Singular)?);
loop {
if self.next_is(Identifier) || self.next_is(Dollar) {
positional.push(self.parse_parameter(ParameterKind::Singular)?);
} else if self.next_is(Eol) {
self.accept(Eol)?;
} else {
break;
}
}

let kind = if self.accepted(Plus)? {
Expand All @@ -703,6 +708,9 @@ impl<'run, 'src> Parser<'run, 'src> {
} else {
None
};
while self.next_is(Eol) {
self.accept(Eol)?;
}

self.expect(Colon)?;

Expand Down Expand Up @@ -2088,13 +2096,13 @@ mod tests {
error! {
name: missing_colon,
input: "a b c\nd e f",
offset: 5,
line: 0,
offset: 11,
line: 1,
column: 5,
width: 1,
width: 0,
kind: UnexpectedToken{
expected: vec![Asterisk, Colon, Dollar, Equals, Identifier, Plus],
found: Eol
expected: vec![Asterisk, Colon, Dollar, Eol, Equals, Identifier, Plus],
found: Eof
},
}

Expand Down Expand Up @@ -2228,7 +2236,7 @@ mod tests {
column: 8,
width: 0,
kind: UnexpectedToken {
expected: vec![Asterisk, Colon, Dollar, Equals, Identifier, Plus],
expected: vec![Asterisk, Colon, Dollar, Eol, Equals, Identifier, Plus],
found: Eof
},
}
Expand Down
6 changes: 3 additions & 3 deletions tests/error_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn file_path_is_indented_if_justfile_is_long() {
.status(EXIT_FAILURE)
.stderr(
"
error: Expected '*', ':', '$', identifier, or '+', but found end of file
error: Expected '*', ':', '$', end of line, identifier, or '+', but found end of file
——▶ justfile:20:4
20 │ foo
Expand All @@ -80,7 +80,7 @@ fn file_paths_are_relative() {
.status(EXIT_FAILURE)
.stderr(format!(
"
error: Expected '*', ':', '$', identifier, or '+', but found end of file
error: Expected '*', ':', '$', end of line, identifier, or '+', but found end of file
——▶ foo{}bar.just:1:4
1 │ baz
Expand All @@ -101,7 +101,7 @@ fn file_paths_not_in_subdir_are_absolute() {
.args(["--justfile", "foo/justfile"])
.status(EXIT_FAILURE)
.stderr_regex(
r"error: Expected '\*', ':', '\$', identifier, or '\+', but found end of file
r"error: Expected '\*', ':', '\$', end of line, identifier, or '\+', but found end of file
——▶ /.*/bar.just:1:4
1 │ baz
Expand Down
1 change: 1 addition & 0 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ mod json;
mod line_prefixes;
mod misc;
mod modules;
mod multi_line_recipe_signatures;
mod multibyte_char;
mod newline_escape;
mod no_cd;
Expand Down
8 changes: 4 additions & 4 deletions tests/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,7 @@ test! {
justfile: "foo 'bar'",
args: ("foo"),
stdout: "",
stderr: "error: Expected '*', ':', '$', identifier, or '+', but found string
stderr: "error: Expected '*', ':', '$', end of line, identifier, or '+', but found string
——▶ justfile:1:5
1 │ foo 'bar'
Expand Down Expand Up @@ -1465,7 +1465,7 @@ foo *a +b:
echo {{a}} {{b}}
",
stdout: "",
stderr: "error: Expected \':\' or \'=\', but found \'+\'
stderr: "error: Expected \':\', end of line, or \'=\', but found \'+\'
——▶ justfile:1:8
1 │ foo *a +b:
Expand All @@ -1481,7 +1481,7 @@ foo +a *b:
echo {{a}} {{b}}
",
stdout: "",
stderr: "error: Expected \':\' or \'=\', but found \'*\'
stderr: "error: Expected \':\', end of line, or \'=\', but found \'*\'
——▶ justfile:1:8
1 │ foo +a *b:
Expand Down Expand Up @@ -1890,7 +1890,7 @@ test! {
echo {{foo}}
",
stderr: "
error: Expected '*', ':', '$', identifier, or '+', but found '='
error: Expected '*', ':', '$', end of line, identifier, or '+', but found '='
——▶ justfile:1:5
1 │ foo = 'bar'
Expand Down
15 changes: 15 additions & 0 deletions tests/multi_line_recipe_signatures.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use super::*;

#[test]
fn foo() {
Test::new()
.justfile(
"
foo
bar:
@echo bar
",
)
.stdout("bar\n")
.run();
}
2 changes: 1 addition & 1 deletion tests/slash_operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn default_un_parenthesized() {
)
.stderr(
"
error: Expected '*', ':', '$', identifier, or '+', but found '/'
error: Expected '*', ':', '$', end of line, identifier, or '+', but found '/'
——▶ justfile:1:11
1 │ foo x='a' / 'b':
Expand Down
Loading