Skip to content
Rusty EcmaScript Syntax Analyzer
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
benches Next (#29) Jul 5, 2019
examples Next (#29) Jul 5, 2019
src Next (#29) Jul 5, 2019
tests/all Next (#29) Jul 5, 2019
.gitignore partially through spider_monkey bugs Jan 16, 2019
.travis.yml ? Feb 23, 2019
CONTRIBUTING.md update docs Mar 4, 2019
Cargo.toml Next (#29) Jul 5, 2019
README.md fix: readme examples (#31) Jul 10, 2019
license.txt add gh files Jul 19, 2018
new_benches.md Next (#29) Jul 5, 2019
old_benches.md Next (#29) Jul 5, 2019
package.json adjust testing Oct 15, 2018
run_moz_central_test.sh

README.md

travis crates.io last commit master

RESSA

Rust EcmaScript Syntax Analyzer

This project is part of a series of crates designed to enable developers to create JavaScript development tools using the Rust programming language. Rusty ECMA Details

The two major pieces that users will interact with are the Parser struct and the enums defined by resast

Parser

The parser struct will be the main way to convert text into an AST. Conveniently Parser implements Iterator over Result<ProgramPart, Error>, this means that you can evaluate your JS in pieces from top to bottom. These pieces will be discussed in more detail in the node section.

Iterator Example

use ressa::Parser;
use resast::ref_tree::prelude::*;

fn main() {
    let js = "function helloWorld() { alert('Hello world'); }";
    let p = Parser::new(&js).unwrap();

    let f = ProgramPart::Decl(
        Decl::Function(
            Function {
                id: Some("helloWorld"),
                params: vec![],
                body: vec![
                    ProgramPart::Stmt(
                        Stmt::Expr(
                            Expr::Call(CallExpr {
                                callee: Box::new(Expr::Ident("alert")),
                                arguments: vec![Expr::Literal(Literal::String("'Hello world'"))],
                            })
                        )
                    )
                ],
                generator: false,
                is_async: false,
            }
        )
    );
    for part in p {
        assert_eq!(part.unwrap(), f);
    }
}

Another way to interact with a Parser would be to utilize the parse method. This method will iterate over all of the found ProgramParts and collect them into a Program,

Parse Example

use ressa::{
    Parser,
};
use resast::ref_tree::prelude::*;
fn main() {
    let js = "
function Thing() {
    return 'stuff';
}
";
    let mut parser = Parser::new(js).expect("Failed to create parser");
    let program = parser.parse().expect("Unable to parse text");
    match program {
        Program::Script(parts) => println!("found a script"),
        Program::Mod(parts) => println!("found an es6 module"),
    }
}

Once you get to the inner parts of a Program you have a Vec<ProgramPart> which will operate the same as the iterator example

Rusty ECMA Details

The Rust ECMA Crates

Why So Many?

While much of what each crate provides is closely coupled with the other crates, the main goal is to provide the largest amount of customizability. For example, someone writing a fuzzer would only need the RESAST and RESW, it seems silly to require that they also pull in RESS and RESSA needlessly.

You can’t perform that action at this time.