Allow multiple attributes on one line (#1537)

This commit is contained in:
Greg Shuflin 2023-01-26 23:54:24 -08:00 committed by GitHub
parent 054d6672c5
commit 687831816d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 80 additions and 12 deletions

View File

@ -854,19 +854,25 @@ impl<'tokens, 'src> Parser<'tokens, 'src> {
let mut attributes = BTreeMap::new(); let mut attributes = BTreeMap::new();
while self.accepted(BracketL)? { while self.accepted(BracketL)? {
let name = self.parse_name()?; loop {
let attribute = Attribute::from_name(name).ok_or_else(|| { let name = self.parse_name()?;
name.error(CompileErrorKind::UnknownAttribute { let attribute = Attribute::from_name(name).ok_or_else(|| {
attribute: name.lexeme(), name.error(CompileErrorKind::UnknownAttribute {
}) attribute: name.lexeme(),
})?; })
if let Some(line) = attributes.get(&attribute) { })?;
return Err(name.error(CompileErrorKind::DuplicateAttribute { if let Some(line) = attributes.get(&attribute) {
attribute: name.lexeme(), return Err(name.error(CompileErrorKind::DuplicateAttribute {
first: *line, 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(BracketR)?;
self.expect_eol()?; self.expect_eol()?;
} }

View File

@ -41,3 +41,65 @@ fn duplicate_attributes_are_disallowed() {
.status(1) .status(1)
.run(); .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();
}