[][src]Struct rslint_parser::Parse

pub struct Parse<T> { /* fields omitted */ }

A utility struct for managing the result of a parser job

Implementations

impl<T> Parse<T>[src]

pub fn new(green: GreenNode, errors: Vec<ParserError>) -> Parse<T>[src]

pub fn green(self) -> GreenNode[src]

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.

pub fn syntax(&self) -> SyntaxNode[src]

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)");

pub fn errors(&self) -> &[ParserError][src]

Get the errors which ocurred when parsing

impl<T: AstNode> Parse<T>[src]

pub fn to_syntax(self) -> Parse<SyntaxNode>[src]

Convert the result to an untyped SyntaxNode parse.

pub fn tree(&self) -> T[src]

Convert this parse result into a typed AST node.

Panics

Panics if the node represented by this parse result mismatches.

pub fn try_tree(&self) -> Option<T>[src]

Try to convert this parse's untyped syntax node into an AST node.

pub fn ok(self) -> Result<T, Vec<ParserError>>[src]

Convert this parse into a result

Trait Implementations

impl<T> Clone for Parse<T>[src]

impl<T: Debug> Debug for Parse<T>[src]

Auto Trait Implementations

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

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> Erasable for T

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

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

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

type Owned = T

The resulting type after obtaining ownership.

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.