Conversation
This is a new subclass of the Ripper parser. It is based on/extracted from the work done in https://github.com/ruby-syntax-tree/syntax_tree. This subclass is similar to SexpBuilderPP in that it provides individual shapes per production rule from ripper. However, there are a couple of differences: * Tree uses class instances instead of arrays to represent nodes. * Comments are automatically attached to the various nodes when parsing is finished. * A couple of additional nodes are added for clarity (i.e., ArgStar, Not, PinnedBegin, etc.). * Every node has location information attached to it (as opposed to just the scanner event nodes). * There's a standard interface for descending the tree (child_nodes). Additionally, each node has pattern matching (both array and hash patterns) as well as pretty_print defined to make it easier to work with. I think we should ship this with Ruby to make it easier to build tools (like formatters and linters) on top of this structure. It also will make it easier to change the parser in the future (if we ever do) because any tools built on top of these objects will not have to worry about the specific order of the nodes (unlike the SexpBuilderPP version) since everything has a named field.
|
Considering these points:
If we're going to add new nodes for clarity, I think we could also take the liberty to add a common ancestor to all nodes. This common ancestor could hold the Having a common ancestor to all nodes has at least two advantages when using the resulting tree to write tools:
|
|
Awesome work on this + would be great to have something like this as part of ripper. Couple of thoughts:
|
This is a new subclass of the Ripper parser. It is based on/extracted from the work done in https://github.com/ruby-syntax-tree/syntax_tree. This subclass is similar to SexpBuilderPP in that it provides individual shapes per production rule from ripper. However, there are a couple of differences:
Additionally, each node has pattern matching (both array and hash patterns) as well as pretty_print defined to make it easier to work with.
I think we should ship this with Ruby to make it easier to build tools (like formatters and linters) on top of this structure. It also will make it easier to change the parser in the future (if we ever do) because any tools built on top of these objects will not have to worry about the specific order of the nodes (unlike the SexpBuilderPP version) since everything has a named field. Additionally, since everything is written in pure Ruby, it makes it easy for other implementations of Ruby to benefit.