This post originated from an RSS feed registered with Agile Buzz
by Marty Andrews.
Original Post: Line numbers with ParseTree
Feed Title: Ramblings of the Wry Tradesman
Feed URL: http://www.wrytradesman.com/blog/index.rdf
Feed Description: Marty Andrews talks about the day to day issues he faces as an agile coach on large enterprise applications in Australia.
I reluctantly moved Roodi over to ParseTree recently because I figured that would make it more accessible to people. My reluctance came from the fact that I was going to lose the line number support the I had in JRuby. Happy days - it turns out I was wrong!
The following bit of code sets up ParseTree so you can parse some code:
parse_tree = ParseTree.new
tree = parse_tree.parse_tree_for_string(ruby_code_as_text, filename)
It turns out that one very small tweak will give me line number support:
parse_tree = ParseTree.new(true)
tree = parse_tree.parse_tree_for_string(ruby_code_as_text, filename)
The addition of that boolean means that ParseTree will now include newline nodes in the tree structure that it gives me. Every newline node includes the line number and the name of the file that it came from. That made the output from Roodi much more useful.