Skip to content

Commit

Permalink
Allow multiple attributes on one line (#1537)
Browse files Browse the repository at this point in the history
  • Loading branch information
neunenak authored Jan 27, 2023
1 parent 054d667 commit 6878318
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -854,19 +854,25 @@ impl<'tokens, 'src> Parser<'tokens, 'src> {
let mut attributes = BTreeMap::new();

while self.accepted(BracketL)? {
let name = self.parse_name()?;
let attribute = Attribute::from_name(name).ok_or_else(|| {
name.error(CompileErrorKind::UnknownAttribute {
attribute: name.lexeme(),
})
})?;
if let Some(line) = attributes.get(&attribute) {
return Err(name.error(CompileErrorKind::DuplicateAttribute {
attribute: name.lexeme(),
first: *line,
}));
loop {
let name = self.parse_name()?;
let attribute = Attribute::from_name(name).ok_or_else(|| {
name.error(CompileErrorKind::UnknownAttribute {
attribute: name.lexeme(),
})
})?;
if let Some(line) = attributes.get(&attribute) {
return Err(name.error(CompileErrorKind::DuplicateAttribute {
attribute: name.lexeme(),
first: *line,
}));
}
attributes.insert(attribute, name.line);

if !self.accepted(TokenKind::Comma)? {
break;
}
}
attributes.insert(attribute, name.line);
self.expect(BracketR)?;
self.expect_eol()?;
}
Expand Down
62 changes: 62 additions & 0 deletions tests/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,65 @@ fn duplicate_attributes_are_disallowed() {
.status(1)
.run();
}

#[test]
fn multiple_attributes_one_line() {
Test::new()
.justfile(
"
[macos, windows,linux]
[no-exit-message]
foo:
exit 1
",
)
.stderr("exit 1\n")
.status(1)
.run();
}

#[test]
fn multiple_attributes_one_line_error_message() {
Test::new()
.justfile(
"
[macos, windows linux]
[no-exit-message]
foo:
exit 1
",
)
.stderr(
"
error: Expected ']' or ',', but found identifier
|
1 | [macos, windows linux]
| ^^^^^
",
)
.status(1)
.run();
}

#[test]
fn multiple_attributes_one_line_duplicate_check() {
Test::new()
.justfile(
"
[macos, windows, linux]
[linux]
foo:
exit 1
",
)
.stderr(
"
error: Recipe attribute `linux` first used on line 1 is duplicated on line 2
|
2 | [linux]
| ^^^^^
",
)
.status(1)
.run();
}

0 comments on commit 6878318

Please sign in to comment.