14 releases (4 breaking)

✓ Uses Rust 2018 edition

0.5.2 May 22, 2019
0.5.1 Mar 4, 2019
0.4.2 Feb 23, 2019
0.4.0 Jan 19, 2019
0.1.0 Oct 23, 2018

#42 in Parser tooling

Download history 6/week @ 2019-02-06 13/week @ 2019-02-20 52/week @ 2019-02-27 9/week @ 2019-03-06 11/week @ 2019-03-13 18/week @ 2019-03-20 16/week @ 2019-03-27 17/week @ 2019-04-03 27/week @ 2019-04-10 13/week @ 2019-04-17 22/week @ 2019-04-24 16/week @ 2019-05-01 13/week @ 2019-05-08 35/week @ 2019-05-15

98 downloads per month
Used in 1 crate

MIT license

193KB
4.5K SLoC

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::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".to_string()),
                params: vec![],
                body: vec![
                    ProgramPart::Stmt(
                        Stmt::Expr(
                            Expr::call(Expr::ident("alert"), vec![Expr::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::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.

Dependencies

~6.5MB
~126K SLoC