tenderlove/rkelly — pull request #23 by nene (2013-06-12 17:50:11+00:00)
Title: Correct begin and end (line+char) positions for each token and node

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:

[[start_line, start_char], [end_line, end_char]]

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.
- With all comments residing in the root SourceElementsNode - all other node types no more need the `@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.