diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-01-03 12:29:35 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-01-03 12:32:17 +0100 |
| commit | 29b31c4a5ac4cde311c4d38b3d70130e7d27ba76 (patch) | |
| tree | fe4e5dbd2166a69af90e69578ad4602725cdb63c /src/syntax/ast.rs | |
| parent | 54962e6dcd002fd27918827996155fd7dc4e1cff (diff) | |
New import syntax
Diffstat (limited to 'src/syntax/ast.rs')
| -rw-r--r-- | src/syntax/ast.rs | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/src/syntax/ast.rs b/src/syntax/ast.rs index ccad77c2..4ef0b2a6 100644 --- a/src/syntax/ast.rs +++ b/src/syntax/ast.rs @@ -1430,29 +1430,26 @@ impl ForPattern { } node! { - /// A module import: `import a, b, c from "utils.typ"`. + /// A module import: `import "utils.typ": a, b, c`. ModuleImport } impl ModuleImport { - /// The items to be imported. - pub fn imports(&self) -> Imports { - self.0 - .children() - .find_map(|node| match node.kind() { - SyntaxKind::Star => Some(Imports::Wildcard), - SyntaxKind::ImportItems => { - let items = node.children().filter_map(SyntaxNode::cast).collect(); - Some(Imports::Items(items)) - } - _ => None, - }) - .expect("module import is missing items") + /// The module or path from which the items should be imported. + pub fn source(&self) -> Expr { + self.0.cast_last_child().expect("module import is missing source") } - /// The path to the file that should be imported. - pub fn path(&self) -> Expr { - self.0.cast_last_child().expect("module import is missing path") + /// The items to be imported. + pub fn imports(&self) -> Option<Imports> { + self.0.children().find_map(|node| match node.kind() { + SyntaxKind::Star => Some(Imports::Wildcard), + SyntaxKind::ImportItems => { + let items = node.children().filter_map(SyntaxNode::cast).collect(); + Some(Imports::Items(items)) + } + _ => None, + }) } } @@ -1471,8 +1468,8 @@ node! { } impl ModuleInclude { - /// The path to the file that should be included. - pub fn path(&self) -> Expr { + /// The module or path from which the content should be included. + pub fn source(&self) -> Expr { self.0.cast_last_child().expect("module include is missing path") } } |
