-
Notifications
You must be signed in to change notification settings - Fork 418
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
Create an optional argument 'options' in parse() #37
Comments
While probably useful to you. I am not entirely convinced this is needed so much to warrant inclusion into PEG.js. Is there any other parser generator you know about that has this feature? Also, I'd probably have the signature be just |
I like your proposal better. If String, options is the startRule. If an object, it can have a |
I would like to see this feature as described. I am doing color coding with the generated parser, but I do not want to hardcode the logic for this into the grammar. What I am trying to do, is passing the parser a formatter object, which is then called at appropriate times from the parser. In the proposed solution, I could do this then by inserting something like the following in right places: { input.formatter.format("comment", comment); } |
If having a stateful parser is not a concern the same behaviour can be achieved by writing a function in the grammar that is capable to access the parser interface, like that: var thisParser = this;
function resolveSymbol(parser, sym){
return (parser.symbols || {})[sym];
} and then using it in the semantic rules of the grammar itself:
Now you can pass parameters to your grammar setting the 'symbols' proprerty on the parser pegParser.symbols = {x: 5};
pegParser.parse("x"); Here is a complete example: https://gist.github.com/1627855 |
while the proposal of replacing startRule parameter with options as stated above is adopted, it's already possible to make this inside the grammar definition in the starting block code doing something like this with actual 7.0 version:
this seems sufficient for me if stated as a way of doing in the documentation. What do you think of this proposal ? |
It could be useful to pass variables to the
parse()
method to customize the behaviour of the parser on-demand.My proposition is to have the following signature :
parse(input, startRule, options)
, with the following behaviour ;Or something of the like.
Right now, I believe the only way to do so is to have
var options = arguments[2] || {};
, which is not very elegant. You also have to generate the module that way to be able to call parse without the fullparse(input, undefined, options)
;The text was updated successfully, but these errors were encountered: