Struct ressa::Builder

source ·
pub struct Builder { /* private fields */ }
Expand description

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

Implementations

Enable or disable error tolerance default: false

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

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

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

Set the js text that this parser would operate on

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

Complete the builder pattern returning Result<Parser, Error>

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.