a-recknagel / stenotype

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

Basic Parser #28

Closed maxfischer2781 closed 4 years ago

maxfischer2781 commented 5 years ago

This pull request adds a basic grammar/parser based on pyparsing. The pull request includes:

This is currently a draft to allow discussion of the approach.

maxfischer2781 commented 5 years ago

I've left the parser.py and CLI unchanged for now. The current parse/unparse pair can "only" do a roundtrip, which isn't that useful for the CLI.

I'll add a typing.unparse(:Steno) -> str if time permits. Feel free to decide whether you want to wait for that.

maxfischer2781 commented 5 years ago

Turns out it wasn't quite as much work as expected. CLI now supports steno to typing conversions:

$ stenotype 'A or [1 or 2]'
typing.Union[A, typing.List[typing.Union[typing.Literal[1], typing.Literal[2]]]]
a-recknagel commented 4 years ago

Ok, tests are fine with me now. I tried to reduce the amount of assert statements in every single test function to one, and used pytest.mark.parametrize to feed in the generic test case data. I also moved one folder in between so that the tests mirror the src directory structure. Everything else that came to mind while running the tests and playing around should imo be handled in different PRs, and this one be merged now. Unless there is something that you'd like to change or add.