-
Notifications
You must be signed in to change notification settings - Fork 419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parse(specific rule) makes no sense! #469
Comments
Ok, I have found that you do that you limit the set of start rules for performance reasons
I offer that you enable full functionality by default and limit the start rules on performance demand. Meantime, I have found a workaround
I argue that generate could produce a number of parser, a parser per every start rule. Edit: Wait, do you advise that I generate a parser for every rule separately? |
@valtih1978 Please tone down your aggressive voice. Just because something isn’t done the way you would do it doesn’t mean there aren’t good reasons for doing it the way it is. The view PEG.js takes is that the whole grammar (or rather the parser generated form it) is the atomic unit, not a rule. The entry point to a parser is its start rule (the first one by default). If you want to have multiple entry points, fine, you just have to explicitly designate them. Think of the parser as an object where each rule is a separate method. A sane advice in OOP is to keep all methods private except those which form the interface to the object. And this is exactly what PEG.js does for parsers. This part of PEG.js philosophy is justified by two things:
Both reasons have their equivalent in the OOP analogy I mentioned. Now, you are right that PEG.js’s approach makes testing slightly harder. In my experience, this is not a big problem. You just need to use test cases that are valid input of some start rule. I was able to test the PEG.js grammar and some other grammars just fine using this approach. As for libraries, I don’t see how the current approach prevents building them. One just needs to be explicit about the “exported” rules. But if building rule libraries is your main use case, you may be better off using some parser combinator-based library, which are naturally better suited to this task than grammar-based parser generators. In any case, I’d not changing the default. As for having a way to easily allow all rules as start rules, see #234. |
I tried to parse with something different than start but it fails with "Can't start parsing from rule myrule" because
Why do you define the grammar but cannot test anything but only one of them? Do you write programs such that only main method can be run in them? What about other procedures? Don't you understand that a grammar is a library, that you may use every parser separately, outside of the scope of the main? I have defined an integer parser somewhere at the bottom of my grammar. Why I cannot use/test it separately, outside of my main program? You say that I am allowed to parse with any start rule but limit their name to 'start'. What the craze? Why
indexOf('start')
, why notstartRule == 'start'
? That would give more freedom and understanding to the user!The text was updated successfully, but these errors were encountered: