@choo-choo/parser-python-peg
v0.1.2
Published
Python PEG (pegen dialect) grammar parser for choo-choo.
Maintainers
Readme
@choo-choo/parser-python-peg
Python PEG (pegen dialect) grammar parser for Choo Choo railroad diagrams.
Parses the Python PEG meta-grammar — the dialect used in docs.python.org/3/reference/grammar.html — and returns an ordered list of rules, each with an IR tree ready to render.
This is a different dialect from the peggy parser shipped in @choo-choo/parser-peg. See the spec for the full diff.
Install
npm install @choo-choo/core @choo-choo/parser-python-pegExample
import { render } from "@choo-choo/core";
import { pythonPegParser } from "@choo-choo/parser-python-peg";
const source = `
boolean:
| 'True'
| 'False'
| 'None'
import_from_as_names: ','.import_from_as_name+
`;
const parsed = pythonPegParser.parse(source);
const boolean = parsed.rules.find((r) => r.name === "boolean")!;
const svg = render(boolean.diagram);Learn more
License
MIT
