diff options
author | Robert Collins <rbtcollins@hp.com> | 2015-08-11 20:00:06 (GMT) |
---|---|---|
committer | Robert Collins <rbtcollins@hp.com> | 2015-08-11 20:00:06 (GMT) |
commit | df395991f6341be037a5c6df9b14d924d5ac9e95 (patch) | |
tree | 5b0bf65fee4d6b2fc5b8f69cacc50a4bddb6d3f0 /Python | |
parent | 5b9cd7fa2e4b73bf97a1b28c3f3a7b15c9302941 (diff) | |
download | cpython-df395991f6341be037a5c6df9b14d924d5ac9e95.zip cpython-df395991f6341be037a5c6df9b14d924d5ac9e95.tar.gz cpython-df395991f6341be037a5c6df9b14d924d5ac9e95.tar.bz2 |
Issue #9232: Support trailing commas in function declarations.
For example, "def f(*, a = 3,): pass" is now legal.
Patch from Mark Dickinson.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/ast.c | 23 | ||||
-rw-r--r-- | Python/graminit.c | 106 |
2 files changed, 74 insertions, 55 deletions
diff --git a/Python/ast.c b/Python/ast.c index b572088..c1c3907 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -1260,16 +1260,20 @@ ast_for_arguments(struct compiling *c, const node *n) and varargslist (lambda definition). parameters: '(' [typedargslist] ')' - typedargslist: ((tfpdef ['=' test] ',')* - ('*' [tfpdef] (',' tfpdef ['=' test])* [',' '**' tfpdef] - | '**' tfpdef) - | tfpdef ['=' test] (',' tfpdef ['=' test])* [',']) + typedargslist: (tfpdef ['=' test] (',' tfpdef ['=' test])* [',' [ + '*' [tfpdef] (',' tfpdef ['=' test])* [',' ['**' tfpdef [',']]] + | '**' tfpdef [',']]] + | '*' [tfpdef] (',' tfpdef ['=' test])* [',' ['**' tfpdef [',']]] + | '**' tfpdef [',']) tfpdef: NAME [':' test] - varargslist: ((vfpdef ['=' test] ',')* - ('*' [vfpdef] (',' vfpdef ['=' test])* [',' '**' vfpdef] - | '**' vfpdef) - | vfpdef ['=' test] (',' vfpdef ['=' test])* [',']) + varargslist: (vfpdef ['=' test] (',' vfpdef ['=' test])* [',' [ + '*' [vfpdef] (',' vfpdef ['=' test])* [',' ['**' vfpdef [',']]] + | '**' vfpdef [',']]] + | '*' [vfpdef] (',' vfpdef ['=' test])* [',' ['**' vfpdef [',']]] + | '**' vfpdef [','] + ) vfpdef: NAME + */ int i, j, k, nposargs = 0, nkwonlyargs = 0; int nposdefaults = 0, found_default = 0; @@ -1371,7 +1375,8 @@ ast_for_arguments(struct compiling *c, const node *n) i += 2; /* the name and the comma */ break; case STAR: - if (i+1 >= NCH(n)) { + if (i+1 >= NCH(n) || + (i+2 == NCH(n) && TYPE(CHILD(n, i+1)) == COMMA)) { ast_error(c, CHILD(n, i), "named arguments must follow bare *"); return NULL; diff --git a/Python/graminit.c b/Python/graminit.c index 8212b2a..354dc12 100644 --- a/Python/graminit.c +++ b/Python/graminit.c @@ -204,11 +204,13 @@ static arc arcs_9_6[2] = { {32, 7}, {0, 6}, }; -static arc arcs_9_7[2] = { +static arc arcs_9_7[3] = { {30, 12}, {34, 3}, + {0, 7}, }; -static arc arcs_9_8[1] = { +static arc arcs_9_8[2] = { + {32, 13}, {0, 8}, }; static arc arcs_9_9[2] = { @@ -221,35 +223,39 @@ static arc arcs_9_10[3] = { {0, 10}, }; static arc arcs_9_11[3] = { - {30, 13}, - {32, 14}, + {30, 14}, + {32, 15}, {0, 11}, }; static arc arcs_9_12[3] = { {32, 7}, - {31, 15}, + {31, 16}, {0, 12}, }; -static arc arcs_9_13[2] = { - {32, 14}, +static arc arcs_9_13[1] = { {0, 13}, }; static arc arcs_9_14[2] = { - {30, 16}, + {32, 15}, + {0, 14}, +}; +static arc arcs_9_15[3] = { + {30, 17}, {34, 3}, + {0, 15}, }; -static arc arcs_9_15[1] = { +static arc arcs_9_16[1] = { {26, 6}, }; -static arc arcs_9_16[3] = { - {32, 14}, - {31, 17}, - {0, 16}, +static arc arcs_9_17[3] = { + {32, 15}, + {31, 18}, + {0, 17}, }; -static arc arcs_9_17[1] = { - {26, 13}, +static arc arcs_9_18[1] = { + {26, 14}, }; -static state states_9[18] = { +static state states_9[19] = { {3, arcs_9_0}, {3, arcs_9_1}, {3, arcs_9_2}, @@ -257,17 +263,18 @@ static state states_9[18] = { {1, arcs_9_4}, {4, arcs_9_5}, {2, arcs_9_6}, - {2, arcs_9_7}, - {1, arcs_9_8}, + {3, arcs_9_7}, + {2, arcs_9_8}, {2, arcs_9_9}, {3, arcs_9_10}, {3, arcs_9_11}, {3, arcs_9_12}, - {2, arcs_9_13}, + {1, arcs_9_13}, {2, arcs_9_14}, - {1, arcs_9_15}, - {3, arcs_9_16}, - {1, arcs_9_17}, + {3, arcs_9_15}, + {1, arcs_9_16}, + {3, arcs_9_17}, + {1, arcs_9_18}, }; static arc arcs_10_0[1] = { {23, 1}, @@ -319,11 +326,13 @@ static arc arcs_11_6[2] = { {32, 7}, {0, 6}, }; -static arc arcs_11_7[2] = { +static arc arcs_11_7[3] = { {36, 12}, {34, 3}, + {0, 7}, }; -static arc arcs_11_8[1] = { +static arc arcs_11_8[2] = { + {32, 13}, {0, 8}, }; static arc arcs_11_9[2] = { @@ -336,35 +345,39 @@ static arc arcs_11_10[3] = { {0, 10}, }; static arc arcs_11_11[3] = { - {36, 13}, - {32, 14}, + {36, 14}, + {32, 15}, {0, 11}, }; static arc arcs_11_12[3] = { {32, 7}, - {31, 15}, + {31, 16}, {0, 12}, }; -static arc arcs_11_13[2] = { - {32, 14}, +static arc arcs_11_13[1] = { {0, 13}, }; static arc arcs_11_14[2] = { - {36, 16}, + {32, 15}, + {0, 14}, +}; +static arc arcs_11_15[3] = { + {36, 17}, {34, 3}, + {0, 15}, }; -static arc arcs_11_15[1] = { +static arc arcs_11_16[1] = { {26, 6}, }; -static arc arcs_11_16[3] = { - {32, 14}, - {31, 17}, - {0, 16}, +static arc arcs_11_17[3] = { + {32, 15}, + {31, 18}, + {0, 17}, }; -static arc arcs_11_17[1] = { - {26, 13}, +static arc arcs_11_18[1] = { + {26, 14}, }; -static state states_11[18] = { +static state states_11[19] = { {3, arcs_11_0}, {3, arcs_11_1}, {3, arcs_11_2}, @@ -372,17 +385,18 @@ static state states_11[18] = { {1, arcs_11_4}, {4, arcs_11_5}, {2, arcs_11_6}, - {2, arcs_11_7}, - {1, arcs_11_8}, + {3, arcs_11_7}, + {2, arcs_11_8}, {2, arcs_11_9}, {3, arcs_11_10}, {3, arcs_11_11}, {3, arcs_11_12}, - {2, arcs_11_13}, + {1, arcs_11_13}, {2, arcs_11_14}, - {1, arcs_11_15}, - {3, arcs_11_16}, - {1, arcs_11_17}, + {3, arcs_11_15}, + {1, arcs_11_16}, + {3, arcs_11_17}, + {1, arcs_11_18}, }; static arc arcs_12_0[1] = { {23, 1}, @@ -1879,11 +1893,11 @@ static dfa dfas[85] = { "\000\000\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {264, "parameters", 0, 4, states_8, "\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {265, "typedargslist", 0, 18, states_9, + {265, "typedargslist", 0, 19, states_9, "\000\000\200\000\006\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {266, "tfpdef", 0, 4, states_10, "\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {267, "varargslist", 0, 18, states_11, + {267, "varargslist", 0, 19, states_11, "\000\000\200\000\006\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {268, "vfpdef", 0, 2, states_12, "\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, |