pub struct Ast { /* private fields */ }
Expand description
An abstract syntax tree, contains all the nodes used in the code
Implementations
sourceimpl Ast
impl Ast
sourcepub fn update_positions(self) -> Self
pub fn update_positions(self) -> Self
Will update the positions of all the tokens in the tree Necessary if you are both mutating the tree and need the positions of the tokens
sourceimpl Ast
impl Ast
sourcepub fn from_tokens(tokens: Vec<Token>) -> Result<Ast, AstError>
pub fn from_tokens(tokens: Vec<Token>) -> Result<Ast, AstError>
Create an Ast from the passed tokens. You probably want parse
Errors
If the tokens passed are impossible to get through normal tokenization, an error of Empty (if the vector is empty) or NoEof (if there is no eof token) will be returned.
More likely, if the tokens pass are invalid Lua 5.1 code, an UnexpectedToken error will be returned.
sourcepub fn with_nodes(self, nodes: Block) -> Self
pub fn with_nodes(self, nodes: Block) -> Self
Returns a new Ast with the given nodes
sourcepub fn with_eof(self, eof: TokenReference) -> Self
pub fn with_eof(self, eof: TokenReference) -> Self
Returns a new Ast with the given EOF token
sourcepub fn nodes(&self) -> &Block
pub fn nodes(&self) -> &Block
The entire code of the function
assert_eq!(full_moon::parse("local x = 1; local y = 2")?.nodes().stmts().count(), 2);
sourcepub fn eof(&self) -> &TokenReference
pub fn eof(&self) -> &TokenReference
The EOF token at the end of every Ast
Trait Implementations
sourceimpl Node for Ast
impl Node for Ast
sourcefn start_position(&self) -> Option<Position>
fn start_position(&self) -> Option<Position>
The start position of a node. None if can’t be determined
sourcefn end_position(&self) -> Option<Position>
fn end_position(&self) -> Option<Position>
The end position of a node. None if it can’t be determined
sourcefn similar(&self, other: &Self) -> bool
fn similar(&self, other: &Self) -> bool
Whether another node of the same type is the same as this one semantically, ignoring position
sourcefn tokens(&self) -> Tokens<'_>ⓘNotable traits for Tokens<'a>impl<'a> Iterator for Tokens<'a> type Item = &'a TokenReference;
fn tokens(&self) -> Tokens<'_>ⓘNotable traits for Tokens<'a>impl<'a> Iterator for Tokens<'a> type Item = &'a TokenReference;
The token references that comprise a node
Auto Trait Implementations
impl RefUnwindSafe for Ast
impl Send for Ast
impl Sync for Ast
impl Unpin for Ast
impl UnwindSafe for Ast
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more