we-like-parsers / pegen

PEG parser generator for Python
https://we-like-parsers.github.io/pegen/
MIT License
155 stars 33 forks source link

Generalize annotation support with actions #5

Closed isidentical closed 3 years ago

isidentical commented 3 years ago

Currently for annotations we can only use either a normal name (like expr) or a name followed by star (expr_ty*), though at least for python, type annotations are a bit more broad. Some examples;

start[ast.mod]: statements
strings[List[str]]: STRING+

These are currently unsupported, so what this PR does is actually unifies the annotation syntax with the mini-action grammar. And opens up the possibility of the using any sort of expression as types (also includes a little bugfix that allows you to create empty dictionary on the action part)

gvanrossum commented 3 years ago

Can you leave a comment explaining why you want this?

isidentical commented 3 years ago

Uups, I thought I added it. Should be present in the description @gvanrossum

gvanrossum commented 3 years ago

OK, got it. LGTM.

pablogsal commented 3 years ago

@isidentical Could you add some tests to cover this?

pablogsal commented 3 years ago

Thanks for the PR @isidentical :tada: