Enum ludtwig_parser::ast::SyntaxNode[][src]

pub enum SyntaxNode {
    Root(Vec<SyntaxNode>),
    Tag(Tag),
    Plain(Plain),
    Whitespace,
    HtmlComment(HtmlComment),
    OutputExpression(OutputExpression),
    TwigComment(TwigComment),
    TwigStatement(TwigStatement),
    TwigStructure(TwigStructure<SyntaxNode>),
}

The base enum for each syntax element in a document. Each variant represents some sort of structured representation of the document syntax. This is the foundation for the AST (abstract syntax tree) that is produced by the parser.

Variants

The root of the AST which contains other SyntaxNode values.

Tag(Tag)

Plain old Html tag that can have any value as a name (even vue components for example). It may also have attributes. It can also have children which are only a list of SyntaxNode instances. For example <h2 class="bold">...</h2>

Plain(Plain)

Basically only plain text but does only represent text without line break characters or indentation.

Whitespace

Some sort of whitespace (can be anything from spaces to tabs to line breaks). Multiple sequential forms of whitespace will always result in only one instance of this.

HtmlComment(HtmlComment)

Comments in Html that look like <!-- some comment -->

OutputExpression(OutputExpression)

Some expression to output something like
twig: {{ my_counter|e }} (can be php)
vue: {{ myCounter.count }} (can be javascript)

TwigComment(TwigComment)

Comment in twig syntax: {# some comment #}

TwigStatement(TwigStatement)

Some execute statement that has no children / has no closing syntax.

Examples

{% set foo = 'foo' %}

or {% parent %}

or ...

TwigStructure(TwigStructure<SyntaxNode>)

Some hierarchical twig syntax.

Examples

{% block my_block_name %}...{% endblock %}

Notes

This is preferred over TwigStatement by the parser if it sees special keywords like block right after the {% .

Implementations

impl SyntaxNode[src]

pub fn is_whitespace(&self) -> bool[src]

impl SyntaxNode[src]

pub fn context_iter(&self) -> AstContextIterator<'_, SyntaxNode>[src]

Create a borrowing iterator over this &SyntaxNode and all it's children (and their children, ...). It visits in a pre-order tree traversal:

  1. visits the node itself
  2. visits all the child nodes

Also each node is visited with a IteratorContext that contains the following information:

  • the parent node of the currently visited one.
  • the previous node in the tree before the visited one (same depth).
  • the after node in the tree that occurs after the visited one (same depth).

pub fn context_attribute_iter(&self) -> AstContextIterator<'_, TagAttribute>[src]

Create a borrowing iterator over the &TagAttributes of a &Tag that iterates over all nested attributes with a context. If this &SyntaxNode is not a &Tag it will return an empty iterator.

Also each attribute is visited with a IteratorContext that contains the following information:

  • the parent attribute of the currently visited one.
  • the previous attribute in the tree before the visited one (same depth).
  • the after attribute in the tree that occurs after the visited one (same depth).

impl SyntaxNode[src]

pub fn iter(&self) -> AstIterator<'_, SyntaxNode>

Notable traits for AstIterator<'a, SyntaxNode>

impl<'a> Iterator for AstIterator<'a, SyntaxNode> type Item = &'a SyntaxNode;impl<'a> Iterator for AstIterator<'a, TagAttribute> type Item = &'a TagAttribute;
[src]

Create a borrowing iterator over this &SyntaxNode and all it's children (and their children, ...). It visits in a pre-order tree traversal:

  1. visits the node itself
  2. visits all the child nodes

pub fn attribute_iter(&self) -> AstIterator<'_, TagAttribute>

Notable traits for AstIterator<'a, SyntaxNode>

impl<'a> Iterator for AstIterator<'a, SyntaxNode> type Item = &'a SyntaxNode;impl<'a> Iterator for AstIterator<'a, TagAttribute> type Item = &'a TagAttribute;
[src]

Create a borrowing iterator over the &TagAttributes of a &Tag that iterates over all nested attributes. If this &SyntaxNode is not a &Tag it will return an empty iterator.

It visits in a pre-order tree traversal:

  1. visits the attribute itself
  2. visits all the child attributes

Trait Implementations

impl Clone for SyntaxNode[src]

impl Debug for SyntaxNode[src]

impl Eq for SyntaxNode[src]

impl<'a> IntoIterator for &'a SyntaxNode[src]

type Item = &'a SyntaxNode

The type of the elements being iterated over.

type IntoIter = AstIterator<'a, SyntaxNode>

Which kind of iterator are we turning this into?

fn into_iter(self) -> Self::IntoIter[src]

Create a borrowing iterator over this &SyntaxNode and all it's children (and their children, ...). It visits in a pre-order tree traversal:

  1. visits the node itself
  2. visits all the child nodes

impl PartialEq<SyntaxNode> for SyntaxNode[src]

impl StructuralEq for SyntaxNode[src]

impl StructuralPartialEq for SyntaxNode[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Conv for T

impl<T> Conv for T

impl<T> FmtForward for T

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pipe for T where
    T: ?Sized

impl<T> Pipe for T

impl<T> PipeAsRef for T

impl<T> PipeBorrow for T

impl<T> PipeDeref for T

impl<T> PipeRef for T

impl<T> Tap for T

impl<T> Tap for T

impl<T, U> TapAsRef<U> for T where
    U: ?Sized

impl<T, U> TapBorrow<U> for T where
    U: ?Sized

impl<T> TapDeref for T

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> TryConv for T

impl<T> TryConv for T

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.