summaryrefslogtreecommitdiff
path: root/crates/typst-eval/src
diff options
context:
space:
mode:
authorIan Wrzesinski <133046678+wrzian@users.noreply.github.com>2025-02-26 15:10:36 -0500
committerGitHub <noreply@github.com>2025-02-26 20:10:36 +0000
commitcfb3b1a2709107f0f06f89ea25cabc939cec15e5 (patch)
treef61f39cc3c1a6eec30d37aa4202d6c599e74b2f7 /crates/typst-eval/src
parent52f1f53973414be72bf22c3253ab365f8db067df (diff)
Improve clarity of `ast.rs` for newcomers to the codebase (#5784)
Co-authored-by: PgBiel <9021226+PgBiel@users.noreply.github.com> Co-authored-by: T0mstone <39707032+T0mstone@users.noreply.github.com>
Diffstat (limited to 'crates/typst-eval/src')
-rw-r--r--crates/typst-eval/src/call.rs8
-rw-r--r--crates/typst-eval/src/code.rs36
-rw-r--r--crates/typst-eval/src/markup.rs4
-rw-r--r--crates/typst-eval/src/rules.rs2
4 files changed, 25 insertions, 25 deletions
diff --git a/crates/typst-eval/src/call.rs b/crates/typst-eval/src/call.rs
index c68bef96..1ca7b4b8 100644
--- a/crates/typst-eval/src/call.rs
+++ b/crates/typst-eval/src/call.rs
@@ -466,7 +466,7 @@ impl<'a> CapturesVisitor<'a> {
}
// Code and content blocks create a scope.
- Some(ast::Expr::Code(_) | ast::Expr::Content(_)) => {
+ Some(ast::Expr::CodeBlock(_) | ast::Expr::ContentBlock(_)) => {
self.internal.enter();
for child in node.children() {
self.visit(child);
@@ -516,7 +516,7 @@ impl<'a> CapturesVisitor<'a> {
// A let expression contains a binding, but that binding is only
// active after the body is evaluated.
- Some(ast::Expr::Let(expr)) => {
+ Some(ast::Expr::LetBinding(expr)) => {
if let Some(init) = expr.init() {
self.visit(init.to_untyped());
}
@@ -529,7 +529,7 @@ impl<'a> CapturesVisitor<'a> {
// A for loop contains one or two bindings in its pattern. These are
// active after the iterable is evaluated but before the body is
// evaluated.
- Some(ast::Expr::For(expr)) => {
+ Some(ast::Expr::ForLoop(expr)) => {
self.visit(expr.iterable().to_untyped());
self.internal.enter();
@@ -544,7 +544,7 @@ impl<'a> CapturesVisitor<'a> {
// An import contains items, but these are active only after the
// path is evaluated.
- Some(ast::Expr::Import(expr)) => {
+ Some(ast::Expr::ModuleImport(expr)) => {
self.visit(expr.source().to_untyped());
if let Some(ast::Imports::Items(items)) = expr.imports() {
for item in items.iter() {
diff --git a/crates/typst-eval/src/code.rs b/crates/typst-eval/src/code.rs
index a7b6b6f9..9078418e 100644
--- a/crates/typst-eval/src/code.rs
+++ b/crates/typst-eval/src/code.rs
@@ -30,7 +30,7 @@ fn eval_code<'a>(
while let Some(expr) = exprs.next() {
let span = expr.span();
let value = match expr {
- ast::Expr::Set(set) => {
+ ast::Expr::SetRule(set) => {
let styles = set.eval(vm)?;
if vm.flow.is_some() {
break;
@@ -39,7 +39,7 @@ fn eval_code<'a>(
let tail = eval_code(vm, exprs)?.display();
Value::Content(tail.styled_with_map(styles))
}
- ast::Expr::Show(show) => {
+ ast::Expr::ShowRule(show) => {
let recipe = show.eval(vm)?;
if vm.flow.is_some() {
break;
@@ -94,9 +94,9 @@ impl Eval for ast::Expr<'_> {
Self::Label(v) => v.eval(vm),
Self::Ref(v) => v.eval(vm).map(Value::Content),
Self::Heading(v) => v.eval(vm).map(Value::Content),
- Self::List(v) => v.eval(vm).map(Value::Content),
- Self::Enum(v) => v.eval(vm).map(Value::Content),
- Self::Term(v) => v.eval(vm).map(Value::Content),
+ Self::ListItem(v) => v.eval(vm).map(Value::Content),
+ Self::EnumItem(v) => v.eval(vm).map(Value::Content),
+ Self::TermItem(v) => v.eval(vm).map(Value::Content),
Self::Equation(v) => v.eval(vm).map(Value::Content),
Self::Math(v) => v.eval(vm).map(Value::Content),
Self::MathText(v) => v.eval(vm).map(Value::Content),
@@ -116,8 +116,8 @@ impl Eval for ast::Expr<'_> {
Self::Float(v) => v.eval(vm),
Self::Numeric(v) => v.eval(vm),
Self::Str(v) => v.eval(vm),
- Self::Code(v) => v.eval(vm),
- Self::Content(v) => v.eval(vm).map(Value::Content),
+ Self::CodeBlock(v) => v.eval(vm),
+ Self::ContentBlock(v) => v.eval(vm).map(Value::Content),
Self::Array(v) => v.eval(vm).map(Value::Array),
Self::Dict(v) => v.eval(vm).map(Value::Dict),
Self::Parenthesized(v) => v.eval(vm),
@@ -126,19 +126,19 @@ impl Eval for ast::Expr<'_> {
Self::Closure(v) => v.eval(vm),
Self::Unary(v) => v.eval(vm),
Self::Binary(v) => v.eval(vm),
- Self::Let(v) => v.eval(vm),
- Self::DestructAssign(v) => v.eval(vm),
- Self::Set(_) => bail!(forbidden("set")),
- Self::Show(_) => bail!(forbidden("show")),
+ Self::LetBinding(v) => v.eval(vm),
+ Self::DestructAssignment(v) => v.eval(vm),
+ Self::SetRule(_) => bail!(forbidden("set")),
+ Self::ShowRule(_) => bail!(forbidden("show")),
Self::Contextual(v) => v.eval(vm).map(Value::Content),
Self::Conditional(v) => v.eval(vm),
- Self::While(v) => v.eval(vm),
- Self::For(v) => v.eval(vm),
- Self::Import(v) => v.eval(vm),
- Self::Include(v) => v.eval(vm).map(Value::Content),
- Self::Break(v) => v.eval(vm),
- Self::Continue(v) => v.eval(vm),
- Self::Return(v) => v.eval(vm),
+ Self::WhileLoop(v) => v.eval(vm),
+ Self::ForLoop(v) => v.eval(vm),
+ Self::ModuleImport(v) => v.eval(vm),
+ Self::ModuleInclude(v) => v.eval(vm).map(Value::Content),
+ Self::LoopBreak(v) => v.eval(vm),
+ Self::LoopContinue(v) => v.eval(vm),
+ Self::FuncReturn(v) => v.eval(vm),
}?
.spanned(span);
diff --git a/crates/typst-eval/src/markup.rs b/crates/typst-eval/src/markup.rs
index 3a5ebe1f..5beefa91 100644
--- a/crates/typst-eval/src/markup.rs
+++ b/crates/typst-eval/src/markup.rs
@@ -33,7 +33,7 @@ fn eval_markup<'a>(
while let Some(expr) = exprs.next() {
match expr {
- ast::Expr::Set(set) => {
+ ast::Expr::SetRule(set) => {
let styles = set.eval(vm)?;
if vm.flow.is_some() {
break;
@@ -41,7 +41,7 @@ fn eval_markup<'a>(
seq.push(eval_markup(vm, exprs)?.styled_with_map(styles))
}
- ast::Expr::Show(show) => {
+ ast::Expr::ShowRule(show) => {
let recipe = show.eval(vm)?;
if vm.flow.is_some() {
break;
diff --git a/crates/typst-eval/src/rules.rs b/crates/typst-eval/src/rules.rs
index 646354d4..f4c1563f 100644
--- a/crates/typst-eval/src/rules.rs
+++ b/crates/typst-eval/src/rules.rs
@@ -45,7 +45,7 @@ impl Eval for ast::ShowRule<'_> {
let transform = self.transform();
let transform = match transform {
- ast::Expr::Set(set) => Transformation::Style(set.eval(vm)?),
+ ast::Expr::SetRule(set) => Transformation::Style(set.eval(vm)?),
expr => expr.eval(vm)?.cast::<Transformation>().at(transform.span())?,
};