a-recknagel / stenotype

Support for shorthand type annotations.
MIT License
3 stars 2 forks source link

[MISC]: Analyze railroad diagram of stenotype's grammar #35

Open a-recknagel opened 4 years ago

a-recknagel commented 4 years ago

A while back, I tried to gain an in-depth understanding of what exactly happens in backend/grammar.py, but never felt like I really got the hang of it. Since pyparsing now offers railroad diagrams, I thought I'd try again. From pyparsing3.0.0a2 onward (with the [diagrams] extension installed), the following can be run to generate stenotype's grammar railroad:

>>> from stenotype.backend.grammar import TYPE
>>> from pyparsing.diagram import to_railroad, railroad_to_html
>>> with open('output.html', 'w') as fp:
...    railroad = to_railroad(TYPE)
...    fp.write(railroad_to_html(railroad))
...  

Which should get us the following:

output

This issue can be used to discuss the current shape of the grammar.


Ultimately, it might be nice to extend the current grammar documentation with this graph (or partial reproductions thereof).

a-recknagel commented 4 years ago

Bearing in mind that I have not much of a clue, a couple of things caught my interest:

pinging @maxfischer2781, in case this is interesting for you.

maxfischer2781 commented 4 years ago

That's both nice and kind of embarrassing. Looks like re-organising could help both the parser and humans.

The nodes '[' TYPE ']' and similar are explicitly named as such. This renders better in error messages.