-
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
null indicates failure - workaround for a grammar that should produce nulls? #17
Comments
I recommend using a special object to represent Example:
Telling the parser what value to use to represent the failure would work, but I don't think the additional complexity is worth it. Exceptions would work too, but they don't have the right semantics here (they are for exceptional circumstances, which failing to parse something inside a backtrcking parser is not). Moreover, I think they would hinder peformance (but this is just a guess, it would have to be implemented and benchamrked to be sure). I'll keep this one open for a while since it bothers me too a bit :-) |
Why not just define a global |
Encounter this one today as well. Also since Should I open a new issue for it? Feel like somewhat related. |
+1 for Not sure about |
Another small reason for using |
I encountered the same problem allowing Couldn't you throw something in the action block to signalize failures or is the performance impact too much? |
This will be resolved as part of #198, closing. |
I have a grammar for a data structure that ideally should include nulls. If the top-level result is null, no problem: the grammar can produce a special object. In that case the function calling the parser can detect the special object and return a null.
However for nulls deeper in the data structure, I'd hate to have to traverse that structure to replace all special objects with nulls. Any ideas?
One thought is to tell the parser what value to use as the failure indicator. Then I can tell the parser to fail when some unique object is returned.
Another thought is to indicate failure by throwing an exception. Or maybe there is an existing workaround I don't know of?
Thanks! PEG.js has saved me a ton of time.
The text was updated successfully, but these errors were encountered: