Correct begin and end (line+char) positions for each token and node #23
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related to the issue I just raised: #22
I replaced the rudimentary
@line
field in Token and Node classes with@range
field that contains the following 2D array:Unlike the old implementation, all nodes now have this information. And I've kept the #line accessor for backwards compatibility.
Also, I eliminated the whole comments-to-syntax-nodes mapping. Placing the array of all comments into the root node.
There are things to improve here:
Maybe the 2D array should be replaced with a hash or object, so it would be a bit more readable. e.g.{:start => {:line => 3, :char => 8}, :end => {:line => 3, :char => 10}}
Instead of line+character based ranges we could provide a simple index based ranges. Some tools might prefer one way, others a different way. So the best might be to support both.@comments
field. So maybe it would be better to wrap everything inside a special ProgramNode that contains this@comments
field. Or not return the comments at all, instead providing RKelly::Parser#comments accessor to access the comments list if needed.All this aside, I think it's an improvement over the current implementation which is simply broken.