Skip to main content

SyntaxNode

Enum SyntaxNode 

Source
pub enum SyntaxNode {
    Root {
        mode: ContentMode,
        children: Vec<SyntaxNode>,
    },
    Group {
        mode: ContentMode,
        kind: GroupKind,
        children: Vec<SyntaxNode>,
    },
    Command {
        name: String,
        args: Vec<ArgumentSlot>,
        known: bool,
    },
    Infix {
        name: String,
        args: Vec<ArgumentSlot>,
        left: Box<SyntaxNode>,
        right: Box<SyntaxNode>,
    },
    Declarative {
        name: String,
        args: Vec<ArgumentSlot>,
    },
    Environment {
        name: String,
        args: Vec<ArgumentSlot>,
        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.

Fields

§children: Vec<SyntaxNode>
§

Group

Group: explicit {…}, implicit, delimited \left…\right, or inline math $…$

Fields

§children: Vec<SyntaxNode>
§

Command

Prefix command: \frac{a}{b}, \sqrt[n]{x}.

This is the most common command type where arguments follow the command name.

Fields

§name: String
§known: bool
§

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.

Fields

§name: String
§

Declarative

Declarative command: \color{red}, \bfseries

Fields

§name: String
§

Environment

Environment: \begin{env}…\end{env}

Examples: \begin{matrix}…\end{matrix}, \begin{align*}…\end{align*}

Fields

§name: String
§known: bool
§

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

§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.

Fields

§message: String
§snippet: String
§

Prime

Math prime shorthand represented by one or more consecutive prime marks.

count must be greater than zero.

Fields

§count: usize
§

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

Source

pub fn is_group(&self) -> bool

Check if this node is a content container (Group or parse-tree Root).

Source

pub fn is_leaf(&self) -> bool

Check if this node is a leaf (has no children)

Source

pub fn group_mode(&self) -> Option<ContentMode>

Get the content mode if this is a content container (Group or Root).

Source

pub fn root(mode: ContentMode, children: Vec<SyntaxNode>) -> Self

Create a parse-tree root node wrapping a sequence of top-level children.

Source

pub fn implicit_group(mode: ContentMode, children: Vec<SyntaxNode>) -> Self

Create an implicit group wrapping a sequence of nodes

Source

pub fn empty_group(mode: ContentMode) -> Self

Create an empty implicit group

Source

pub fn prime(count: usize) -> Self

Create a math prime shorthand node.

Trait Implementations§

Source§

impl Clone for SyntaxNode

Source§

fn clone(&self) -> SyntaxNode

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SyntaxNode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for SyntaxNode

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for SyntaxNode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for SyntaxNode

Source§

fn eq(&self, other: &SyntaxNode) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for SyntaxNode

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for SyntaxNode

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.