peggyjs / peggy

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

Proposal to rename `grammarSource` option in parse method to `source` #515

Open skoji opened 2 months ago

skoji commented 2 months ago

I am using the Peggy parser generator library for JavaScript, which has been instrumental in handling complex parsing tasks. However, I have noticed a potentially confusing aspect regarding the parse method.

Currently, the parse method accepts an option named grammarSource. The name suggests that you should use this parameter to specify the name of grammar rules. However, the parameter means the name of the text that the parser is supposed to parse, not the grammar rules.

The name grammarSource could be misleading, so I propose renaming it to source. This change would make it more straightforward that the option is meant for the input text to be parsed rather than the source of the grammar rules.

hildjj commented 2 months ago

Some issues:

I more or less agree with you that source would be better, but I think it's too late to make the switch. What we could do is improve the documentation to make it more clear that this is the source that the grammar is operating on, not the source for the grammar.

Let's leave this issue open for suggestions for doc improvements.