Well, that didn't go to plan.
import { pegex } from 'pegex'
const grammar = `
# A simple grammar for the simple JSON data language.
# See https://github.com/ingydotnet/pegex-json-pm for a Parser implementation
# that uses this grammar.
%grammar json
%version 0.0.1
json: map | seq
node: map | seq | scalar
map:
/ ~ LCURLY ~ /
pair* % / ~ COMMA ~ /
/ ~ RCURLY ~ /
pair:
string
/ ~ COLON ~ /
node
seq:
/ ~ LSQUARE ~ /
node* % / ~ COMMA ~ /
/ ~ RSQUARE ~ /
scalar:
string |
number |
boolean |
null
string: / # XXX Need to code this to spec.
DOUBLE # This works for simple cases,
((: # but doesn't handle all escaping yet.
BACK BACK |
BACK DOUBLE |
[^ DOUBLE BREAK ]
)*)
DOUBLE
/
number: /(
DASH?
(: 0 | [1-9] DIGIT* )
(: DOT DIGIT* )?
(: [eE] [ DASH PLUS ]? DIGIT+ )?
)/
boolean: true | false
true: /true/
false: /false/
null: /null/
`
const parser = pegex(grammar)
console.log(parser.parse(`[ "foo" ]`))
/*
mallet3=; bun src/json.js
381 | return o;
382 | }
383 | c = new o.constructor();
384 | for (k in o) {
385 | v = o[k];
386 | c[k] = clone(v);
^
RangeError: Maximum call stack size exceeded.
at clone (/home/matthewt/.bun/install/cache/pegex@0.1.7@@@1/lib/pegex/pegex/ast.js:386:14)
at clone (/home/matthewt/.bun/install/cache/pegex@0.1.7@@@1/lib/pegex/pegex/ast.js:386:14)
at clone (/home/matthewt/.bun/install/cache/pegex@0.1.7@@@1/lib/pegex/pegex/ast.js:386:14)
at clone (/home/matthewt/.bun/install/cache/pegex@0.1.7@@@1/lib/pegex/pegex/ast.js:386:14)
at clone (/home/matthewt/.bun/install/cache/pegex@0.1.7@@@1/lib/pegex/pegex/ast.js:386:14)
at clone (/home/matthewt/.bun/install/cache/pegex@0.1.7@@@1/lib/pegex/pegex/ast.js:386:14)
at clone (/home/matthewt/.bun/install/cache/pegex@0.1.7@@@1/lib/pegex/pegex/ast.js:386:14)
at clone (/home/matthewt/.bun/install/cache/pegex@0.1.7@@@1/lib/pegex/pegex/ast.js:386:14)
at clone (/home/matthewt/.bun/install/cache/pegex@0.1.7@@@1/lib/pegex/pegex/ast.js:386:14)
at clone (/home/matthewt/.bun/install/cache/pegex@0.1.7@@@1/lib/pegex/pegex/ast.js:386:14)
Bun v1.2.0 (Linux x64)
*/
Well, that didn't go to plan.