summaryrefslogtreecommitdiff
path: root/src/syntax
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-03-11 12:59:55 +0100
committerLaurenz <laurmaedje@gmail.com>2022-03-11 23:36:06 +0100
commit5ac7eb3860ebd3247f6486c227e816894cb8fd91 (patch)
treea29a868c681c7de39f15f2d9d3f031db1861b90a /src/syntax
parent5ce2a006b6d45d29be15e4562ae3ab4fc1b8e97c (diff)
Rename template to content
Diffstat (limited to 'src/syntax')
-rw-r--r--src/syntax/ast.rs18
-rw-r--r--src/syntax/highlight.rs2
-rw-r--r--src/syntax/mod.rs24
3 files changed, 26 insertions, 18 deletions
diff --git a/src/syntax/ast.rs b/src/syntax/ast.rs
index 425af0c1..f48b445c 100644
--- a/src/syntax/ast.rs
+++ b/src/syntax/ast.rs
@@ -221,8 +221,8 @@ pub enum Expr {
Ident(Ident),
/// A code block: `{ let x = 1; x + 2 }`.
Code(CodeBlock),
- /// A template block: `[*Hi* there!]`.
- Template(TemplateBlock),
+ /// A content block: `[*Hi* there!]`.
+ Content(ContentBlock),
/// A grouped expression: `(1 + 2)`.
Group(GroupExpr),
/// An array expression: `(1, "hi", 12cm)`.
@@ -270,7 +270,7 @@ impl TypedNode for Expr {
match node.kind() {
NodeKind::Ident(_) => node.cast().map(Self::Ident),
NodeKind::CodeBlock => node.cast().map(Self::Code),
- NodeKind::TemplateBlock => node.cast().map(Self::Template),
+ NodeKind::ContentBlock => node.cast().map(Self::Content),
NodeKind::GroupExpr => node.cast().map(Self::Group),
NodeKind::ArrayExpr => node.cast().map(Self::Array),
NodeKind::DictExpr => node.cast().map(Self::Dict),
@@ -299,7 +299,7 @@ impl TypedNode for Expr {
match self {
Self::Lit(v) => v.as_red(),
Self::Code(v) => v.as_red(),
- Self::Template(v) => v.as_red(),
+ Self::Content(v) => v.as_red(),
Self::Ident(v) => v.as_red(),
Self::Array(v) => v.as_red(),
Self::Dict(v) => v.as_red(),
@@ -419,14 +419,14 @@ impl CodeBlock {
}
node! {
- /// A template block: `[*Hi* there!]`.
- TemplateBlock: TemplateBlock
+ /// A content block: `[*Hi* there!]`.
+ ContentBlock: ContentBlock
}
-impl TemplateBlock {
- /// The contents of the template.
+impl ContentBlock {
+ /// The contained markup.
pub fn body(&self) -> Markup {
- self.0.cast_first_child().expect("template is missing body")
+ self.0.cast_first_child().expect("content is missing body")
}
}
diff --git a/src/syntax/highlight.rs b/src/syntax/highlight.rs
index 20ea4039..c0e3376e 100644
--- a/src/syntax/highlight.rs
+++ b/src/syntax/highlight.rs
@@ -203,7 +203,7 @@ impl Category {
NodeKind::List => None,
NodeKind::Enum => None,
NodeKind::CodeBlock => None,
- NodeKind::TemplateBlock => None,
+ NodeKind::ContentBlock => None,
NodeKind::GroupExpr => None,
NodeKind::ArrayExpr => None,
NodeKind::DictExpr => None,
diff --git a/src/syntax/mod.rs b/src/syntax/mod.rs
index a3393eda..e15cfabc 100644
--- a/src/syntax/mod.rs
+++ b/src/syntax/mod.rs
@@ -579,9 +579,9 @@ pub enum NodeKind {
From,
/// The `as` keyword.
As,
- /// Template markup of which all lines must start in some column.
+ /// Markup of which all lines must start in some column.
///
- /// Notably, the usize does not determine in which column the markup
+ /// Notably, the number does not determine in which column the markup
/// started, but to the right of which column all markup elements must be,
/// so it is zero except for headings and lists.
Markup(usize),
@@ -644,8 +644,8 @@ pub enum NodeKind {
Str(EcoString),
/// A code block: `{ let x = 1; x + 2 }`.
CodeBlock,
- /// A template block: `[*Hi* there!]`.
- TemplateBlock,
+ /// A content block: `[*Hi* there!]`.
+ ContentBlock,
/// A grouped expression: `(1 + 2)`.
GroupExpr,
/// An array expression: `(1, "hi", 12cm)`.
@@ -763,8 +763,16 @@ impl NodeKind {
}
}
+ /// Whether this node has to appear at the start of a line.
+ pub fn only_at_start(&self) -> bool {
+ match self {
+ Self::Heading | Self::Enum | Self::List => true,
+ _ => false,
+ }
+ }
+
/// Which mode this node can appear in, in both if `None`.
- pub fn mode(&self) -> Option<TokenMode> {
+ pub fn only_in_mode(&self) -> Option<TokenMode> {
match self {
Self::Markup(_)
| Self::Linebreak
@@ -782,7 +790,7 @@ impl NodeKind {
| Self::List
| Self::Raw(_)
| Self::Math(_) => Some(TokenMode::Markup),
- Self::TemplateBlock
+ Self::ContentBlock
| Self::Space(_)
| Self::Ident(_)
| Self::CodeBlock
@@ -884,7 +892,7 @@ impl NodeKind {
Self::Fraction(_) => "`fr` value",
Self::Str(_) => "string",
Self::CodeBlock => "code block",
- Self::TemplateBlock => "template block",
+ Self::ContentBlock => "content block",
Self::GroupExpr => "group",
Self::ArrayExpr => "array",
Self::DictExpr => "dictionary",
@@ -1008,7 +1016,7 @@ impl Hash for NodeKind {
Self::Fraction(v) => v.to_bits().hash(state),
Self::Str(v) => v.hash(state),
Self::CodeBlock => {}
- Self::TemplateBlock => {}
+ Self::ContentBlock => {}
Self::GroupExpr => {}
Self::ArrayExpr => {}
Self::DictExpr => {}