summaryrefslogtreecommitdiff
path: root/src/syntax
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-04-23 21:55:58 +0200
committerLaurenz <laurmaedje@gmail.com>2022-04-23 21:55:58 +0200
commit04fb8b288aa7c80607da79db7d085a4820b95a9d (patch)
tree7ca96d09d511274ebac298c329d5eef53a290d9c /src/syntax
parent7a2cc3e7d29d16c5cf9b5a93a688e14da93c8662 (diff)
Show rules with type ascribed object
Diffstat (limited to 'src/syntax')
-rw-r--r--src/syntax/ast.rs21
-rw-r--r--src/syntax/highlight.rs18
-rw-r--r--src/syntax/mod.rs2
3 files changed, 29 insertions, 12 deletions
diff --git a/src/syntax/ast.rs b/src/syntax/ast.rs
index 8af359bf..82bb7d56 100644
--- a/src/syntax/ast.rs
+++ b/src/syntax/ast.rs
@@ -249,7 +249,7 @@ pub enum Expr {
Let(LetExpr),
/// A set expression: `set text(...)`.
Set(SetExpr),
- /// A show expression: `show heading(body) as [*{body}*]`.
+ /// A show expression: `show node: heading as [*{nody.body}*]`.
Show(ShowExpr),
/// A wrap expression: `wrap body in columns(2, body)`.
Wrap(WrapExpr),
@@ -999,19 +999,28 @@ impl SetExpr {
}
node! {
- /// A show expression: `show heading(body) as [*{body}*]`.
+ /// A show expression: `show node: heading as [*{nody.body}*]`.
ShowExpr
}
impl ShowExpr {
+ /// The binding to assign to.
+ pub fn binding(&self) -> Ident {
+ self.0.cast_first_child().expect("show rule is missing binding")
+ }
+
/// The function to customize with this show rule.
pub fn target(&self) -> Ident {
- self.0.cast_first_child().expect("show rule is missing target")
+ self.0
+ .children()
+ .filter_map(RedRef::cast)
+ .nth(1)
+ .expect("show rule is missing target")
}
- /// The closure that defines the rule.
- pub fn recipe(&self) -> ClosureExpr {
- self.0.cast_last_child().expect("show rule is missing closure")
+ /// The expression that realizes the node.
+ pub fn body(&self) -> Expr {
+ self.0.cast_last_child().expect("show rule is missing body")
}
}
diff --git a/src/syntax/highlight.rs b/src/syntax/highlight.rs
index 10dfce69..9bee73ae 100644
--- a/src/syntax/highlight.rs
+++ b/src/syntax/highlight.rs
@@ -178,13 +178,21 @@ impl Category {
NodeKind::None => Some(Category::None),
NodeKind::Auto => Some(Category::Auto),
NodeKind::Ident(_) => match parent.kind() {
- NodeKind::Named => None,
- NodeKind::ClosureExpr if i == 0 => Some(Category::Function),
- NodeKind::SetExpr => Some(Category::Function),
- NodeKind::ShowExpr => Some(Category::Function),
+ NodeKind::Markup(_) => Some(Category::Variable),
NodeKind::FuncCall => Some(Category::Function),
NodeKind::MethodCall if i > 0 => Some(Category::Function),
- NodeKind::Markup(_) => Some(Category::Variable),
+ NodeKind::ClosureExpr if i == 0 => Some(Category::Function),
+ NodeKind::SetExpr => Some(Category::Function),
+ NodeKind::ShowExpr
+ if parent
+ .children()
+ .filter(|c| matches!(c.kind(), NodeKind::Ident(_)))
+ .map(RedRef::span)
+ .nth(1)
+ .map_or(false, |span| span == child.span()) =>
+ {
+ Some(Category::Function)
+ }
_ => None,
},
NodeKind::Bool(_) => Some(Category::Bool),
diff --git a/src/syntax/mod.rs b/src/syntax/mod.rs
index 71646cb2..00bcb376 100644
--- a/src/syntax/mod.rs
+++ b/src/syntax/mod.rs
@@ -671,7 +671,7 @@ pub enum NodeKind {
LetExpr,
/// A set expression: `set text(...)`.
SetExpr,
- /// A show expression: `show heading(body) as [*{body}*]`.
+ /// A show expression: `show node: heading as [*{nody.body}*]`.
ShowExpr,
/// A wrap expression: `wrap body in columns(2, body)`.
WrapExpr,