Skip to content

Instantly share code, notes, and snippets.

@ear7h
Created December 2, 2020 06:15
Show Gist options
  • Save ear7h/18f34e51619093438fab350d5f50fa34 to your computer and use it in GitHub Desktop.
Save ear7h/18f34e51619093438fab350d5f50fa34 to your computer and use it in GitHub Desktop.
Run a pegjs grammar on an input without compiling it first
#!/usr/bin/env node
const pegjs = require("pegjs");
const fs = require("fs");
const file = fs.readFileSync(process.argv[2], "utf-8");
const parser = pegjs.generate(file);
const input = fs.readFileSync(0, "utf-8");
console.log(parser.parse(input));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment