plyplus icon indicating copy to clipboard operation
plyplus copied to clipboard

Too permissive rules for list in Python grammar

Open Smattr opened this issue 9 years ago • 0 comments

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)* ','?)? '\]';

Smattr avatar Apr 12 '15 23:04 Smattr