@@ -7,6 +7,7 @@ use std::iter::FromIterator;
77
88use crate::ast;
99use crate::fstring::parse_located_fstring;
10+ use crate::function::parse_args;
1011use crate::error::LexicalError;
1112use crate::lexer;
1213use crate::location;
@@ -580,7 +581,7 @@ KwargParameter<ArgType>: Option<ast::Parameter> = {
580581ClassDef: ast::Statement = {
581582 <decorator_list:Decorator*> <location:@L> "class" <name:Identifier> <a:("(" ArgumentList ")")?> ":" <body:Suite> => {
582583 let (bases, keywords) = match a {
583- Some((_, args , _)) => args,
584+ Some((_, arg , _)) => (arg. args, arg.keywords) ,
584585 None => (vec![], vec![]),
585586 };
586587 ast::Statement {
@@ -616,14 +617,13 @@ Path: ast::Expression = {
616617Decorator: ast::Expression = {
617618 "@" <p:Path> <a: (@L "(" ArgumentList ")")?> "\n" => {
618619 match a {
619- Some((location, _, args, _)) => {
620- let (args, keywords) = args;
620+ Some((location, _, arg, _)) => {
621621 ast::Expression {
622622 location,
623623 node: ast::ExpressionType::Call {
624624 function: Box::new(p),
625- args,
626- keywords,
625+ args: arg.args ,
626+ keywords: arg.keywords ,
627627 }
628628 }
629629 },
@@ -633,7 +633,7 @@ Decorator: ast::Expression = {
633633};
634634
635635YieldExpr: ast::Expression = {
636- <location:@L> "yield" <value:TestList?> => ast::Expression {
636+ <location:@L> "yield" <value:TestList?> => ast::Expression {
637637 location,
638638 node: ast::ExpressionType::Yield { value: value.map(Box::new) }
639639 },
@@ -847,10 +847,9 @@ AtomExpr: ast::Expression = {
847847AtomExpr2: ast::Expression = {
848848 Atom,
849849 <f:AtomExpr2> <location:@L> "(" <a:ArgumentList> ")" => {
850- let (args, keywords) = a;
851850 ast::Expression {
852851 location,
853- node: ast::ExpressionType::Call { function: Box::new(f), args, keywords }
852+ node: ast::ExpressionType::Call { function: Box::new(f), args: a.args, keywords: a. keywords }
854853 }
855854 },
856855 <e:AtomExpr2> <location:@L> "[" <s:SubscriptList> "]" => ast::Expression {
@@ -1060,31 +1059,10 @@ SingleForComprehension: ast::Comprehension = {
10601059ExpressionNoCond: ast::Expression = OrTest;
10611060ComprehensionIf: ast::Expression = "if" <c:ExpressionNoCond> => c;
10621061
1063- ArgumentList: (Vec<ast::Expression>, Vec<ast::Keyword>) = {
1064- <e: Comma<FunctionArgument>> => {
1065- let mut args = vec![];
1066- let mut keywords = vec![];
1067- for (name, value) in e {
1068- match name {
1069- Some(n) => {
1070- keywords.push(ast::Keyword { name: n, value: value });
1071- },
1072- None => {
1073- // Allow starred args after keyword arguments.
1074- let is_starred = if let ast::ExpressionType::Starred { .. } = &value.node {
1075- true
1076- } else {
1077- false
1078- };
1079-
1080- if keywords.len() > 0 && !is_starred {
1081- panic!("positional argument follows keyword argument {:?}", keywords);
1082- };
1083- args.push(value);
1084- },
1085- }
1086- }
1087- (args, keywords)
1062+ ArgumentList: ast::ArgumentList = {
1063+ <e: Comma<FunctionArgument>> =>? {
1064+ let arg_list = parse_args(e)?;
1065+ Ok(arg_list)
10881066 }
10891067};
10901068
0 commit comments