-
Notifications
You must be signed in to change notification settings - Fork 55
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
Missing output for optional nodes #73
Comments
The key thing to remember is that the structure of the output mirrors the
You try to parse this string:
And you get this sequence of elements from the root node of the tree:
This mirrors the structure of the In order to get this output:
You would need a grammar where the
I'm not sure what you mean by "required" here, and the grammar presented after Then you give another version of the
This rule is a sequence of two elements: it requires one
If you look inside the second element here you'll see multiple elements for each
This rule looks to me like the correct grammar, as you seem to want your query |
First of all, thanks for developing this great library! I am prototyping a search grammar in javascript with the hopes of porting it to Java for uses in an android app.
I am building a search grammar that takes the form
expression (operator expression)*
. If I build the grammar using optional repetition, the optional nodes are missing from the output.Example:
peg file
test app.js
If I attempt to parse the following string:
I get the following output using the URL parser sample code:
I expected to get:
If I change the grammar such that all nodes are required I get the expected output.
If I print the entire tree I see that all required nodes are in the tree, but optional nodes are not. Here is an excerpt from an expression node:
You can see that all nodes other than the optional
negation
node are listed. The negation node is parsed as a member of the elements list. This is also true for theexpr_op
nodes. They are only included in the tree if they are required nodes.If I change the grammar to use a different form of repetition I get a third output:
output:
However the
expr_op
nodes are included as nodes in the second blob.It seems like
and
should produce the same output and that the
expr_op
nodes andexpression
nodes should be at the same level in the tree. Your help is greatly appreciated!EDIT: I was hoping the tree object would look something like this:
The text was updated successfully, but these errors were encountered: