imports
This commit is contained in:
parent
e618498881
commit
92c6d7f311
@ -33,9 +33,33 @@ peg::parser! {
|
||||
kind:statement_kind() { Statement { id: Default::default(), location: Default::default(), kind } }
|
||||
|
||||
rule statement_kind() -> StatementKind =
|
||||
__ import:import() { StatementKind::Import(import) } /
|
||||
__ decl:declaration() { StatementKind::Declaration(decl) } /
|
||||
__ expr:expression() { StatementKind::Expression(expr) }
|
||||
|
||||
rule import() -> ImportSpecifier =
|
||||
"import" _ path_components:path_components() suffix:import_suffix()? {
|
||||
ImportSpecifier {
|
||||
id: Default::default(),
|
||||
path_components,
|
||||
imported_names: suffix.unwrap_or_else(|| ImportedNames::LastOfPath)
|
||||
}
|
||||
}
|
||||
|
||||
rule path_components() -> Vec<Rc<String>> =
|
||||
"::"? name:identifier() rest:path_component()* {
|
||||
let mut items = vec![rc_string(name)];
|
||||
items.extend(rest.into_iter().map(|n| rc_string(n)));
|
||||
items
|
||||
}
|
||||
|
||||
rule path_component() -> &'input str = "::" ident:identifier() { ident }
|
||||
|
||||
rule import_suffix() -> ImportedNames =
|
||||
"::*" { ImportedNames::All } /
|
||||
"::{" __ names:(identifier() ** (_ "," _)) __ "}" { ImportedNames::List(names.into_iter().map(rc_string).collect()) }
|
||||
|
||||
|
||||
rule declaration() -> Declaration =
|
||||
binding() / type_decl() / annotation() / func() / interface() / implementation() / module()
|
||||
|
||||
|
@ -1049,7 +1049,7 @@ fn modules() {
|
||||
|
||||
#[test]
|
||||
fn imports() {
|
||||
assert_ast! {
|
||||
assert_ast2! {
|
||||
"import harbinger::draughts::Norgleheim",
|
||||
vec![stmt(StatementKind::Import(ImportSpecifier {
|
||||
id: ItemId::default(),
|
||||
@ -1058,7 +1058,7 @@ fn imports() {
|
||||
}))]
|
||||
};
|
||||
|
||||
assert_ast! {
|
||||
assert_ast2! {
|
||||
"import harbinger::draughts::{Norgleheim, Xraksenlaigar}",
|
||||
vec![stmt(StatementKind::Import(ImportSpecifier {
|
||||
id: ItemId::default(),
|
||||
@ -1068,7 +1068,7 @@ fn imports() {
|
||||
}))]
|
||||
};
|
||||
|
||||
assert_ast! {
|
||||
assert_ast2! {
|
||||
"import bespouri::{}",
|
||||
vec![stmt(StatementKind::Import(ImportSpecifier {
|
||||
id: Default::default(),
|
||||
@ -1077,7 +1077,7 @@ fn imports() {
|
||||
}))]
|
||||
};
|
||||
|
||||
assert_ast! {
|
||||
assert_ast2! {
|
||||
"import bespouri::*",
|
||||
vec![stmt(StatementKind::Import(ImportSpecifier {
|
||||
id: Default::default(),
|
||||
|
Loading…
Reference in New Issue
Block a user