logic-parsers
v1.3.0
Published
Wasm glue for the logic-parser rust library (personal use)
Downloads
17
Readme
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;