diff options
| author | Martin <mhaug@live.de> | 2021-12-22 20:37:34 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-22 20:37:34 +0100 |
| commit | f6c7a8292dc1ab0560408fca9d74505e9d7cf13a (patch) | |
| tree | badd3076f6146cec34c55764600df5124c408521 /src/syntax/ast.rs | |
| parent | 738ff7e1f573bef678932b313be9969a17af8d22 (diff) | |
| parent | 438255519e88bb790480306b9a9b452aaf054519 (diff) | |
Merge pull request #51 from typst/set-rules
Set rules
Diffstat (limited to 'src/syntax/ast.rs')
| -rw-r--r-- | src/syntax/ast.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/syntax/ast.rs b/src/syntax/ast.rs index 8df25f59..ae8ecdc9 100644 --- a/src/syntax/ast.rs +++ b/src/syntax/ast.rs @@ -1,4 +1,6 @@ //! A typed layer over the red-green tree. +//! +//! The AST is rooted in the [`Markup`] node. use std::ops::Deref; @@ -211,6 +213,8 @@ pub enum Expr { With(WithExpr), /// A let expression: `let x = 1`. Let(LetExpr), + /// A set expression: `set text(...)`. + Set(SetExpr), /// An if-else expression: `if x { y } else { z }`. If(IfExpr), /// A while loop expression: `while x { y }`. @@ -238,6 +242,7 @@ impl TypedNode for Expr { NodeKind::Closure => node.cast().map(Self::Closure), NodeKind::WithExpr => node.cast().map(Self::With), NodeKind::LetExpr => node.cast().map(Self::Let), + NodeKind::SetExpr => node.cast().map(Self::Set), NodeKind::IfExpr => node.cast().map(Self::If), NodeKind::WhileExpr => node.cast().map(Self::While), NodeKind::ForExpr => node.cast().map(Self::For), @@ -262,6 +267,7 @@ impl TypedNode for Expr { Self::Closure(v) => v.as_red(), Self::With(v) => v.as_red(), Self::Let(v) => v.as_red(), + Self::Set(v) => v.as_red(), Self::If(v) => v.as_red(), Self::While(v) => v.as_red(), Self::For(v) => v.as_red(), @@ -279,6 +285,7 @@ impl Expr { Self::Ident(_) | Self::Call(_) | Self::Let(_) + | Self::Set(_) | Self::If(_) | Self::While(_) | Self::For(_) @@ -838,6 +845,25 @@ impl LetExpr { } node! { + /// A set expression: `set text(...)`. + SetExpr +} + +impl SetExpr { + /// The class to set style properties for. + pub fn class(&self) -> Ident { + self.0.cast_first_child().expect("set expression is missing class") + } + + /// The style properties to set. + pub fn args(&self) -> CallArgs { + self.0 + .cast_first_child() + .expect("set expression is missing argument list") + } +} + +node! { /// An import expression: `import a, b, c from "utils.typ"`. ImportExpr } |
