[Python-Dev] funcdef grammar production (original) (raw)
Jewett, Jim J jim.jewett at eds.com
Mon Mar 15 14:23:04 EST 2004
- Previous message: [Python-Dev] pdb enhancements (patch 896011, bugs 751124,875404)
- Next message: [Python-Dev] funcdef grammar production
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
PEP 318 is likely to change the BNF productions for funcdef, so I was taking a look at what is there right now.
funcdef ::= "def" funcname "(" [parameter_list] ")" ":" suite parameter_list ::= (defparameter ",")* ("" identifier [, "" identifier] | "" identifier | defparameter [","]) defparameter ::= parameter ["=" expression] sublist ::= parameter ("," parameter) [","] parameter ::= identifier | "(" sublist ")" funcname ::= identifier
But the text points out that no purely positional (without a default value) arguments can occur after any keyword arguments. Is there a reason not to include this in the BNF?
(Assuming the other productions are unchanged,) this seems to work:
parameter_list ::= starparameter | defparameter ("," defparameter)* ["," [starparameter]] | parameter ("," parameter)* ("," defparameter)* ["," [starparameter]]
starparameter ::= "*" identifier [, "" identifier] | "" identifier
defparameter ::= parameter "=" expression
starparameter was separated out because a trailing comma is permitted after a positional or default parameter, but not after *args or **kwargs.
Is there some technical reason not to do this? For instance, is the doco autogenerated from the actual code? Is it somehow cheaper to check for an optional first parameter than for three possibilities?
-jJ
- Previous message: [Python-Dev] pdb enhancements (patch 896011, bugs 751124,875404)
- Next message: [Python-Dev] funcdef grammar production
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]