Disallow empty import groups
This commit is contained in:
parent
91985df449
commit
9adae9c262
@ -197,7 +197,7 @@ fn import(input: Span) -> ParseResult<ImportSpecifier> {
|
||||
map(
|
||||
preceded(
|
||||
tag("::"),
|
||||
delimited(char('{'), separated_list0(tok(char(',')), identifier), char('}')),
|
||||
delimited(char('{'), cut(separated_list1(tok(char(',')), identifier)), char('}')),
|
||||
),
|
||||
|names| ImportedNames::List(names.into_iter().map(|n| rc_string(n.fragment())).collect()),
|
||||
),
|
||||
|
@ -78,7 +78,13 @@ peg::parser! {
|
||||
|
||||
rule import_suffix() -> ImportedNames =
|
||||
"::*" { ImportedNames::All } /
|
||||
"::{" __ names:(identifier() ** (_ "," _)) __ "}" { ImportedNames::List(names.into_iter().map(rc_string).collect()) }
|
||||
"::{" __ names:(identifier() ** (_ "," _)) __ "}" {?
|
||||
if names.is_empty() {
|
||||
Err("import groups must have at least one item")
|
||||
} else {
|
||||
Ok(ImportedNames::List(names.into_iter().map(rc_string).collect()))
|
||||
}
|
||||
}
|
||||
|
||||
rule declaration(parser: &mut Parser) -> Declaration =
|
||||
binding(parser) / type_decl(parser) / annotation(parser) / func(parser) / interface(parser) /
|
||||
|
@ -1106,15 +1106,7 @@ fn imports() {
|
||||
}))]
|
||||
};
|
||||
|
||||
//TODO this shouldn't be legal
|
||||
assert_ast! {
|
||||
"import bespouri::{}",
|
||||
vec![stmt(StatementKind::Import(ImportSpecifier {
|
||||
id: Default::default(),
|
||||
path_components: vec![rc("bespouri")],
|
||||
imported_names: ImportedNames::List(vec![]),
|
||||
}))]
|
||||
};
|
||||
assert_fail!("import bespouri::{}");
|
||||
|
||||
assert_ast! {
|
||||
"import bespouri::*",
|
||||
|
Loading…
Reference in New Issue
Block a user