Enum Node

Source
pub enum Node<'a> {
    Tag(Tag<'a>),
    Ident(Ann<Atom<'a>>),
    Enclosure(Ann<Enclosure<'a, Node<'a>>>),
    String(Ann<Atom<'a>>),
    InvalidToken(Ann<Atom<'a>>),
}

Variants§

§

Tag(Tag<'a>)

The parser doesn’t emit AST Tag nodes. This is done in a later processing phase.

§

Ident(Ann<Atom<'a>>)

Some identifier that may or may not be followed by square parentheses and/or a curly brace enclosure. E.g. \name.

§

Enclosure(Ann<Enclosure<'a, Node<'a>>>)

An enclosure can be a multitude of things:

  • Some syntactic enclosure:
    • Curly braces
    • Parentheses
    • Square parentheses
  • Some error with it’s invalid start & end token (i.e. a opening [ and closing })
  • Additionally, after parsing, an enclosure can also be a fragment (i.e. a list of AST nodes)
§

String(Ann<Atom<'a>>)

Some string of arbitrary characters or a single special token.

§

InvalidToken(Ann<Atom<'a>>)

Some unbalanced token that isn’t associated with an enclosure. In Subscript, enclosure symbols must be balanced. If the author must use such in their publications, then use the tag version.

Implementations§

Source§

impl<'a> Node<'a>

Source

pub fn new_tag(name: Ann<&'a str>, children: Vec<Node<'a>>) -> Self

Some tag with no parameters and just children.

Source

pub fn new_ident(str: Ann<&'a str>) -> Self

Source

pub fn new_enclosure( range: CharRange, kind: EnclosureKind<'a>, children: Vec<Node<'a>>, ) -> Self

Source

pub fn new_string(str: Ann<&'a str>) -> Self

Source

pub fn unannotated_tag(name: &'a str, children: Vec<Node<'a>>) -> Self

Source

pub fn unannotated_tag_(name: &'a str, child: Node<'a>) -> Self

Source

pub fn unannotated_ident(str: &'a str) -> Self

Source

pub fn unannotated_enclosure( kind: EnclosureKind<'a>, children: Vec<Node<'a>>, ) -> Self

Source

pub fn unannotated_str(str: &'a str) -> Self

Source

pub fn unannotated_string(str: String) -> Self

Source

pub fn new_fragment(nodes: Vec<Self>) -> Self

Source

pub fn is_whitespace(&self) -> bool

Source

pub fn is_tag(&self) -> bool

Source

pub fn is_ident(&self) -> bool

Source

pub fn is_enclosure(&self) -> bool

Source

pub fn is_string(&self) -> bool

Source

pub fn is_any_enclosure(&self) -> bool

Source

pub fn is_enclosure_of_kind(&self, k: EnclosureKind<'_>) -> bool

Source

pub fn is_named_block(&self, name: &str) -> bool

Source

pub fn get_string(&'a self) -> Option<Ann<Atom<'a>>>

Source

pub fn get_enclosure_children( &self, kind: EnclosureKind<'_>, ) -> Option<&Vec<Node<'a>>>

Source

pub fn unblock(self) -> Vec<Self>

Source

pub fn into_fragment(self) -> Vec<Self>

Unpacks an Node::Enclosure with the Fragment kind or returns a singleton vec.

Source

pub fn unwrap_tag(&self) -> Option<&Tag<'a>>

Source

pub fn unwrap_tag_mut(&mut self) -> Option<&mut Tag<'a>>

Source

pub fn unwrap_ident<'b>(&'b self) -> Option<&'b Ann<Atom<'a>>>

Source

pub fn unwrap_enclosure<'b>( &'b self, ) -> Option<&'b Ann<Enclosure<'a, Node<'a>>>>

Source

pub fn unwrap_curly_brace<'b>(&'b self) -> Option<&'b Vec<Node<'a>>>

Source

pub fn unwrap_string<'b>(&'b self) -> Option<&'b Ann<Atom<'a>>>

Source

pub fn unwrap_string_mut<'b>(&'b mut self) -> Option<&'b mut Ann<Atom<'a>>>

Source

pub fn into_tag(self) -> Option<Tag<'a>>

Source

pub fn transform<F: Fn(NodeEnvironment<'a>, Node<'a>) -> Node<'a>>( self, env: NodeEnvironment<'a>, f: Rc<F>, ) -> Self

Bottom up ‘node to ndoe’ transformation.

Source

pub fn transform_mut<F: FnMut(NodeEnvironment<'a>, Node<'a>) -> Node<'a>>( self, env: NodeEnvironment<'a>, f: Rc<RefCell<F>>, ) -> Self

Source

pub fn transform_children<F>(self, f: Rc<F>) -> Self
where F: Fn(Vec<Node<'a>>) -> Vec<Node<'a>>,

Bottom up transformation of AST child nodes within the same enclosure.

Source

pub fn into_highlight_ranges( self, nesting: Vec<Atom<'a>>, binder: Option<Atom<'a>>, ) -> Vec<Highlight<'a>>

For syntax highlighting VIA the compiler frontend.

Source

pub fn to_string(&self) -> String

Examples found in repository?
examples/frontend.rs (line 10)
4fn main() {
5    let source = include_str!("./source/electrical-engineering.txt");
6    // let source = "\\h1{Hello world}";
7    let nodes = subscript_compiler::frontend::pass::pp_normalize::run_compiler_frontend(source);
8    // let nodes = subscript_compiler::frontend::pass::html_normalize::html_canonicalization(nodes);
9    for node in nodes {
10        println!("{}", node.to_string());
11    }
12}
Source

pub fn syntactically_equal(&self, other: &Self) -> bool

Source

pub fn push_child(self, child: Self) -> Self

Push to a fragment or tag node. TODO: Should we also push to any EnclosureKind?

Trait Implementations§

Source§

impl<'a> Clone for Node<'a>

Source§

fn clone(&self) -> Node<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Node<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Node<'a>

§

impl<'a> RefUnwindSafe for Node<'a>

§

impl<'a> Send for Node<'a>

§

impl<'a> Sync for Node<'a>

§

impl<'a> Unpin for Node<'a>

§

impl<'a> UnwindSafe for Node<'a>

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