Parse trailing commas in lists/dicts

This commit is contained in:
Daniel Watkins committed 2018-08-11 23:37:01 -04:00
1 parent 37c1377fcb
commit 19c9db2375
2 files changed
+14 -2

No files matched your search

+2 -2
View File
@@ -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
View File
@@ -0,0 +1,12 @@
list1 = ["a", "b",]
list2 = [
"a",
"b",
]
assert list1 == list2
dict1 = {"a": "b",}
dict2 = {
"a": "b",
}
#assert dict1 == dict2