diff options
| author | Martin Haug <mhaug@live.de> | 2021-05-29 12:25:10 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-05-31 22:33:40 +0200 |
| commit | 9f77f09aacd1fb0fd6138a6d16ed2755f6bfae3f (patch) | |
| tree | eba4a1609f178b3f2e6838ca9ee3c013e420621f /src/syntax/expr.rs | |
| parent | 0bfee5b7772338fd39bbf708d3e31ea7bcec859b (diff) | |
Parse import and include expressions
Co-Authored-By: Laurenz <laurmaedje@gmail.com>
Diffstat (limited to 'src/syntax/expr.rs')
| -rw-r--r-- | src/syntax/expr.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/syntax/expr.rs b/src/syntax/expr.rs index 97361fc3..fd106eb8 100644 --- a/src/syntax/expr.rs +++ b/src/syntax/expr.rs @@ -56,6 +56,10 @@ pub enum Expr { While(WhileExpr), /// A for loop expression: `for x in y { z }`. For(ForExpr), + /// An import expression: `import "utils.typ" using a, b, c`. + Import(ImportExpr), + /// An include expression: `include "chapter1.typ"`. + Include(IncludeExpr), } impl Expr { @@ -85,6 +89,8 @@ impl Expr { Self::If(ref v) => v.span, Self::While(ref v) => v.span, Self::For(ref v) => v.span, + Self::Import(ref v) => v.span, + Self::Include(ref v) => v.span, } } @@ -432,6 +438,35 @@ pub struct LetExpr { pub init: Option<Box<Expr>>, } +/// An import expression: `import "utils.typ" using a, b, c`. +#[derive(Debug, Clone, PartialEq)] +pub struct ImportExpr { + /// The source code location. + pub span: Span, + /// The items to be imported. + pub imports: Imports, + /// The location of the importable file. + pub path: Box<Expr>, +} + +/// The items that ought to be imported from a file. +#[derive(Debug, Clone, PartialEq)] +pub enum Imports { + /// All items in the scope of the file should be imported. + Wildcard, + /// The specified identifiers from the file should be imported. + Idents(Vec<Ident>), +} + +/// An include expression: `include "chapter1.typ"`. +#[derive(Debug, Clone, PartialEq)] +pub struct IncludeExpr { + /// The source code location. + pub span: Span, + /// The location of the file to be included. + pub path: Box<Expr>, +} + /// An if-else expression: `if x { y } else { z }`. #[derive(Debug, Clone, PartialEq)] pub struct IfExpr { |
