gazayas / masamune-ast

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

`msmn.pry` #23

Open gazayas opened 1 year ago

gazayas commented 1 year ago

I'd like to have a method in Masamune::AbstractSyntaxTree called pry which will stop at each point in the code where the node matches pry's parameters:

msmn.pry(type: :variables, token: "n")

Ideally I want to show the node class (i.e. - Masamune::AbstractSyntaxTree::VarField), the data from Ripper specifically for that node, and the corresponding Masamune::AbstractSyntaxTree::LexNode.

Then you could press enter to show the next node in the tree until you reach the final node.

gazayas commented 1 year ago

In the pry gem, binding.pry is usually placed somewhere inside the code, but msmn.pry would be placed outside of the code block that we instantiate Masamune::AbstractSyntaxTree.new(code) with. Then we would just call pry afterwards.

So, something like this.

code = <<~CODE
  10.times do |n|
    puts n
  end
CODE

msmn = Masamune::AbstractSyntaxTree.new(code)
msmn.pry(type: :variables, token: "n")
kaspth commented 1 year ago

I'd recommend shifting this to irb instead, since IRB has pretty supplanted pry in terms of features and isn't as needed anymore.