pub struct Parse<T> { /* private fields */ }
Expand description
A utility struct for managing the result of a parser job
Implementations§
Source§impl<T> Parse<T>
impl<T> Parse<T>
pub fn new(green: GreenNode, errors: Vec<ParserError>) -> Parse<T>
Sourcepub fn green(self) -> GreenNode
pub fn green(self) -> GreenNode
Consume the parse result and get its green node. This is useful for multithreaded accesses to the tree as syntax nodes are not sync but green nodes are.
Sourcepub fn syntax(&self) -> SyntaxNode
pub fn syntax(&self) -> SyntaxNode
The syntax node represented by this Parse result
use rslint_parser::{parse_text, ast::IfStmt, SyntaxNodeExt, SyntaxKind, AstNode};
let parse = parse_text(
"
if (a > 5) {
/* something */
}
", 0);
// The first child of the root syntax node (Script) is the if statement.
let if_stmt = parse.syntax().first_child().unwrap();
assert_eq!(if_stmt.kind(), SyntaxKind::IF_STMT);
// The if statement node is untyped, we must first cast it to a typed ast node
// to be able to get properties of it in an easy way.
assert_eq!(if_stmt.to::<IfStmt>().condition().unwrap().syntax().text(), "(a > 5)");
Sourcepub fn errors(&self) -> &[ParserError] ⓘ
pub fn errors(&self) -> &[ParserError] ⓘ
Get the errors which ocurred when parsing
Source§impl<T: AstNode> Parse<T>
impl<T: AstNode> Parse<T>
Sourcepub fn to_syntax(self) -> Parse<SyntaxNode>
pub fn to_syntax(self) -> Parse<SyntaxNode>
Convert the result to an untyped SyntaxNode parse.
Sourcepub fn tree(&self) -> T
pub fn tree(&self) -> T
Convert this parse result into a typed AST node.
§Panics
Panics if the node represented by this parse result mismatches.
Sourcepub fn try_tree(&self) -> Option<T>
pub fn try_tree(&self) -> Option<T>
Try to convert this parse’s untyped syntax node into an AST node.
Sourcepub fn ok(self) -> Result<T, Vec<ParserError>>
pub fn ok(self) -> Result<T, Vec<ParserError>>
Convert this parse into a result
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Parse<T>
impl<T> RefUnwindSafe for Parse<T>
impl<T> Send for Parse<T>
impl<T> Sync for Parse<T>
impl<T> Unpin for Parse<T>
impl<T> UnwindSafe for Parse<T>
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