peggyjs / peggy

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

Allow use of an empty array as default value in allowedStartRules option #493

Closed XenoS-ITA closed 3 weeks ago

XenoS-ITA commented 4 months ago

How the feature should work

When an empty or null array is passed peggy should take the default value, which is the first rule. Right now if you define allowedStartRules there is no method to use the first rule.

Use case behind it

In the following code, if the file is a library, all rules should be added as start instead if it is not the first rule should be taken

const output = peggy.generate(fileContent, {
    format: "commonjs", 
    output: "source", 
    allowedStartRules: isLibrary ? ["*"] : []
})

Even some kind of ENUM might be fine

hildjj commented 3 weeks ago

I'm making it so that null, undefined, and [] all get the default start rule.