Shopify / tree_stand

A high-level Ruby wrapper for tree-sitter bindings.
https://rubygems.org/gems/tree_stand
MIT License
11 stars 3 forks source link

Support for `pp node` (pretty-printing) #16

Closed DerekStride closed 1 year ago

DerekStride commented 1 year ago

What

To define a customized pretty printing function for your classes, redefine method #pretty_print(pp) in the class. -- Output Customization (in Ruby Docs)

This PR adds the #pretty_print(pp) method powered by an underlying Utils::Printer class to encapsulate the printing logic.

Other Notes

There's a second commit adding some improvements to bin/console into the PR. It runs TreeStand.configure and creates a parser & a simple tree to facilitate quick experimentation.

phsurette commented 1 year ago

It took me a while to figure out that you can use PP.pp(node) to quickly inspect a node. Once you know that this is very easy to use! Might be a good thing to add to the readme or a walkthrough.

DerekStride commented 1 year ago

I added some documentation before shipping, it's live here: https://shopify.github.io/tree_stand/TreeStand/Utils/Printer.html