Merge pull request #605 from RustPython/subscript_list

Add subscript list in grammar.
This commit is contained in:
Windel Bouwman authored and GitHub committed 2019-03-06 17:10:32 +01:00
commit e5ead870bc
1 file changed
+15 -1
+15 -1
View File
@@ -791,10 +791,24 @@ Power: ast::Expression = {
AtomExpr: ast::Expression = {
<e:Atom> => e,
<f:AtomExpr> "(" <a:ArgumentList> ")" => ast::Expression::Call { function: Box::new(f), args: a.0, keywords: a.1 },
<e:AtomExpr> "[" <s:Subscript> "]" => ast::Expression::Subscript { a: Box::new(e), b: Box::new(s) },
<e:AtomExpr> "[" <s:SubscriptList> "]" => ast::Expression::Subscript { a: Box::new(e), b: Box::new(s) },
<e:AtomExpr> "." <n:Identifier> => ast::Expression::Attribute { value: Box::new(e), name: n },
};
SubscriptList: ast::Expression = {
<s1:Subscript> <s2:("," Subscript)*> ","? => {
if s2.is_empty() {
s1
} else {
let mut dims = vec![s1];
for x in s2 {
dims.push(x.1)
}
ast::Expression::Tuple { elements: dims }
}
}
};
Subscript: ast::Expression = {
<e:Test> => e,
<e1:Test?> ":" <e2:Test?> <e3:SliceOp?> => {