[][src]Struct ressa::Builder

pub struct Builder { /* fields omitted */ }

This is used to create a Parser using the builder method

use ressa::Builder;
use ressa::node::*;
fn main() {
    let js = "for (var i = 0; i < 100; i++) {
        console.log('loop', i);
        }";
    let p = Builder::new()
                    .module(false)
                    .js(js)
                    .build()
                    .unwrap();
    for part in p {
        let expectation = ProgramPart::Statement(
            Statement::For(
                ForStatement {
                    init: Some(
                        LoopInit::Variable(
                            vec![VariableDecl::with_value("i", Expression::number("0"))]
                        )
                    ),
                    test: Some(
                        Expression::binary(Expression::ident("i"), BinaryOperator::LessThan, Expression::number("100"))
                    ),
                    update: Some(
                        Expression::Update(
                            UpdateExpression {
                                operator: UpdateOperator::Increment,
                                argument: Box::new(Expression::ident("i")),
                                prefix: false,
                            }
                        )
                    ),
                    body:
                        Box::new(Statement::Block(
                            vec![ProgramPart::Statement(
                                Statement::Expr(
                                    Expression::call(Expression::member(Expression::ident("console"), Expression::ident("log"), false),
                                    vec![
                                        Expression::string("'loop'"),
                                        Expression::ident("i"),
                                    ])
                                )
                            )]
                        )
                    )
                }
            )
        );
        assert_eq!(part.unwrap(), expectation);
    }
}

Methods

impl Builder
[src]

pub fn new() -> Self
[src]

pub fn set_tolerant(&mut self, value: bool)
[src]

Enable or disable error tolerance default: false

pub fn tolerant(&mut self, value: bool) -> &mut Self
[src]

Enable or disable error tolerance with a builder pattern default: false

pub fn set_module(&mut self, value: bool)
[src]

Set the parsing context to module or script default: false (script)

pub fn module(&mut self, value: bool) -> &mut Self
[src]

Set the parsing context to module or script with a builder pattern default: false (script)

pub fn set_js(
    &mut self,
    js: impl Into<String>
)
[src]

Set the js text that this parser would operate on

pub fn js(
    &mut self,
    js: impl Into<String>
) -> &mut Self
[src]

Set the js text that this parser would operate on with a builder pattern

pub fn build(&self) -> Result<Parser<DefaultCommentHandler>, Error>
[src]

Complete the builder pattern returning Result<Parser, Error>

pub fn with_comment_handler<CH>(
    &self,
    comment_handler: CH
) -> Result<Parser<CH>, Error> where
    CH: CommentHandler + Sized
[src]

An alternate to the build method. This will allow users to define their own comment handler

Auto Trait Implementations

impl Send for Builder

impl Sync for Builder

Blanket Implementations

impl<T> From for T
[src]

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

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

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]