peggyjs/peggy

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

Closed this issue · 1 comments

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

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