peggy-tag
Tagged template strings for Peggy grammars
Installation
npm install peggy-tag
Usage
import peggy from "../lib/index.js";
const parse = peggy`foo = $("f" "o"+)`;
console.log(parse("foooo")); // "foooo"
const trace = peggy.withOptions({ trace: true });
const traceParse = trace`num = n:$[0-9]+ { return parseInt(n, 10); }`
console.log(traceParse("123"));
// 1:1-1:1 rule.enter num
// 1:1-1:4 rule.match num
// 123
Notes:
- This currently is only tested on Node 18+, no browser version yet.
- Can't be used with
require
. - This is for non-performance-sensitive code (e.g. prototypes), because the parser with be generated every time the template is evaluated.