From 9f77f09aacd1fb0fd6138a6d16ed2755f6bfae3f Mon Sep 17 00:00:00 2001 From: Martin Haug Date: Sat, 29 May 2021 12:25:10 +0200 Subject: Parse import and include expressions Co-Authored-By: Laurenz --- src/syntax/expr.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/syntax/expr.rs') 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>, } +/// 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, +} + +/// 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), +} + +/// 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, +} + /// An if-else expression: `if x { y } else { z }`. #[derive(Debug, Clone, PartialEq)] pub struct IfExpr { -- cgit v1.2.3