For linting Peggy grammars using eslint.
npm install -D @peggyjs/eslint-parser
We'll document this more if anyone else wants to use it.
import { parseForESLint, visitor } from "@peggyjs/eslint-parser";
const parserResults = parseForESLint(text, { filePath: filename });
const v = new visitor.Visitor({
rule(node) {
console.log(node.name.value);
}
});
v.visit(parserResults.ast);
This uses a slightly different grammar than the one built in to Peggy, in order to pull out information about more concrete parts of the grammar like punctuation that don't matter to Peggy semantics.