Skip to content

Commit

Permalink
Allow comments after mod statements (casey#2201)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored and Spatenheinz committed Jun 28, 2024
1 parent 999c69c commit cab2bba
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,11 @@ impl<'run, 'src> Parser<'run, 'src> {
});
}
Some(Keyword::Mod)
if self.next_are(&[Identifier, Identifier, StringToken])
|| self.next_are(&[Identifier, Identifier, Identifier, StringToken])
if self.next_are(&[Identifier, Identifier, Comment])
|| self.next_are(&[Identifier, Identifier, Eof])
|| self.next_are(&[Identifier, Identifier, Eol])
|| self.next_are(&[Identifier, Identifier, Identifier, StringToken])
|| self.next_are(&[Identifier, Identifier, StringToken])
|| self.next_are(&[Identifier, QuestionMark]) =>
{
let comment = pop_doc_comment(&mut items, eol_since_last_comment);
Expand Down
17 changes: 15 additions & 2 deletions tests/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ fn modules_are_unstable() {
mod foo
",
)
.arg("foo")
.arg("foo")
.stderr(
"error: Modules are currently unstable. \
Invoke `just` with the `--unstable` flag to enable unstable features.\n",
Expand Down Expand Up @@ -781,3 +779,18 @@ fn colon_separated_path_components_are_not_used_as_arguments() {
.status(1)
.run();
}

#[test]
fn comments_can_follow_modules() {
Test::new()
.write("foo.just", "foo:\n @echo FOO")
.justfile(
"
mod foo # this is foo
",
)
.test_round_trip(false)
.args(["--unstable", "foo", "foo"])
.stdout("FOO\n")
.run();
}

0 comments on commit cab2bba

Please sign in to comment.