peggyjs / peggy

Peggy: Parser generator for JavaScript
https://peggyjs.org/
MIT License
914 stars 65 forks source link

non-default startRule doesn't work with multiple allowedStartRules #539

Open hildjj opened 1 month ago

hildjj commented 1 month ago

Example:

foo.peggy:

foo = "1"
bar = "2"
bin/peggy.js -S bar --allowed-start-rules foo,bar f.peggy
const {parse} = require('./f.js')
parse("2") // Error, expected "1"

generate-js.js has this:

const startRuleFunction = name(allowedStartRules[0]);

there should be a new option defaultStartRule that gets hooked up in the CLI correctly and ends up in the AST for later use by generate-js.

hildjj commented 1 month ago

Work-around:

bin/peggy.js --allowed-start-rules bar,foo f.peggy

the docs clearly say that -S is only for testing.