rd-parse-jsexpr

    2.1.0 • Public • Published

    jsexpr

    Javascript (ES2015) expression grammar, defined in Javascript, and parsed by Javascript ! Designed for rd-parse.

    It is an "immutable" pure functional reduction of the ECMAScript grammar: loosely based on descriptions from here and here. Matches (almost) anything you can put on the right hand side of an assignment operator in ES2015.

    The mutating constructs such as increment / decrement / assignment operators, as well as higher level language constructs (loops, classes etc) are excluded.

    Usage:

        import Parser from 'rd-parse';
        import Grammar from 'rd-parse-jsexpr';
    
        const parser = Parser(Grammar);
    
        const ast = parser('[1,2,3].map(a => a*a).reduce((a,b) => a + b)');
    
        console.log(JSON.stringify(ast, null, 2));      // Pretty print your AST

    I tried to keep the AST as close as possible to the format produced by another popular JS expression parser jsep.

    This grammar is slightly richer than jsep though. Unlike the latter, I properly parse ES6 arrow functions, object literals, and support spread elements, and shorthand notation. The code is also readable ;)

    Install

    npm i rd-parse-jsexpr

    DownloadsWeekly Downloads

    9

    Version

    2.1.0

    License

    MIT

    Unpacked Size

    21.3 kB

    Total Files

    7

    Last publish

    Collaborators

    • dmaevsky