plyplus
plyplus copied to clipboard
Too permissive rules for list in Python grammar
In the Python grammar (plyplus/test/python.g) there are the following rules for lists:
list : LBRACK (list_inner|comprehension)? RBRACK ;
...
list_inner : expr | expr COMMA (expr (COMMA)? )* ;
It seems to me this permits items that are not separated by commas. E.g. [1, 2 3]
, which does not seem to be a legal Python list. Is it intentional that the grammar matches a wider set than just legal lists?
This only occurred to me because I was writing a plyplus grammar that needed support for something similar to Python lists and my own rule does not look like this. It instead reads:
list: '\[' (item (',' item)* ','?)? '\]';