Since nodes start with a type (a Symbol that represents what operation the node is performing), I wanted to expose that layer of abstraction explicitly in the code instead of just writing what I had before when grabbing the appropriate node class:
class_name = "Masamune::AbstractSyntaxTree::#{tree_node.first.to_s.camelize}"
klass = class_name.constantize
msmn_node = klass.new(tree_node, self.__id__)
For whoever's reading the code, this doesn't explicitly say what tree_node.first is, but with this new patch we show them that the type is originally defined as a symbol, we show them that this value represents a type as can be seen in the argument for the get_node_class method, and we find the class via that symbol. I think this will make the code easier to read, especially if developers want to check their results against Ripper.sexp's output itself.
The output from
Ripper.sexp
for this code:Since nodes start with a type (a Symbol that represents what operation the node is performing), I wanted to expose that layer of abstraction explicitly in the code instead of just writing what I had before when grabbing the appropriate node class:
For whoever's reading the code, this doesn't explicitly say what
tree_node.first
is, but with this new patch we show them that the type is originally defined as a symbol, we show them that this value represents atype
as can be seen in the argument for theget_node_class
method, and we find the class via that symbol. I think this will make the code easier to read, especially if developers want to check their results againstRipper.sexp
's output itself.