gazayas / masamune-ast

A covenience wrapper around Prism, a Ruby source code parser
MIT License
13 stars 1 forks source link

Define position and token data as Hashes #17

Closed gazayas closed 1 year ago

gazayas commented 1 year ago

Before, running Masamune::AbstractSyntaxTree.new("x = 1").variables would return this:

[[[1, 0], "x"]]

This isn't very descriptive, so I decided to change this to the following:

[{position: [1, 0], token: "x"}]

Since it's a hash inside an array it's easier to look it, and it should be easier to read since each piece of data has a key attached to it.

Why I'm not returning Masamune::AbstractSyntaxTree::DataNode objects

I want to add an option to return Masamune::AbstractSyntaxTree::DataNode objects when performing a search like msmn.variables, but since these objects tend to have a lot of information, I thought it would be beneficial to just return a list of hashes. I have made a note here to implement this though in case we want it in the future.