lexanth / python-ast

Python (3) Parser for JavaScript/TypeScript (based on antlr4ts)
MIT License
14 stars 5 forks source link

Very Long Chains #1

Closed tomitrescak closed 2 years ago

tomitrescak commented 3 years ago

Hello, thank you for the amazing library!

I'm just curious why the grammar is creating such a long chains of contexts. I have a simple expression 1+1 and this is just a snapshot of the tree (I just visualise children of each context):

image image

You can see how many contexts are built in order to reach the arithmetic expression with many redundant nodes in between. I worked with java-ast and there were no redundant nodes.

lexanth commented 3 years ago

The actual python parsing is all antlr (grammar and library), so it might be better for discussion over there. https://github.com/antlr/grammars-v4/issues/2251 seems to discuss the need to optimise the grammar to avoid this sort of chaining, for example.

genderev commented 2 years ago

How did you even visualize this snapshot? I can't figure out how to use this library.

tomitrescak commented 2 years ago

@genderev I used my own visualisation code for this using vega. This library just builds the AST, nothing else.