@@ -84,27 +84,27 @@ func setCtx(exprs []ast.Expr, ctx ast.ExprContext) {
84
84
%type <obj> strings
85
85
%type <mod> inputs file_input single_input eval_input
86
86
%type <stmts> simple_stmt stmt nl_or_stmt small_stmts stmts suite optional_else
87
- %type <stmt> compound_stmt small_stmt expr_stmt del_stmt pass_stmt flow_stmt import_stmt global_stmt nonlocal_stmt assert_stmt break_stmt continue_stmt return_stmt raise_stmt yield_stmt import_name import_from while_stmt if_stmt for_stmt try_stmt with_stmt
87
+ %type <stmt> compound_stmt small_stmt expr_stmt del_stmt pass_stmt flow_stmt import_stmt global_stmt nonlocal_stmt assert_stmt break_stmt continue_stmt return_stmt raise_stmt yield_stmt import_name import_from while_stmt if_stmt for_stmt try_stmt with_stmt funcdef classdef classdef_or_funcdef decorated
88
88
%type <op> augassign
89
- %type <expr> expr_or_star_expr expr star_expr xor_expr and_expr shift_expr arith_expr term factor power trailer atom test_or_star_expr test not_test lambdef test_nocond lambdef_nocond or_test and_test comparison testlist testlist_star_expr yield_expr_or_testlist yield_expr yield_expr_or_testlist_star_expr dictorsetmaker sliceop arglist except_clause
90
- %type <exprs> exprlist testlistraw comp_if comp_iter expr_or_star_exprs test_or_star_exprs tests test_colon_tests trailers equals_yield_expr_or_testlist_star_expr
89
+ %type <expr> expr_or_star_expr expr star_expr xor_expr and_expr shift_expr arith_expr term factor power trailer atom test_or_star_expr test not_test lambdef test_nocond lambdef_nocond or_test and_test comparison testlist testlist_star_expr yield_expr_or_testlist yield_expr yield_expr_or_testlist_star_expr dictorsetmaker sliceop arglist except_clause optional_return_type decorator
90
+ %type <exprs> exprlist testlistraw comp_if comp_iter expr_or_star_exprs test_or_star_exprs tests test_colon_tests trailers equals_yield_expr_or_testlist_star_expr decorators
91
91
%type <cmpop> comp_op
92
92
%type <comma> optional_comma
93
93
%type <comprehensions> comp_for
94
94
%type <slice> subscript subscriptlist subscripts
95
95
%type <call> argument arguments optional_arguments arguments2
96
96
%type <level> dot dots
97
- %type <str> dotted_name from_arg vfpdef
97
+ %type <str> dotted_name from_arg
98
98
%type <identifiers> names
99
99
%type <alias> dotted_as_name import_as_name
100
100
%type <aliases> dotted_as_names import_as_names import_from_arg
101
101
%type <ifstmt> elifs
102
102
%type <exchandlers> except_clauses
103
103
%type <withitem> with_item
104
104
%type <withitems> with_items
105
- %type <arg> vfpdeftest optional_vfpdef
106
- %type <args> vfpdeftests vfpdeftests1
107
- %type <arguments> varargslist
105
+ %type <arg> vfpdeftest vfpdef optional_vfpdef tfpdeftest tfpdef optional_tfpdef
106
+ %type <args> vfpdeftests vfpdeftests1 tfpdeftests tfpdeftests1
107
+ %type <arguments> varargslist parameters optional_typedargslist typedargslist
108
108
109
109
%token NEWLINE
110
110
%token ENDMARKER
@@ -285,141 +285,172 @@ decorator:
285
285
decorators :
286
286
decorator
287
287
{
288
- // FIXME
288
+ $$ = nil
289
+ $$ = append($$ , $1 )
289
290
}
290
291
| decorators decorator
291
292
{
292
- // FIXME
293
+ $$ = append( $$ , $2 )
293
294
}
294
295
295
296
classdef_or_funcdef :
296
297
classdef
297
298
{
298
- // FIXME
299
+ $$ = $1
299
300
}
300
301
| funcdef
301
302
{
302
- // FIXME
303
+ $$ = $1
303
304
}
304
305
305
306
decorated :
306
307
decorators classdef_or_funcdef
307
308
{
308
- // FIXME
309
+ switch x := ($2 ).(type) {
310
+ case *ast.ClassDef:
311
+ x.DecoratorList = $1
312
+ $$ = x
313
+ case *ast.FunctionDef:
314
+ x.DecoratorList = $1
315
+ $$ = x
316
+ default :
317
+ panic (" bad type for decorated" )
318
+ }
309
319
}
310
320
311
321
optional_return_type:
312
322
{
313
- // FIXME
323
+ $$ = nil
314
324
}
315
325
| MINUSGT test
316
326
{
317
- // FIXME
327
+ $$ = $2
318
328
}
319
329
320
330
funcdef:
321
331
DEF NAME parameters optional_return_type ' :' suite
322
332
{
323
- // FIXME
333
+ $$ = &ast.FunctionDef{StmtBase: ast.StmtBase{$<pos>$}, Name: ast.Identifier( $2 ), Args: $3 , Body: $6 , Returns: $4 }
324
334
}
325
335
326
336
parameters:
327
337
' (' optional_typedargslist ' )'
328
338
{
329
- // FIXME
339
+ $$ = $2
330
340
}
331
341
332
342
optional_typedargslist:
333
343
{
334
- // FIXME
344
+ $$ = &ast.Arguments{Pos: $<pos>$}
335
345
}
336
346
| typedargslist
337
347
{
338
- // FIXME
348
+ $$ = $1
339
349
}
340
350
341
351
// (',' tfpdef ['=' test])*
342
352
tfpdeftest:
343
353
tfpdef
344
354
{
345
- // FIXME
355
+ $$ = $1
356
+ $<expr>$ = nil
346
357
}
347
358
| tfpdef ' =' test
348
359
{
349
- // FIXME
360
+ $$ = $1
361
+ $<expr>$ = $3
350
362
}
351
363
352
364
tfpdeftests:
353
365
{
354
- // FIXME
366
+ $$ = nil
367
+ $<exprs>$ = nil
355
368
}
356
369
| tfpdeftests ' ,' tfpdeftest
357
370
{
358
- // FIXME
371
+ $$ = append($$ , $3 )
372
+ if $<expr>3 != nil {
373
+ $<exprs>$ = append($<exprs>$, $<expr>3 )
374
+ }
375
+ }
376
+
377
+ tfpdeftests1:
378
+ tfpdeftest
379
+ {
380
+ $$ = nil
381
+ $$ = append($$ , $1 )
382
+ $<exprs>$ = nil
383
+ if $<expr>1 != nil {
384
+ $<exprs>$ = append($<exprs>$, $<expr>1 )
385
+ }
386
+ }
387
+ | tfpdeftests1 ' ,' tfpdeftest
388
+ {
389
+ $$ = append($$ , $3 )
390
+ if $<expr>3 != nil {
391
+ $<exprs>$ = append($<exprs>$, $<expr>3 )
392
+ }
359
393
}
360
394
361
395
optional_tfpdef:
362
396
{
363
- // FIXME
397
+ $$ = &ast.Arg{Pos: $<pos>$, Arg: ast.Identifier( " " )}
364
398
}
365
399
| tfpdef
366
400
{
367
- // FIXME
401
+ $$ = $1
368
402
}
369
403
404
+ // FIXME this isn't checking all the python rules for args before kwargs etc
370
405
typedargslist:
371
- tfpdeftest tfpdeftests
372
- {
373
- // FIXME
374
- }
375
- | tfpdeftest tfpdeftests ' ,'
406
+ tfpdeftests1 optional_comma
376
407
{
377
- // FIXME
408
+ $$ = &ast.Arguments{Pos: $<pos>$, Args: $1 , Defaults: $<exprs> 1 }
378
409
}
379
- | tfpdeftest tfpdeftests ' ,' ' *' optional_tfpdef tfpdeftests
410
+ | tfpdeftests1 ' ,' ' *' optional_tfpdef tfpdeftests
380
411
{
381
- // FIXME
412
+ $$ = &ast.Arguments{Pos: $<pos>$, Args: $1 , Defaults: $<exprs> 1 , Vararg: $4 , Kwonlyargs: $5 , KwDefaults: $<exprs> 5 }
382
413
}
383
- | tfpdeftest tfpdeftests ' ,' ' *' optional_tfpdef tfpdeftests ' ,' STARSTAR tfpdef
414
+ | tfpdeftests1 ' ,' ' *' optional_tfpdef tfpdeftests ' ,' STARSTAR tfpdef
384
415
{
385
- // FIXME
416
+ $$ = &ast.Arguments{Pos: $<pos>$, Args: $1 , Defaults: $<exprs> 1 , Vararg: $4 , Kwonlyargs: $5 , KwDefaults: $<exprs> 5 , Kwarg: $8 }
386
417
}
387
- | tfpdeftest tfpdeftests ' ,' STARSTAR tfpdef
418
+ | tfpdeftests1 ' ,' STARSTAR tfpdef
388
419
{
389
- // FIXME
420
+ $$ = &ast.Arguments{Pos: $<pos>$, Args: $1 , Defaults: $<exprs> 1 , Kwarg: $4 }
390
421
}
391
422
| ' *' optional_tfpdef tfpdeftests
392
423
{
393
- // FIXME
424
+ $$ = &ast.Arguments{Pos: $<pos>$, Vararg: $2 , Kwonlyargs: $3 , KwDefaults: $<exprs> 3 }
394
425
}
395
426
| ' *' optional_tfpdef tfpdeftests ' ,' STARSTAR tfpdef
396
427
{
397
- // FIXME
428
+ $$ = &ast.Arguments{Pos: $<pos>$, Vararg: $2 , Kwonlyargs: $3 , KwDefaults: $<exprs> 3 , Kwarg: $6 }
398
429
}
399
430
| STARSTAR tfpdef
400
431
{
401
- // FIXME
432
+ $$ = &ast.Arguments{Pos: $<pos>$, Kwarg: $2 }
402
433
}
403
434
404
435
tfpdef:
405
436
NAME
406
437
{
407
- // FIXME
438
+ $$ = &ast.Arg{Pos: $<pos>$, Arg: ast.Identifier( $1 )}
408
439
}
409
440
| NAME ' :' test
410
441
{
411
- // FIXME
442
+ $$ = &ast.Arg{Pos: $<pos>$, Arg: ast.Identifier( $1 ), Annotation: $3 }
412
443
}
413
444
414
445
vfpdeftest:
415
446
vfpdef
416
447
{
417
- $$ = &ast.Arg{Pos: $<pos>$, Arg: ast.Identifier( $1 )}
448
+ $$ = $1
418
449
$<expr>$ = nil
419
450
}
420
451
| vfpdef ' =' test
421
452
{
422
- $$ = &ast.Arg{Pos: $<pos>$, Arg: ast.Identifier( $1 )}
453
+ $$ = $1
423
454
$<expr>$ = $3
424
455
}
425
456
@@ -460,7 +491,7 @@ optional_vfpdef:
460
491
}
461
492
| vfpdef
462
493
{
463
- $$ = &ast.Arg{Pos: $<pos>$, Arg: ast.Identifier( $1 )}
494
+ $$ = $1
464
495
}
465
496
466
497
// FIXME this isn't checking all the python rules for args before kwargs etc
@@ -475,33 +506,29 @@ varargslist:
475
506
}
476
507
| vfpdeftests1 ' ,' ' *' optional_vfpdef vfpdeftests ' ,' STARSTAR vfpdef
477
508
{
478
- starstar := &ast.Arg{Pos: $<pos>8, Arg: ast.Identifier($8)}
479
- $$ = &ast.Arguments{Pos: $<pos>$, Args: $1, Defaults: $<exprs>1, Vararg: $4, Kwonlyargs: $5, KwDefaults: $<exprs>5, Kwarg: starstar}
509
+ $$ = &ast.Arguments{Pos: $<pos>$, Args: $1 , Defaults: $<exprs>1 , Vararg: $4 , Kwonlyargs: $5 , KwDefaults: $<exprs>5 , Kwarg: $8 }
480
510
}
481
511
| vfpdeftests1 ' ,' STARSTAR vfpdef
482
512
{
483
- starstar := &ast.Arg{Pos: $<pos>4, Arg: ast.Identifier($4)}
484
- $$ = &ast.Arguments{Pos: $<pos>$, Args: $1, Defaults: $<exprs>1, Kwarg: starstar}
513
+ $$ = &ast.Arguments{Pos: $<pos>$, Args: $1 , Defaults: $<exprs>1 , Kwarg: $4 }
485
514
}
486
515
| ' *' optional_vfpdef vfpdeftests
487
516
{
488
517
$$ = &ast.Arguments{Pos: $<pos>$, Vararg: $2 , Kwonlyargs: $3 , KwDefaults: $<exprs>3 }
489
518
}
490
519
| ' *' optional_vfpdef vfpdeftests ' ,' STARSTAR vfpdef
491
520
{
492
- starstar := &ast.Arg{Pos: $<pos>6, Arg: ast.Identifier($6)}
493
- $$ = &ast.Arguments{Pos: $<pos>$, Vararg: $2, Kwonlyargs: $3, KwDefaults: $<exprs>3, Kwarg: starstar}
521
+ $$ = &ast.Arguments{Pos: $<pos>$, Vararg: $2 , Kwonlyargs: $3 , KwDefaults: $<exprs>3 , Kwarg: $6 }
494
522
}
495
523
| STARSTAR vfpdef
496
524
{
497
- starstar := &ast.Arg{Pos: $<pos>2, Arg: ast.Identifier($2)}
498
- $$ = &ast.Arguments{Pos: $<pos>$, Kwarg: starstar}
525
+ $$ = &ast.Arguments{Pos: $<pos>$, Kwarg: $2 }
499
526
}
500
527
501
528
vfpdef:
502
529
NAME
503
530
{
504
- $$ = $1
531
+ $$ = &ast.Arg{Pos: $<pos>$, Arg: ast.Identifier( $1 )}
505
532
}
506
533
507
534
stmt:
@@ -997,15 +1024,15 @@ compound_stmt:
997
1024
}
998
1025
| funcdef
999
1026
{
1000
- // FIXME
1027
+ $$ = $1
1001
1028
}
1002
1029
| classdef
1003
1030
{
1004
- // FIXME
1031
+ $$ = $1
1005
1032
}
1006
1033
| decorated
1007
1034
{
1008
- // FIXME
1035
+ $$ = $1
1009
1036
}
1010
1037
1011
1038
elifs:
@@ -1737,6 +1764,7 @@ classdef:
1737
1764
CLASS NAME optional_arglist_call ' :' suite
1738
1765
{
1739
1766
// FIXME
1767
+ // $$ = &ast.ClassDef{StmtBase: ast.StmtBase{$<pos>$}, Name: ast.Identifier($2), Args: $3, Body: $5}
1740
1768
}
1741
1769
1742
1770
arguments:
0 commit comments