antlr / antlr4

ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files.
http://antlr.org
BSD 3-Clause "New" or "Revised" License
17.12k stars 3.28k forks source link

pygrun -tree prettyprint using nltk #3222

Open SkittlePox opened 3 years ago

SkittlePox commented 3 years ago

Looks like the Natural Language Toolkit can pretty-print the AST that comes out of pygrun -t:

from nltk import Tree
tree = Tree.fromstring('...')
tree.pretty_print()

>>>
         program                                
    ________|_________                           
   |                 dec                        
   |                  |                          
   |              predicate                     
   |         _________|________________          
   |        |         |      |  boolean_expressi
   |        |         |      |         on       
   |        |         |      |         |         
newLine Predicate   hello    :=       True  

It would be trivial to add this to the existing pygrun python file (and I would happily do it), but is importing outside repos for tiny amounts of functionality like this frowned upon?

ericvergnaud commented 3 years ago

Hi, since this is only useful during dev I would not want to include it in the runtime itself. But I would be ok with a self documented auxiliary file.