-
Notifications
You must be signed in to change notification settings - Fork 8
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
Allow access to skipped whitespace #47
Comments
From our perspective What we don't really get is your second suggestion: what do you mean by "a collection of all parsed nodes"? It is not a new CST right? |
In addition to the aNode children -> {leftHandNode . operatorNode . rightHandNode}
aNode childrenIncludingSpaces -> {leftHandNode . spacesNode . operatorNode . spacesNode . rightHandNode}
"I still have to figure out whether there should be a spaces node at the first position in that array Instead of getting the skippedSpaces for a specific node, this interface allows for a more "natural" tree traversal. However, it might be very difficult to implement correctly... :) |
Ah alright I see! |
Please have a look / try out the new methods added in 31c8c08. They are a first sketch of how this could work and not all corner cases are covered yet. If this works for you, I'll see to getting it right :) |
Thanks a lot for prototyping this so quickly. In general it works as we have expected it. The prototype is based on the assumption that nodes that are next to each other in the CST are also neighbours in the original string. However we see a problem with rules that contain a grammar := OhmGrammar new: 'OhmNodeTestGrammar {
StartRule = (";" firstRule)+
firstRule = "a"
space += comment
comment = "\"" (~"\"" any)* "\""
}'.
result := (grammar
match: ';a ; "comment" a'
startingFrom: #StartRule) cst. Here are parts of the CST that is produced with the code above: If we want to retrieve the comment before the last result children last children last skippedSpacesNodes your code takes the other We really appreciate your effort! Thanks a lot! |
Ah! Thanks a lot! I suspected something like this but didn't have the time to think this through. I'll look into this case. |
Please have a look at 9b85725 :) Again it is more of a sketch as I currently do not have time to think this trough. The current approach might still miss cases but is easier to reason about (but might take a little longer on the first call due to the construction of the source map). |
When I try to send the message
This produces an error when trying to access the source map (index out of bound). It seems to be related to #43 because there are nodes of optional rules that have an interval outside the interval of method declaration: |
Thanks for the PR! I will look at it Monday. Also: Sorry for not advancing this further. The week was somewhat busy. I am working on #48 currently, which resulted in a major rework of the whitespace skipping and might also help with the Optional problem (all maybe instances of skipped whitespace although the rule actually failed, but the parse succeeded as the rule was optional/negated/lookahead). |
I actually have a solution to this in my local image. The space skipping logic was inconsistent throughout nodes, as I did not completely understand the rule when to do it when I first implemented it. I now adjusted it but I did not manage to adjust all tests accordingly before the exam preparations started. I hope I can attend to it beginning of next week. It should resolve a number of issues... |
That sounds really great! We really appreciate your work for this issue :) |
I uploaded the intermediate state of the work on a new branch called new-whitespace-handling. You can try that one. I would advise loading it into a fresh image though... It works okay in my image so far, but not all tests are green so something is still off. I think I can attend to it Tuesday afternoon. |
In order to support Pretty Printers, the CST should allow access to whitespace. The whitespace does not have to be explicitly materialized in the CST but could also be re-constructed after the fact.
Here are two suggestions:
skippedSpaces
that returns the spaces skipped before the node was applied. There are two options how the spaces could be returned:childrenIncludingSpaces
that returns a collection of all parsed nodes including the space nodes in betweenAny thoughts from your side @Paula-Kli?
The text was updated successfully, but these errors were encountered: