logic-parsers
TypeScript icon, indicating that this package has built-in type declarations

1.3.0 • Public • Published

Wasm bindings for the logic-parser

Wasm bindings for the ../logic-parser written in Rust.

Packaging and publishing was achieved thanks to wasm-bindgen!

npm install logic-parsers

Usage

const { parse_expression, generate_svg } = await import('logic-parsers');

const parsed = parse_expression("((p || q)) => (q && ~(r))");

Outputs:

{
    "status": "success",
    "ast": {
        "type": "operator.implies",
        "left": {
            "type": "operator.or",
            "left": {
                "type": "identifier",
                "name": "p"
            },
            "right": {
                "type": "identifier",
                "name": "q"
            }
        },
        "right": {
            "type": "operator.and",
            "left": {
                "type": "identifier",
                "name": "q"
            },
            "right": {
                "type": "operator.not",
                "operand": {
                    "type": "identifier",
                    "name": "r"
                }
            }
        }
    }
}

SVG tree rendering:

const svg_xml = generate_svg(parsed.ast);
document.querySelector("#output").innerHTML = svg_xml;

SVG Result

Readme

Keywords

none

Package Sidebar

Install

npm i logic-parsers

Weekly Downloads

1

Version

1.3.0

License

MIT

Unpacked Size

208 kB

Total Files

6

Last publish

Collaborators

  • paoloose