33 releases

0.8.0-alpha.5 Jan 22, 2022
0.7.6 Nov 26, 2021
0.7.1 Aug 23, 2020
0.7.0 Mar 1, 2020
0.2.1 Oct 30, 2018

#351 in Parser implementations

Download history 12/week @ 2022-04-21 244/week @ 2022-04-28 239/week @ 2022-05-05 544/week @ 2022-05-12 146/week @ 2022-05-19 147/week @ 2022-05-26 382/week @ 2022-06-02 23/week @ 2022-06-09 18/week @ 2022-06-16 9/week @ 2022-06-23 50/week @ 2022-06-30 46/week @ 2022-07-07 43/week @ 2022-07-14 108/week @ 2022-07-21 11/week @ 2022-07-28 98/week @ 2022-08-04

299 downloads per month
Used in 5 crates (4 directly)

MIT license

325KB
7.5K SLoC

Rust

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.

Iterator Example

use resast::prelude::*;
use ressa::*;

fn main() {
    let js = "function helloWorld() { alert('Hello world'); }";
    let p = Parser::new(&js).unwrap();
    let f = ProgramPart::decl(Decl::Func(Func {
        id: Some(Ident::from("helloWorld")),
        params: vec![],
        body: FuncBody(vec![ProgramPart::Stmt(Stmt::Expr(Expr::Call(CallExpr {
            callee: Box::new(Expr::ident_from("alert")),
            arguments: vec![Expr::Lit(Lit::String(StringLit::Single(Cow::Owned(
                "Hello world".to_string(),
            ))))],
        })))]),
        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.

Dependencies

~4–5.5MB
~114K SLoC