fastexpr-rs

Crates.iofastexpr-rs
lib.rsfastexpr-rs
version1.0.2
sourcesrc
created_at2024-07-30 18:00:24.699619
updated_at2024-07-30 18:12:37.833013
descriptionA tiny, fast Javascript expression parser
homepage
repositoryhttps://github.com/anpete/fastexpr.rs
max_upload_size
id1320171
size109,389
Andrew Peters (anpete)

documentation

README

fastexpr.rs

A fast, tiny, minimal dependency JavaScript expression parser, written in Rust.

Features

  • Fast. Hand-coded lexer and top-down operator precedence parser.
  • Small. Around ~1000 LOC.
  • Compatible. Parses all valid JavaScript expressions. Produces an esprima style AST.

Usage:

let result = parse("(s) => `hello from ${s}!`");

match result {
    Ok(expr) => {
        println!("{:#?}", expr);
    }
    Err(err) => {
        println!("{:#?}", err);
    }
}

which produces:

ArrowFunction {
    params: [
        Identifier {
            token: Identifier(
                "s",
            ),
        },
    ],
    body: TemplateLiteral {
        quasis: [
            TemplateString {
                token: String(
                    "hello from ",
                ),
                tail: false,
            },
            TemplateString {
                token: String(
                    "!",
                ),
                tail: true,
            },
        ],
        expressions: [
            Identifier {
                token: Identifier(
                    "s",
                ),
            },
        ],
    },
}
Commit count: 0

cargo fmt