summaryrefslogtreecommitdiff
path: root/src/syntax/ast.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/syntax/ast.rs')
-rw-r--r--src/syntax/ast.rs26
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
}