Struct biome_js_parser::Parse
source · 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_module(root: JsSyntaxNode, errors: Vec<ParseDiagnostic>) -> Parse<T>
pub fn new_script(root: JsSyntaxNode, errors: Vec<ParseDiagnostic>) -> Parse<T>
pub fn new(root: JsSyntaxNode, errors: Vec<ParseDiagnostic>) -> Parse<T>
pub fn cast<N: AstNode<Language = JsLanguage>>(self) -> Option<Parse<N>>
sourcepub fn syntax(&self) -> JsSyntaxNode
pub fn syntax(&self) -> JsSyntaxNode
The syntax node represented by this Parse result
use biome_js_parser::{JsParserOptions, parse_script};
use biome_js_syntax::{JsIfStatement, JsSyntaxKind};
use biome_rowan::{AstNode, AstNodeList};
let parse = parse_script(
"
if (a > 5) {
/* something */
}
",
JsParserOptions::default()
);
// The first stmt in the root syntax node (Script) is the if statement.
let if_stmt = parse.tree().statements().first().unwrap();
assert_eq!(if_stmt.syntax().kind(), JsSyntaxKind::JS_IF_STATEMENT);sourcepub fn diagnostics(&self) -> &[ParseDiagnostic]
pub fn diagnostics(&self) -> &[ParseDiagnostic]
Get the diagnostics which occurred when parsing
sourcepub fn into_diagnostics(self) -> Vec<ParseDiagnostic>
pub fn into_diagnostics(self) -> Vec<ParseDiagnostic>
Get the diagnostics which occurred when parsing
sourcepub fn has_errors(&self) -> bool
pub fn has_errors(&self) -> bool
Returns true if the parser encountered some errors during the parsing.
source§impl<T: AstNode<Language = JsLanguage>> Parse<T>
impl<T: AstNode<Language = JsLanguage>> Parse<T>
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<ParseDiagnostic>>
pub fn ok(self) -> Result<T, Vec<ParseDiagnostic>>
Convert this parse into a result
Trait Implementations§
Auto Trait Implementations§
impl<T> RefUnwindSafe for Parse<T>where
T: RefUnwindSafe,
impl<T> !Send for Parse<T>
impl<T> !Sync for Parse<T>
impl<T> Unpin for Parse<T>where
T: Unpin,
impl<T> UnwindSafe for Parse<T>where
T: UnwindSafe,
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