[][src]Struct ressa::Parser

pub struct Parser<'a, CH> {
    pub comment_handler: CH,
    // some fields omitted
}

This is the primary interface that you would interact with. There are two main ways to use it, the first is to utilize the Iterator implementation. Each iteration will return a Result<ProgramPart, Error>. The other option is to use the parse method, which is just a wrapper around the collect method on Iterator, however the final result will be a Result<Program, Error> and the ProgramPart collection will be the inner data. Since modern js allows for both Modules as well as Scripts, these will be the two enum variants.

Fields

comment_handler: CH

Implementations

impl<'a> Parser<'a, DefaultCommentHandler>[src]

pub fn new(text: &'a str) -> Result<Self, Error>[src]

Create a new parser with the provided javascript This will default to parsing in the script context and discard comments. If you wanted change this behavior utilize the Builder pattern

impl<'a> Parser<'a, ()>[src]

pub fn builder() -> Builder<'a>[src]

impl<'b, CH> Parser<'b, CH> where
    CH: CommentHandler<'b> + Sized
[src]

pub fn build(
    tolerant: bool,
    is_module: bool,
    scanner: Scanner<'b>,
    comment_handler: CH,
    original: &'b str
) -> Result<Self, Error>
[src]

Internal constructor for completing the builder pattern

pub fn parse(&mut self) -> Result<Program<'_>, Error>[src]

Wrapper around the Iterator implementation for Parser

extern crate ressa;
use ressa::Parser;
use resast::prelude::*;
fn main() {
    let js = "function helloWorld() { alert('Hello world'); }";
    let mut p = Parser::new(&js).unwrap();
    let call = CallExpr {
        callee: Box::new(Expr::ident_from("alert")),
        arguments: vec![Expr::Lit(Lit::single_string_from("Hello world"))],
    };
    let expectation = Program::Script(vec![ProgramPart::Decl(Decl::Func(Func {
        id: Some(Ident::from("helloWorld")),
        params: Vec::new(),
        body: FuncBody(vec![ProgramPart::Stmt(Stmt::Expr(Expr::Call(call)))]),
        generator: false,
        is_async: false,
    }))]);
    let program = p.parse().unwrap();
    //assert_eq!(program, expectation);
}

pub fn is_simple(arg: &FuncArg<'_>) -> bool[src]

pub fn next_position(&self) -> SourceLocation[src]

Trait Implementations

impl<'b, CH> Iterator for Parser<'b, CH> where
    CH: CommentHandler<'b> + Sized
[src]

type Item = Result<ProgramPart<'b>, Error>

The type of the elements being iterated over.

Auto Trait Implementations

impl<'a, CH> RefUnwindSafe for Parser<'a, CH> where
    CH: RefUnwindSafe

impl<'a, CH> Send for Parser<'a, CH> where
    CH: Send

impl<'a, CH> Sync for Parser<'a, CH> where
    CH: Sync

impl<'a, CH> Unpin for Parser<'a, CH> where
    CH: Unpin

impl<'a, CH> UnwindSafe for Parser<'a, CH> where
    CH: UnwindSafe

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> From<T> for T[src]

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

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

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.