mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-09 22:49:57 +09:00
Merge pull request #58 from OddBloke/trailing_commas
Parse trailing commas in lists/dicts
This commit is contained in:
@@ -336,7 +336,7 @@ Atom: ast::Expression = {
|
||||
<s:String> => ast::Expression::String { value: s },
|
||||
<n:Number> => ast::Expression::Number { value: n },
|
||||
<i:Identifier> => ast::Expression::Identifier { name: i },
|
||||
"[" <e:TestList?> "]" => {
|
||||
"[" <e:TestList?> <_trailing_comma:","?> "]" => {
|
||||
match e {
|
||||
None => ast::Expression::List { elements: Vec::new() },
|
||||
Some(elements) => ast::Expression::List { elements },
|
||||
@@ -362,7 +362,7 @@ Atom: ast::Expression = {
|
||||
};
|
||||
|
||||
TestDict: Vec<(ast::Expression, ast::Expression)> = {
|
||||
<e1:DictEntry> <e2:("," DictEntry)*> => {
|
||||
<e1:DictEntry> <e2:("," DictEntry)*> <_trailing_comma:","?> => {
|
||||
let mut d = vec![e1];
|
||||
d.extend(e2.into_iter().map(|x| x.1));
|
||||
d
|
||||
|
||||
12
tests/snippets/commas.py
Normal file
12
tests/snippets/commas.py
Normal file
@@ -0,0 +1,12 @@
|
||||
list1 = ["a", "b",]
|
||||
list2 = [
|
||||
"a",
|
||||
"b",
|
||||
]
|
||||
assert list1 == list2
|
||||
|
||||
dict1 = {"a": "b",}
|
||||
dict2 = {
|
||||
"a": "b",
|
||||
}
|
||||
#assert dict1 == dict2
|
||||
Reference in New Issue
Block a user