pub struct Ast { /* private fields */ }
Expand description
An abstract syntax tree, contains all the nodes used in the code
Implementations§
source§impl 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
source§impl 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§
source§impl<'de> Deserialize<'de> for Ast
impl<'de> Deserialize<'de> for Ast
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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 Node for Ast
impl Node for Ast
source§fn start_position(&self) -> Option<Position>
fn start_position(&self) -> Option<Position>
The start position of a node. None if can’t be determined
source§fn end_position(&self) -> Option<Position>
fn end_position(&self) -> Option<Position>
The end position of a node. None if it can’t be determined
source§fn 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
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§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more