summaryrefslogtreecommitdiff
path: root/src/syntax
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-08-17 22:04:18 +0200
committerLaurenz <laurmaedje@gmail.com>2021-08-17 22:20:37 +0200
commit594809e35b9e768f1a50926cf5e7a9df41ba7d16 (patch)
tree488f201599a67329d7916b9b3ecb73dd27ad24d7 /src/syntax
parentc53d98a22f367a9eecfb45d1b22f1be5c6cf908d (diff)
Library functions behave more imperatively
- Templates scope state changes - State-modifying function operate in place instead of returning a template - Internal template representation contains actual owned nodes instead of a pointer to a syntax tree + an expression map - No more wide calls
Diffstat (limited to 'src/syntax')
-rw-r--r--src/syntax/expr.rs4
-rw-r--r--src/syntax/node.rs4
-rw-r--r--src/syntax/pretty.rs2
-rw-r--r--src/syntax/visit.rs4
4 files changed, 6 insertions, 8 deletions
diff --git a/src/syntax/expr.rs b/src/syntax/expr.rs
index 3a71bedd..aac23a6f 100644
--- a/src/syntax/expr.rs
+++ b/src/syntax/expr.rs
@@ -170,7 +170,7 @@ pub struct TemplateExpr {
/// The source code location.
pub span: Span,
/// The contents of the template.
- pub tree: Rc<SyntaxTree>,
+ pub tree: SyntaxTree,
}
/// A grouped expression: `(1 + 2)`.
@@ -406,8 +406,6 @@ pub struct CallExpr {
pub span: Span,
/// The function to call.
pub callee: Expr,
- /// Whether the call is wide, that is, capturing the template behind it.
- pub wide: bool,
/// The arguments to the function.
pub args: CallArgs,
}
diff --git a/src/syntax/node.rs b/src/syntax/node.rs
index 2ca861dc..4ff69c17 100644
--- a/src/syntax/node.rs
+++ b/src/syntax/node.rs
@@ -5,8 +5,6 @@ use super::*;
pub enum SyntaxNode {
/// Whitespace containing less than two newlines.
Space,
- /// Plain text.
- Text(EcoString),
/// A forced line break: `\`.
Linebreak(Span),
/// A paragraph break: Two or more newlines.
@@ -15,6 +13,8 @@ pub enum SyntaxNode {
Strong(Span),
/// Emphasized text was enabled / disabled: `_`.
Emph(Span),
+ /// Plain text.
+ Text(EcoString),
/// A raw block with optional syntax highlighting: `` `...` ``.
Raw(Box<RawNode>),
/// A section heading: `= Introduction`.
diff --git a/src/syntax/pretty.rs b/src/syntax/pretty.rs
index 40ebf758..cf9ee69d 100644
--- a/src/syntax/pretty.rs
+++ b/src/syntax/pretty.rs
@@ -88,11 +88,11 @@ impl Pretty for SyntaxNode {
match self {
// TODO: Handle escaping.
Self::Space => p.push(' '),
- Self::Text(text) => p.push_str(text),
Self::Linebreak(_) => p.push_str(r"\"),
Self::Parbreak(_) => p.push_str("\n\n"),
Self::Strong(_) => p.push('*'),
Self::Emph(_) => p.push('_'),
+ Self::Text(text) => p.push_str(text),
Self::Raw(raw) => raw.pretty(p),
Self::Heading(n) => n.pretty(p),
Self::List(n) => n.pretty(p),
diff --git a/src/syntax/visit.rs b/src/syntax/visit.rs
index 5e00e1e6..2b4649de 100644
--- a/src/syntax/visit.rs
+++ b/src/syntax/visit.rs
@@ -87,11 +87,11 @@ impl_visitors! {
visit_node(v, node: SyntaxNode) {
match node {
SyntaxNode::Space => {}
- SyntaxNode::Text(_) => {}
SyntaxNode::Linebreak(_) => {}
SyntaxNode::Parbreak(_) => {}
SyntaxNode::Strong(_) => {}
SyntaxNode::Emph(_) => {}
+ SyntaxNode::Text(_) => {}
SyntaxNode::Raw(_) => {}
SyntaxNode::Heading(n) => v.visit_heading(n),
SyntaxNode::List(n) => v.visit_list(n),
@@ -149,7 +149,7 @@ impl_visitors! {
visit_template(v, template: TemplateExpr) {
v.visit_enter();
- v.visit_tree(r!(rc: template.tree));
+ v.visit_tree(r!(template.tree));
v.visit_exit();
}