@@ -1805,13 +1805,9 @@ def classdef__30(self, class_loc, name_tok, arglist_opt, colon_loc, body):
1805
1805
name_loc = name_tok .loc , colon_loc = colon_loc ,
1806
1806
loc = class_loc .join (body [- 1 ].loc ))
1807
1807
1808
- @action (Rule ("argument" ))
1809
- def arglist_1 (self , arg ):
1810
- return [arg ], self ._empty_arglist ()
1811
-
1812
1808
@action (Seq (Loc ("*" ), Rule ("test" ), Star (SeqN (1 , Tok ("," ), Rule ("argument" ))),
1813
1809
Opt (Seq (Tok ("," ), Loc ("**" ), Rule ("test" )))))
1814
- def arglist_2 (self , star_loc , stararg , postargs , kwarg_opt ):
1810
+ def arglist_1 (self , star_loc , stararg , postargs , kwarg_opt ):
1815
1811
dstar_loc = kwarg = None
1816
1812
if kwarg_opt :
1817
1813
_ , dstar_loc , kwarg = kwarg_opt
@@ -1828,31 +1824,32 @@ def arglist_2(self, star_loc, stararg, postargs, kwarg_opt):
1828
1824
star_loc = star_loc , dstar_loc = dstar_loc , loc = None )
1829
1825
1830
1826
@action (Seq (Loc ("**" ), Rule ("test" )))
1831
- def arglist_3 (self , dstar_loc , kwarg ):
1827
+ def arglist_2 (self , dstar_loc , kwarg ):
1832
1828
return [], \
1833
1829
ast .Call (args = [], keywords = [], starargs = None , kwargs = kwarg ,
1834
1830
star_loc = None , dstar_loc = dstar_loc , loc = None )
1835
1831
1836
- @action (SeqN (0 , Rule ("argument" ), Tok ("," )))
1837
- def arglist_4 (self , arg ):
1838
- return [], ([arg ], self ._empty_arglist ())
1839
-
1840
- @action (Alt (Seq (Star (SeqN (0 , Rule ("argument" ), Tok ("," ))),
1841
- Alt (arglist_1 , arglist_2 , arglist_3 )),
1842
- arglist_4 ))
1843
- def arglist (self , pre_args , rest ):
1844
- # Python's grammar is very awkwardly formulated here in a way
1845
- # that is not easily amenable to our combinator approach.
1846
- # Thus it is changed to the equivalent:
1847
- #
1848
- # arglist: (argument ',')* ( argument | ... ) | argument ','
1849
- #
1832
+ @action (Seq (Rule ("argument" ),
1833
+ Alt (SeqN (1 , Tok ("," ), Alt (Rule ("arglist_1" ),
1834
+ Rule ("arglist_2" ),
1835
+ Rule ("arglist_3" ),
1836
+ Eps ())),
1837
+ Eps ())))
1838
+ def arglist_3 (self , arg , cont ):
1839
+ if cont is None :
1840
+ return [arg ], self ._empty_arglist ()
1841
+ else :
1842
+ args , rest = cont
1843
+ return [arg ] + args , rest
1844
+
1845
+ @action (Alt (Rule ("arglist_1" ),
1846
+ Rule ("arglist_2" ),
1847
+ Rule ("arglist_3" )))
1848
+ def arglist (self , args , call ):
1850
1849
"""arglist: (argument ',')* (argument [','] |
1851
1850
'*' test (',' argument)* [',' '**' test] |
1852
1851
'**' test)"""
1853
- post_args , call = rest
1854
-
1855
- for arg in pre_args + post_args :
1852
+ for arg in args :
1856
1853
if isinstance (arg , ast .keyword ):
1857
1854
call .keywords .append (arg )
1858
1855
elif len (call .keywords ) > 0 :
0 commit comments