pub enum SyntaxNode {
Root {
mode: ContentMode,
children: Vec<SyntaxNode>,
},
Group {
mode: ContentMode,
kind: GroupKind,
children: Vec<SyntaxNode>,
},
Command {
name: String,
args: Vec<Option<Argument>>,
known: bool,
},
Infix {
name: String,
args: Vec<Option<Argument>>,
left: Box<SyntaxNode>,
right: Box<SyntaxNode>,
},
Declarative {
name: String,
args: Vec<Option<Argument>>,
},
Environment {
name: String,
args: Vec<Option<Argument>>,
known: bool,
body: Box<SyntaxNode>,
},
Scripted {
base: Box<SyntaxNode>,
subscript: Option<Box<SyntaxNode>>,
superscript: Option<Box<SyntaxNode>>,
},
Error {
message: String,
snippet: String,
},
Prime {
count: usize,
},
Text(String),
Char(char),
ActiveSpace,
}Expand description
Immutable syntax tree node
Represents the structure of parsed LaTeX source code. Each variant corresponds to a different syntactic construct.
Variants§
Root
Parse-tree root node produced by the top-level parser.
A Root never nests inside another SyntaxNode; it marks the entry
point of a parsed formula and carries the top-level content mode.
Group
Group: explicit {…}, implicit, delimited \left…\right, or inline math $…$
Command
Prefix command: \frac{a}{b}, \sqrt[n]{x}.
This is the most common command type where arguments follow the command name.
Infix
Infix command: a \over b, {n \choose k}
Only ONE infix command is allowed per group at the top level. The left and right operands are collected during parsing.
Declarative
Declarative command: \color{red}, \bfseries
Environment
Environment: \begin{env}…\end{env}
Examples: \begin{matrix}…\end{matrix}, \begin{align*}…\end{align*}
Scripted
Scripted expression: x^2_i, a_{n-1}
Subscripts and superscripts are normalized:
- Order of ^ and _ is ignored (x^2_i == x_i^2)
- Duplicates take the last occurrence (x^a^b -> superscript = b)
Fields
base: Box<SyntaxNode>subscript: Option<Box<SyntaxNode>>superscript: Option<Box<SyntaxNode>>Error
Parser-produced error placeholder.
Recovery inserts this node where the parser could not interpret a source
fragment. AST and document-style conversions preserve it so callers can
inspect partial trees or serialize the captured snippet. Callers that
require semantically complete trees should inspect parser diagnostics and
check for Error nodes before continuing.
Prime
Math prime shorthand represented by one or more consecutive prime marks.
count must be greater than zero.
Text(String)
Text string (Text mode only)
Produced in Text mode or as content of Text-mode arguments/environments. Consecutive characters and whitespace are merged into a single Text node. Multiple whitespace characters collapse into a single space. Note: In Math mode, characters remain as individual Char nodes, not Text.
Char(char)
Single character (primarily in math mode)
Examples: letters (a-z, A-Z), digits (0-9), symbols (+, -, =)
ActiveSpace
Active character ~ (non-breaking space)
In LaTeX, ~ produces a non-breaking space. This node is produced in both Math and Text modes. In Text mode, ~ is NOT merged into TextChunk; it remains as a separate node.
TODO: Decide whether this needs to remain a distinct node type.
Implementations§
Source§impl SyntaxNode
impl SyntaxNode
Sourcepub fn is_group(&self) -> bool
pub fn is_group(&self) -> bool
Check if this node is a content container (Group or parse-tree Root).
Sourcepub fn group_mode(&self) -> Option<ContentMode>
pub fn group_mode(&self) -> Option<ContentMode>
Get the content mode if this is a content container (Group or Root).
Sourcepub fn root(mode: ContentMode, children: Vec<SyntaxNode>) -> SyntaxNode
pub fn root(mode: ContentMode, children: Vec<SyntaxNode>) -> SyntaxNode
Create a parse-tree root node wrapping a sequence of top-level children.
Sourcepub fn implicit_group(
mode: ContentMode,
children: Vec<SyntaxNode>,
) -> SyntaxNode
pub fn implicit_group( mode: ContentMode, children: Vec<SyntaxNode>, ) -> SyntaxNode
Create an implicit group wrapping a sequence of nodes
Sourcepub fn empty_group(mode: ContentMode) -> SyntaxNode
pub fn empty_group(mode: ContentMode) -> SyntaxNode
Create an empty implicit group
Sourcepub fn prime(count: usize) -> SyntaxNode
pub fn prime(count: usize) -> SyntaxNode
Create a math prime shorthand node.
Trait Implementations§
Source§impl Clone for SyntaxNode
impl Clone for SyntaxNode
Source§fn clone(&self) -> SyntaxNode
fn clone(&self) -> SyntaxNode
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SyntaxNode
impl Debug for SyntaxNode
Source§impl<'de> Deserialize<'de> for SyntaxNode
impl<'de> Deserialize<'de> for SyntaxNode
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<SyntaxNode, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<SyntaxNode, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Display for SyntaxNode
impl Display for SyntaxNode
Source§impl PartialEq for SyntaxNode
impl PartialEq for SyntaxNode
Source§fn eq(&self, other: &SyntaxNode) -> bool
fn eq(&self, other: &SyntaxNode) -> bool
self and other values to be equal, and is used by ==.