GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — cpython/Grammar/python.gram at main · python/cpython Expand file tree/ Copy pathpython.gramMore file actions 1167 lines (966 loc) · 44 KB / Copy pathpython.gramFile metadata and controls1167 lines (966 loc) · 44 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 # PEG grammar for Python @trailer ''' void * _PyPegen_parse(Parser *p) { // Initialize keywords p->keywords = reserved_keywords; p->n_keyword_lists = n_keyword_lists; p->soft_keywords = soft_keywords; // Run parser void *result = NULL; if (p->start_rule == Py_file_input) { result = file_rule(p); } else if (p->start_rule == Py_single_input) { result = interactive_rule(p); } else if (p->start_rule == Py_eval_input) { result = eval_rule(p); } else if (p->start_rule == Py_func_type_input) { result = func_type_rule(p); } return result; } ''' @include "invalid.gram" # ========================= START OF THE GRAMMAR ========================= # General grammatical elements and rules: # # * Strings with double quotes (") denote SOFT KEYWORDS # * Strings with single quotes (') denote KEYWORDS # * Upper case names (NAME) denote tokens in the Grammar/Tokens file # # Grammar Syntax (see PEP 617 for more information): # # rule_name: expression # Optionally, a type can be included right after the rule name, which # specifies the return type of the C or Python function corresponding to the # rule: # rule_name[return_type]: expression # If the return type is omitted, then a void * is returned in C and an Any in # Python. # e1 e2 # Match e1, then match e2. # e1 | e2 # Match e1 or e2. # The first alternative can also appear on the line after the rule name for # formatting purposes. In that case, a | must be used before the first # alternative, like so: # rule_name[return_type]: # | first_alt # | second_alt # ( e ) # Match e (allows also to use other operators in the group like '(e)*') # [ e ] or e? # Optionally match e. # e* # Match zero or more occurrences of e. # e+ # Match one or more occurrences of e. # s.e+ # Match one or more occurrences of e, separated by s. The generated parse tree # does not include the separator. This is otherwise identical to (e (s e)*). # &e # Succeed if e can be parsed, without consuming any input. # !e # Fail if e can be parsed, without consuming any input. # ~ # Commit to the current alternative, even if it fails to parse. # &&e # Eager parse e. The parser will not backtrack and will immediately # fail with SyntaxError if e cannot be parsed. # # STARTING RULES # ============== file[mod_ty]: a=[statements] ENDMARKER { _PyPegen_make_module(p, a) } interactive[mod_ty]: a=statement_newline { _PyAST_Interactive(a, p->arena) } eval[mod_ty]: a=expressions NEWLINE* ENDMARKER { _PyAST_Expression(a, p->arena) } func_type[mod_ty]: '(' a=[type_expressions] ')' '->' b=expression NEWLINE* ENDMARKER { _PyAST_FunctionType(a, b, p->arena) } # GENERAL STATEMENTS # ================== statements[asdl_stmt_seq*]: a=statement+ { (asdl_stmt_seq*)_PyPegen_seq_flatten(p, a) } statement[asdl_stmt_seq*]: | a=compound_stmt { _PyPegen_register_stmts(p , (asdl_stmt_seq*)_PyPegen_singleton_seq(p, a) ) } | a[asdl_stmt_seq*]=simple_stmts { a } single_compound_stmt[asdl_stmt_seq*]: | a=compound_stmt { _PyPegen_register_stmts(p, (asdl_stmt_seq*)_PyPegen_singleton_seq(p, a)) } statement_newline[asdl_stmt_seq*]: | a=single_compound_stmt NEWLINE { a } | simple_stmts | NEWLINE { (asdl_stmt_seq*)_PyPegen_singleton_seq(p, CHECK(stmt_ty, _PyAST_Pass(EXTRA))) } | ENDMARKER { _PyPegen_interactive_exit(p) } simple_stmts[asdl_stmt_seq*]: | a=simple_stmt !';' NEWLINE { (asdl_stmt_seq*)_PyPegen_singleton_seq(p, a) } # Not needed, there for speedup | a[asdl_stmt_seq*]=';'.simple_stmt+ [';'] NEWLINE { a } # NOTE: assignment MUST precede expression, else parsing a simple assignment # will throw a SyntaxError. simple_stmt[stmt_ty] (memo): | assignment | &"type" type_alias | &('import' | 'from' | "lazy") import_stmt | e=star_expressions { _PyAST_Expr(e, EXTRA) } | &'return' return_stmt | &'raise' raise_stmt | &'pass' pass_stmt | &'del' del_stmt | &'yield' yield_stmt | &'assert' assert_stmt | &'break' break_stmt | &'continue' continue_stmt | &'global' global_stmt | &'nonlocal' nonlocal_stmt compound_stmt[stmt_ty]: | &('def' | '@' | 'async') function_def | &'if' if_stmt | &('class' | '@') class_def | &('with' | 'async') with_stmt | &('for' | 'async') for_stmt | &'try' try_stmt | &'while' while_stmt | match_stmt # SIMPLE STATEMENTS # ================= # NOTE: annotated_rhs may start with 'yield'; yield_expr must start with 'yield' assignment[stmt_ty]: | a=NAME ':' b=expression c=['=' d=annotated_rhs { d }] { CHECK_VERSION( stmt_ty, 6, "Variable annotation syntax is", _PyAST_AnnAssign(CHECK(expr_ty, _PyPegen_set_expr_context(p, a, Store)), b, c, 1, EXTRA) ) } | a=('(' b=single_target ')' { b } | attribute_or_subscript_target) ':' b=expression c=['=' d=annotated_rhs { d }] { CHECK_VERSION(stmt_ty, 6, "Variable annotations syntax is", _PyAST_AnnAssign(a, b, c, 0, EXTRA)) } | a[asdl_expr_seq*]=(z=star_targets '=' { z })+ b=annotated_rhs !'=' tc=[TYPE_COMMENT] { _PyAST_Assign(a, b, NEW_TYPE_COMMENT(p, tc), EXTRA) } | a=single_target b=augassign ~ c=annotated_rhs { _PyAST_AugAssign(a, b->kind, c, EXTRA) } | invalid_assignment annotated_rhs[expr_ty]: yield_expr | star_expressions augassign[AugOperator*]: | '+=' { _PyPegen_augoperator(p, Add) } | '-=' { _PyPegen_augoperator(p, Sub) } | '*=' { _PyPegen_augoperator(p, Mult) } | '@=' { CHECK_VERSION(AugOperator*, 5, "The '@' operator is", _PyPegen_augoperator(p, MatMult)) } | '/=' { _PyPegen_augoperator(p, Div) } | '%=' { _PyPegen_augoperator(p, Mod) } | '&=' { _PyPegen_augoperator(p, BitAnd) } | '|=' { _PyPegen_augoperator(p, BitOr) } | '^=' { _PyPegen_augoperator(p, BitXor) } | '<<=' { _PyPegen_augoperator(p, LShift) } | '>>=' { _PyPegen_augoperator(p, RShift) } | '**=' { _PyPegen_augoperator(p, Pow) } | '//=' { _PyPegen_augoperator(p, FloorDiv) } return_stmt[stmt_ty]: | 'return' a=[star_expressions] { _PyAST_Return(a, EXTRA) } raise_stmt[stmt_ty]: | 'raise' a=expression 'from' b=expression { _PyAST_Raise(a, b, EXTRA) } | invalid_raise_stmt | 'raise' a=expression { _PyAST_Raise(a, NULL, EXTRA) } | 'raise' { _PyAST_Raise(NULL, NULL, EXTRA) } pass_stmt[stmt_ty]: | 'pass' { _PyAST_Pass(EXTRA) } break_stmt[stmt_ty]: | 'break' { _PyAST_Break(EXTRA) } continue_stmt[stmt_ty]: | 'continue' { _PyAST_Continue(EXTRA) } global_stmt[stmt_ty]: 'global' a[asdl_expr_seq*]=','.NAME+ { _PyAST_Global(CHECK(asdl_identifier_seq*, _PyPegen_map_names_to_ids(p, a)), EXTRA) } nonlocal_stmt[stmt_ty]: 'nonlocal' a[asdl_expr_seq*]=','.NAME+ { _PyAST_Nonlocal(CHECK(asdl_identifier_seq*, _PyPegen_map_names_to_ids(p, a)), EXTRA) } del_stmt[stmt_ty]: | 'del' a=del_targets &(';' | NEWLINE) { _PyAST_Delete(a, EXTRA) } | invalid_del_stmt yield_stmt[stmt_ty]: y=yield_expr { _PyAST_Expr(y, EXTRA) } assert_stmt[stmt_ty]: | invalid_assert_stmt | 'assert' a=expression b=[',' z=expression { z }] { _PyAST_Assert(a, b, EXTRA) } import_stmt[stmt_ty](memo): | invalid_import | import_name | import_from # Import statements # ----------------- import_name[stmt_ty]: | "lazy" 'import' a=dotted_as_names { CHECK_VERSION(stmt_ty, 15, "Lazy imports are", _PyAST_Import(a, 1, EXTRA)) } | 'import' a=dotted_as_names { _PyAST_Import(a, 0, EXTRA) } # note below: the ('.' | '...') is necessary because '...' is tokenized as ELLIPSIS import_from[stmt_ty]: | invalid_import_from | lazy="lazy" 'from' a=('.' | '...')* b=dotted_name 'import' c=import_from_targets { CHECK_VERSION(stmt_ty, 15, "Lazy imports are", _PyPegen_checked_from_import(p, a, b, c, lazy, EXTRA)) } | "lazy" 'from' a=('.' | '...')+ 'import' b=import_from_targets { CHECK_VERSION(stmt_ty, 15, "Lazy imports are", _PyAST_ImportFrom(NULL, b, _PyPegen_seq_count_dots(a), 1, EXTRA)) } | 'from' a=('.' | '...')* b=dotted_name 'import' c=import_from_targets { _PyPegen_checked_from_import(p, a, b, c, NULL, EXTRA) } | 'from' a=('.' | '...')+ 'import' b=import_from_targets { _PyAST_ImportFrom(NULL, b, _PyPegen_seq_count_dots(a), 0, EXTRA) } import_from_targets[asdl_alias_seq*]: | '(' a=import_from_as_names [','] ')' { a } | import_from_as_names !',' | '*' { (asdl_alias_seq*)_PyPegen_singleton_seq(p, CHECK(alias_ty, _PyPegen_alias_for_star(p, EXTRA))) } | invalid_import_from_targets import_from_as_names[asdl_alias_seq*]: | a[asdl_alias_seq*]=','.import_from_as_name+ { a } import_from_as_name[alias_ty]: | invalid_import_from_as_name | a=NAME b=['as' z=NAME { z }] { _PyAST_alias( a->v.Name.id, (b) ? ((expr_ty) b)->v.Name.id : NULL, EXTRA) } dotted_as_names[asdl_alias_seq*]: | a[asdl_alias_seq*]=','.dotted_as_name+ { a } dotted_as_name[alias_ty]: | invalid_dotted_as_name | a=dotted_name b=['as' z=NAME { z }] { _PyAST_alias( a->v.Name.id, (b) ? ((expr_ty) b)->v.Name.id : NULL, EXTRA) } dotted_name[expr_ty]: | a=dotted_name '.' b=NAME { _PyPegen_join_names_with_dot(p, a, b) } | NAME # COMPOUND STATEMENTS # =================== # Common elements # --------------- block[asdl_stmt_seq*] (memo): | NEWLINE INDENT a=statements DEDENT { a } | simple_stmts | invalid_block decorators[asdl_expr_seq*]: a[asdl_expr_seq*]=('@' f=named_expression NEWLINE { f })+ { a } # Class definitions # ----------------- class_def[stmt_ty]: | a=decorators b=class_def_raw { _PyPegen_class_def_decorators(p, a, b) } | class_def_raw class_def_raw[stmt_ty]: | invalid_class_def_raw | 'class' a=NAME t=[type_params] b=['(' z=[arguments] ')' { z }] ':' c=block { _PyAST_ClassDef(a->v.Name.id, (b) ? ((expr_ty) b)->v.Call.args : NULL, (b) ? ((expr_ty) b)->v.Call.keywords : NULL, c, NULL, t, EXTRA) } # Function definitions # -------------------- function_def[stmt_ty]: | d=decorators f=function_def_raw { _PyPegen_function_def_decorators(p, d, f) } | function_def_raw function_def_raw[stmt_ty]: | invalid_def_raw | 'def' n=NAME t=[type_params] '(' params=[params] ')' a=['->' z=expression { z }] ':' tc=[func_type_comment] b=block { _PyAST_FunctionDef(n->v.Name.id, (params) ? params : CHECK(arguments_ty, _PyPegen_empty_arguments(p)), b, NULL, a, NEW_TYPE_COMMENT(p, tc), t, EXTRA) } | 'async' 'def' n=NAME t=[type_params] '(' params=[params] ')' a=['->' z=expression { z }] ':' tc=[func_type_comment] b=block { CHECK_VERSION( stmt_ty, 5, "Async functions are", _PyAST_AsyncFunctionDef(n->v.Name.id, (params) ? params : CHECK(arguments_ty, _PyPegen_empty_arguments(p)), b, NULL, a, NEW_TYPE_COMMENT(p, tc), t, EXTRA) ) } # Function parameters # ------------------- params[arguments_ty]: | invalid_parameters | parameters parameters[arguments_ty]: | a=slash_no_default b[asdl_arg_seq*]=param_no_default* c=param_with_default* d=[star_etc] { CHECK_VERSION(arguments_ty, 8, "Positional-only parameters are", _PyPegen_make_arguments(p, a, NULL, b, c, d)) } | a=slash_with_default b=param_with_default* c=[star_etc] { CHECK_VERSION(arguments_ty, 8, "Positional-only parameters are", _PyPegen_make_arguments(p, NULL, a, NULL, b, c)) } | a[asdl_arg_seq*]=param_no_default+ b=param_with_default* c=[star_etc] { _PyPegen_make_arguments(p, NULL, NULL, a, b, c) } | a=param_with_default+ b=[star_etc] { _PyPegen_make_arguments(p, NULL, NULL, NULL, a, b)} | a=star_etc { _PyPegen_make_arguments(p, NULL, NULL, NULL, NULL, a) } # Some duplication here because we can't write (',' | &')'), # which is because we don't support empty alternatives (yet). slash_no_default[asdl_arg_seq*]: | a[asdl_arg_seq*]=param_no_default+ '/' ',' { a } | a[asdl_arg_seq*]=param_no_default+ '/' &')' { a } slash_with_default[SlashWithDefault*]: | a=param_no_default* b=param_with_default+ '/' ',' { _PyPegen_slash_with_default(p, (asdl_arg_seq *)a, b) } | a=param_no_default* b=param_with_default+ '/' &')' { _PyPegen_slash_with_default(p, (asdl_arg_seq *)a, b) } star_etc[StarEtc*]: | invalid_star_etc | '*' a=param_no_default b=param_maybe_default* c=[kwds] { _PyPegen_star_etc(p, a, b, c) } | '*' a=param_no_default_star_annotation b=param_maybe_default* c=[kwds] { _PyPegen_star_etc(p, a, b, c) } | '*' ',' b=param_maybe_default+ c=[kwds] { _PyPegen_star_etc(p, NULL, b, c) } | a=kwds { _PyPegen_star_etc(p, NULL, NULL, a) } kwds[arg_ty]: | invalid_kwds | '**' a=param_no_default { a } # One parameter. This *includes* a following comma and type comment. # # There are three styles: # - No default # - With default # - Maybe with default # # There are two alternative forms of each, to deal with type comments: # - Ends in a comma followed by an optional type comment # - No comma, optional type comment, must be followed by close paren # The latter form is for a final parameter without trailing comma. # param_no_default[arg_ty]: | a=param ',' tc=TYPE_COMMENT? { _PyPegen_add_type_comment_to_arg(p, a, tc) } | a=param tc=TYPE_COMMENT? &')' { _PyPegen_add_type_comment_to_arg(p, a, tc) } param_no_default_star_annotation[arg_ty]: | a=param_star_annotation ',' tc=TYPE_COMMENT? { _PyPegen_add_type_comment_to_arg(p, a, tc) } | a=param_star_annotation tc=TYPE_COMMENT? &')' { _PyPegen_add_type_comment_to_arg(p, a, tc) } param_with_default[NameDefaultPair*]: | a=param c=default ',' tc=TYPE_COMMENT? { _PyPegen_name_default_pair(p, a, c, tc) } | a=param c=default tc=TYPE_COMMENT? &')' { _PyPegen_name_default_pair(p, a, c, tc) } param_maybe_default[NameDefaultPair*]: | a=param c=default? ',' tc=TYPE_COMMENT? { _PyPegen_name_default_pair(p, a, c, tc) } | a=param c=default? tc=TYPE_COMMENT? &')' { _PyPegen_name_default_pair(p, a, c, tc) } param[arg_ty]: a=NAME b=annotation? { _PyAST_arg(a->v.Name.id, b, NULL, EXTRA) } param_star_annotation[arg_ty]: a=NAME b=star_annotation { _PyAST_arg(a->v.Name.id, b, NULL, EXTRA) } annotation[expr_ty]: ':' a=expression { a } star_annotation[expr_ty]: ':' a=star_expression { a } default[expr_ty]: '=' a=expression { a } | invalid_default # If statement # ------------ if_stmt[stmt_ty]: | invalid_if_stmt | 'if' a=named_expression ':' b=block c=elif_stmt { _PyAST_If(a, b, CHECK(asdl_stmt_seq*, _PyPegen_singleton_seq(p, c)), EXTRA) } | 'if' a=named_expression ':' b=block c=[else_block] { _PyAST_If(a, b, c, EXTRA) } elif_stmt[stmt_ty]: | invalid_elif_stmt | 'elif' a=named_expression ':' b=block c=elif_stmt { _PyAST_If(a, b, CHECK(asdl_stmt_seq*, _PyPegen_singleton_seq(p, c)), EXTRA) } | 'elif' a=named_expression ':' b=block c=[else_block] { _PyAST_If(a, b, c, EXTRA) } else_block[asdl_stmt_seq*]: | invalid_else_stmt | 'else' &&':' b=block { b } # While statement # --------------- while_stmt[stmt_ty]: | invalid_while_stmt | 'while' a=named_expression ':' b=block c=[else_block] { _PyAST_While(a, b, c, EXTRA) } # For statement # ------------- for_stmt[stmt_ty]: | invalid_for_stmt | 'for' t=star_targets 'in' ~ ex=star_expressions ':' tc=[TYPE_COMMENT] b=block el=[else_block] { _PyAST_For(t, ex, b, el, NEW_TYPE_COMMENT(p, tc), EXTRA) } | 'async' 'for' t=star_targets 'in' ~ ex=star_expressions ':' tc=[TYPE_COMMENT] b=block el=[else_block] { CHECK_VERSION(stmt_ty, 5, "Async for loops are", _PyAST_AsyncFor(t, ex, b, el, NEW_TYPE_COMMENT(p, tc), EXTRA)) } | invalid_for_target # With statement # -------------- with_stmt[stmt_ty]: | invalid_with_stmt_indent | 'with' '(' a[asdl_withitem_seq*]=','.with_item+ ','? ')' ':' tc=[TYPE_COMMENT] b=block { _PyAST_With(a, b, NEW_TYPE_COMMENT(p, tc), EXTRA) } | 'with' a[asdl_withitem_seq*]=','.with_item+ ':' tc=[TYPE_COMMENT] b=block { _PyAST_With(a, b, NEW_TYPE_COMMENT(p, tc), EXTRA) } | 'async' 'with' '(' a[asdl_withitem_seq*]=','.with_item+ ','? ')' ':' b=block { CHECK_VERSION(stmt_ty, 5, "Async with statements are", _PyAST_AsyncWith(a, b, NULL, EXTRA)) } | 'async' 'with' a[asdl_withitem_seq*]=','.with_item+ ':' tc=[TYPE_COMMENT] b=block { CHECK_VERSION(stmt_ty, 5, "Async with statements are", _PyAST_AsyncWith(a, b, NEW_TYPE_COMMENT(p, tc), EXTRA)) } | invalid_with_stmt with_item[withitem_ty]: | e=expression 'as' t=star_target &(',' | ')' | ':') { _PyAST_withitem(e, t, p->arena) } | invalid_with_item | e=expression { _PyAST_withitem(e, NULL, p->arena) } # Try statement # ------------- try_stmt[stmt_ty]: | invalid_try_stmt | 'try' &&':' b=block f=finally_block { _PyAST_Try(b, NULL, NULL, f, EXTRA) } | 'try' &&':' b=block ex[asdl_excepthandler_seq*]=except_block+ el=[else_block] f=[finally_block] { _PyAST_Try(b, ex, el, f, EXTRA) } | 'try' &&':' b=block ex[asdl_excepthandler_seq*]=except_star_block+ el=[else_block] f=[finally_block] { CHECK_VERSION(stmt_ty, 11, "Exception groups are", _PyAST_TryStar(b, ex, el, f, EXTRA)) } # Except statement # ---------------- except_block[excepthandler_ty]: | invalid_except_stmt_indent | 'except' e=expression ':' b=block { _PyAST_ExceptHandler(e, NULL, b, EXTRA) } | 'except' e=expression 'as' t=NAME ':' b=block { _PyAST_ExceptHandler(e, ((expr_ty) t)->v.Name.id, b, EXTRA) } | 'except' e=expressions ':' b=block { CHECK_VERSION( excepthandler_ty, 14, "except expressions without parentheses are", _PyAST_ExceptHandler(e, NULL, b, EXTRA)) } | 'except' ':' b=block { _PyAST_ExceptHandler(NULL, NULL, b, EXTRA) } | invalid_except_stmt except_star_block[excepthandler_ty]: | invalid_except_star_stmt_indent | 'except' '*' e=expression ':' b=block { _PyAST_ExceptHandler(e, NULL, b, EXTRA) } | 'except' '*' e=expression 'as' t=NAME ':' b=block { _PyAST_ExceptHandler(e, ((expr_ty) t)->v.Name.id, b, EXTRA) } | 'except' '*' e=expressions ':' b=block { CHECK_VERSION( excepthandler_ty, 14, "except expressions without parentheses are", _PyAST_ExceptHandler(e, NULL, b, EXTRA)) } | invalid_except_star_stmt finally_block[asdl_stmt_seq*]: | invalid_finally_stmt | 'finally' &&':' a=block { a } # Match statement # --------------- match_stmt[stmt_ty]: | "match" subject=subject_expr ':' NEWLINE INDENT cases[asdl_match_case_seq*]=case_block+ DEDENT { CHECK_VERSION(stmt_ty, 10, "Pattern matching is", _PyAST_Match(subject, cases, EXTRA)) } | invalid_match_stmt subject_expr[expr_ty]: | value=star_named_expression ',' values=star_named_expressions? { _PyAST_Tuple(CHECK(asdl_expr_seq*, _PyPegen_seq_insert_in_front(p, value, values)), Load, EXTRA) } | named_expression case_block[match_case_ty]: | invalid_case_block | "case" pattern=patterns guard=guard? ':' body=block { _PyAST_match_case(pattern, guard, body, p->arena) } guard[expr_ty]: 'if' guard=named_expression { guard } patterns[pattern_ty]: | patterns[asdl_pattern_seq*]=open_sequence_pattern { _PyAST_MatchSequence(patterns, EXTRA) } | pattern pattern[pattern_ty]: | as_pattern | or_pattern as_pattern[pattern_ty]: | pattern=or_pattern 'as' target=pattern_capture_target { _PyAST_MatchAs(pattern, target->v.Name.id, EXTRA) } | invalid_as_pattern or_pattern[pattern_ty]: | patterns[asdl_pattern_seq*]='|'.closed_pattern+ { asdl_seq_LEN(patterns) == 1 ? asdl_seq_GET(patterns, 0) : _PyAST_MatchOr(patterns, EXTRA) } closed_pattern[pattern_ty] (memo): | literal_pattern | capture_pattern | wildcard_pattern | value_pattern | group_pattern | sequence_pattern | mapping_pattern | class_pattern # Literal patterns are used for equality and identity constraints literal_pattern[pattern_ty]: | value=signed_number !('+' | '-') { _PyAST_MatchValue(value, EXTRA) } | value=complex_number { _PyAST_MatchValue(value, EXTRA) } | value=strings { _PyAST_MatchValue(value, EXTRA) } | 'None' { _PyAST_MatchSingleton(Py_None, EXTRA) } | 'True' { _PyAST_MatchSingleton(Py_True, EXTRA) } | 'False' { _PyAST_MatchSingleton(Py_False, EXTRA) } # Literal expressions are used to restrict permitted mapping pattern keys literal_expr[expr_ty]: | signed_number !('+' | '-') | complex_number | &(STRING|FSTRING_START|TSTRING_START) strings | 'None' { _PyAST_Constant(Py_None, NULL, EXTRA) } | 'True' { _PyAST_Constant(Py_True, NULL, EXTRA) } | 'False' { _PyAST_Constant(Py_False, NULL, EXTRA) } complex_number[expr_ty]: | real=signed_real_number '+' imag=imaginary_number { _PyAST_BinOp(real, Add, imag, EXTRA) } | real=signed_real_number '-' imag=imaginary_number { _PyAST_BinOp(real, Sub, imag, EXTRA) } signed_number[expr_ty]: | NUMBER | '+' number=NUMBER { _PyAST_UnaryOp(UAdd, number, EXTRA) } | '-' number=NUMBER { _PyAST_UnaryOp(USub, number, EXTRA) } signed_real_number[expr_ty]: | real_number | '+' real=real_number { _PyAST_UnaryOp(UAdd, real, EXTRA) } | '-' real=real_number { _PyAST_UnaryOp(USub, real, EXTRA) } real_number[expr_ty]: | real=NUMBER { _PyPegen_ensure_real(p, real) } imaginary_number[expr_ty]: | imag=NUMBER { _PyPegen_ensure_imaginary(p, imag) } capture_pattern[pattern_ty]: | target=pattern_capture_target { _PyAST_MatchAs(NULL, target->v.Name.id, EXTRA) } pattern_capture_target[expr_ty]: | !"_" name=NAME !('.' | '(' | '=') { _PyPegen_set_expr_context(p, name, Store) } wildcard_pattern[pattern_ty]: | "_" { _PyAST_MatchAs(NULL, NULL, EXTRA) } value_pattern[pattern_ty]: | attr=attr !('.' | '(' | '=') { _PyAST_MatchValue(attr, EXTRA) } attr[expr_ty]: | value=name_or_attr '.' attr=NAME { _PyAST_Attribute(value, attr->v.Name.id, Load, EXTRA) } name_or_attr[expr_ty]: | attr | NAME group_pattern[pattern_ty]: | '(' pattern=pattern ')' { pattern } sequence_pattern[pattern_ty]: | '[' patterns=maybe_sequence_pattern? ']' { _PyAST_MatchSequence(patterns, EXTRA) } | '(' patterns=open_sequence_pattern? ')' { _PyAST_MatchSequence(patterns, EXTRA) } open_sequence_pattern[asdl_seq*]: | pattern=maybe_star_pattern ',' patterns=maybe_sequence_pattern? { _PyPegen_seq_insert_in_front(p, pattern, patterns) } maybe_sequence_pattern[asdl_seq*]: | patterns=','.maybe_star_pattern+ ','? { patterns } maybe_star_pattern[pattern_ty]: | star_pattern | pattern star_pattern[pattern_ty] (memo): | '*' target=pattern_capture_target { _PyAST_MatchStar(target->v.Name.id, EXTRA) } | '*' wildcard_pattern { _PyAST_MatchStar(NULL, EXTRA) } mapping_pattern[pattern_ty]: | '{' '}' { _PyAST_MatchMapping(NULL, NULL, NULL, EXTRA) } | '{' rest=double_star_pattern ','? '}' { _PyAST_MatchMapping(NULL, NULL, rest->v.Name.id, EXTRA) } | '{' items=items_pattern ',' rest=double_star_pattern ','? '}' { _PyAST_MatchMapping( CHECK(asdl_expr_seq*, _PyPegen_get_pattern_keys(p, items)), CHECK(asdl_pattern_seq*, _PyPegen_get_patterns(p, items)), rest->v.Name.id, EXTRA) } | '{' items=items_pattern ','? '}' { _PyAST_MatchMapping( CHECK(asdl_expr_seq*, _PyPegen_get_pattern_keys(p, items)), CHECK(asdl_pattern_seq*, _PyPegen_get_patterns(p, items)), NULL, EXTRA) } | invalid_mapping_pattern items_pattern[asdl_seq*]: | ','.key_value_pattern+ key_value_pattern[KeyPatternPair*]: | key=(literal_expr | attr) ':' pattern=pattern { _PyPegen_key_pattern_pair(p, key, pattern) } double_star_pattern[expr_ty]: | '**' target=pattern_capture_target { target } class_pattern[pattern_ty]: | cls=name_or_attr '(' ')' { _PyAST_MatchClass(cls, NULL, NULL, NULL, EXTRA) } | cls=name_or_attr '(' patterns=positional_patterns ','? ')' { _PyAST_MatchClass(cls, patterns, NULL, NULL, EXTRA) } | cls=name_or_attr '(' keywords=keyword_patterns ','? ')' { _PyAST_MatchClass( cls, NULL, CHECK(asdl_identifier_seq*, _PyPegen_map_names_to_ids(p, CHECK(asdl_expr_seq*, _PyPegen_get_pattern_keys(p, keywords)))), CHECK(asdl_pattern_seq*, _PyPegen_get_patterns(p, keywords)), EXTRA) } | cls=name_or_attr '(' patterns=positional_patterns ',' keywords=keyword_patterns ','? ')' { _PyAST_MatchClass( cls, patterns, CHECK(asdl_identifier_seq*, _PyPegen_map_names_to_ids(p, CHECK(asdl_expr_seq*, _PyPegen_get_pattern_keys(p, keywords)))), CHECK(asdl_pattern_seq*, _PyPegen_get_patterns(p, keywords)), EXTRA) } | invalid_class_pattern positional_patterns[asdl_pattern_seq*]: | args[asdl_pattern_seq*]=','.pattern+ { args } keyword_patterns[asdl_seq*]: | ','.keyword_pattern+ keyword_pattern[KeyPatternPair*]: | arg=NAME '=' value=pattern { _PyPegen_key_pattern_pair(p, arg, value) } # Type statement # --------------- type_alias[stmt_ty]: | "type" n=NAME t=[type_params] '=' b=expression { CHECK_VERSION(stmt_ty, 12, "Type statement is", _PyAST_TypeAlias(CHECK(expr_ty, _PyPegen_set_expr_context(p, n, Store)), t, b, EXTRA)) } # Type parameter declaration # -------------------------- type_params[asdl_type_param_seq*]: | invalid_type_params | '[' t=type_param_seq ']' { CHECK_VERSION(asdl_type_param_seq *, 12, "Type parameter lists are", t) } type_param_seq[asdl_type_param_seq*]: a[asdl_type_param_seq*]=','.type_param+ [','] { a } type_param[type_param_ty] (memo): | a=NAME b=[type_param_bound] c=[type_param_default] { _PyAST_TypeVar(a->v.Name.id, b, c, EXTRA) } | invalid_type_param | '*' a=NAME b=[type_param_starred_default] { _PyAST_TypeVarTuple(a->v.Name.id, b, EXTRA) } | '**' a=NAME b=[type_param_default] { _PyAST_ParamSpec(a->v.Name.id, b, EXTRA) } type_param_bound[expr_ty]: ':' e=expression { e } type_param_default[expr_ty]: '=' e=expression { CHECK_VERSION(expr_ty, 13, "Type parameter defaults are", e) } type_param_starred_default[expr_ty]: '=' e=star_expression { CHECK_VERSION(expr_ty, 13, "Type parameter defaults are", e) } # EXPRESSIONS # ----------- expressions[expr_ty]: | a=expression b=(',' c=expression { c })+ [','] { _PyAST_Tuple(CHECK(asdl_expr_seq*, _PyPegen_seq_insert_in_front(p, a, b)), Load, EXTRA) } | a=expression ',' { _PyAST_Tuple(CHECK(asdl_expr_seq*, _PyPegen_singleton_seq(p, a)), Load, EXTRA) } | expression expression[expr_ty] (memo): | invalid_if_expression | invalid_expression | invalid_legacy_expression | if_expression | disjunction | lambdef if_expression[expr_ty]: | a=disjunction 'if' b=disjunction 'else' c=expression { _PyAST_IfExp(b, a, c, EXTRA) } yield_expr[expr_ty]: | 'yield' 'from' a=expression { _PyAST_YieldFrom(a, EXTRA) } | 'yield' a=[star_expressions] { _PyAST_Yield(a, EXTRA) } star_expressions[expr_ty]: | a=star_expression b=(',' c=star_expression { c })+ [','] { _PyAST_Tuple(CHECK(asdl_expr_seq*, _PyPegen_seq_insert_in_front(p, a, b)), Load, EXTRA) } | a=star_expression ',' { _PyAST_Tuple(CHECK(asdl_expr_seq*, _PyPegen_singleton_seq(p, a)), Load, EXTRA) } | star_expression star_expression[expr_ty] (memo): | '*' a=bitwise_or { _PyAST_Starred(a, Load, EXTRA) } | expression star_named_expressions[asdl_expr_seq*]: a[asdl_expr_seq*]=','.star_named_expression+ [','] { a } star_named_expression[expr_ty]: | '*' a=bitwise_or { _PyAST_Starred(a, Load, EXTRA) } | named_expression assignment_expression[expr_ty]: | a=NAME ':=' ~ b=expression { CHECK_VERSION(expr_ty, 8, "Assignment expressions are", _PyAST_NamedExpr(CHECK(expr_ty, _PyPegen_set_expr_context(p, a, Store)), b, EXTRA)) } named_expression[expr_ty]: | assignment_expression | invalid_named_expression | expression !':=' disjunction[expr_ty] (memo, fastpath=_PyPegen_atom_fast_path): | a=conjunction b=('or' c=conjunction { c })+ { _PyAST_BoolOp( Or, CHECK(asdl_expr_seq*, _PyPegen_seq_insert_in_front(p, a, b)), EXTRA) } | conjunction conjunction[expr_ty] (memo): | a=inversion b=('and' c=inversion { c })+ { _PyAST_BoolOp( And, CHECK(asdl_expr_seq*, _PyPegen_seq_insert_in_front(p, a, b)), EXTRA) } | inversion inversion[expr_ty] (memo, fastpath=_PyPegen_atom_fast_path): | 'not' a=inversion { _PyAST_UnaryOp(Not, a, EXTRA) } | comparison # Comparison operators # -------------------- comparison[expr_ty]: | a=bitwise_or b=compare_op_bitwise_or_pair+ { _PyAST_Compare( a, CHECK(asdl_int_seq*, _PyPegen_get_cmpops(p, b)), CHECK(asdl_expr_seq*, _PyPegen_get_exprs(p, b)), EXTRA) } | bitwise_or compare_op_bitwise_or_pair[CmpopExprPair*]: | '==' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, Eq, a) } | (tok='!=' { _PyPegen_check_barry_as_flufl(p, tok) ? NULL : tok }) a=bitwise_or { _PyPegen_cmpop_expr_pair(p, NotEq, a) } | '<=' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, LtE, a) } | invalid_noteq | '<' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, Lt, a) } | '>=' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, GtE, a) } | '>' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, Gt, a) } | 'not' 'in' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, NotIn, a) } | 'in' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, In, a) } | 'is' 'not' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, IsNot, a) } | 'is' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, Is, a) } # Bitwise operators # ----------------- bitwise_or[expr_ty]: | a=bitwise_or '|' b=bitwise_xor { _PyAST_BinOp(a, BitOr, b, EXTRA) } | invalid_bitwise_or | bitwise_xor bitwise_xor[expr_ty]: | a=bitwise_xor '^' b=bitwise_and { _PyAST_BinOp(a, BitXor, b, EXTRA) } | bitwise_and bitwise_and[expr_ty]: | a=bitwise_and '&' b=shift_expr { _PyAST_BinOp(a, BitAnd, b, EXTRA) } | invalid_bitwise_and | shift_expr shift_expr[expr_ty]: | a=shift_expr '<<' b=sum { _PyAST_BinOp(a, LShift, b, EXTRA) } | a=shift_expr '>>' b=sum { _PyAST_BinOp(a, RShift, b, EXTRA) } | sum # Arithmetic operators # -------------------- sum[expr_ty]: | a=sum '+' b=term { _PyAST_BinOp(a, Add, b, EXTRA) } | a=sum '-' b=term { _PyAST_BinOp(a, Sub, b, EXTRA) } | invalid_arithmetic | term term[expr_ty]: | a=term '*' b=factor { _PyAST_BinOp(a, Mult, b, EXTRA) } | a=term '/' b=factor { _PyAST_BinOp(a, Div, b, EXTRA) } | a=term '//' b=factor { _PyAST_BinOp(a, FloorDiv, b, EXTRA) } | a=term '%' b=factor { _PyAST_BinOp(a, Mod, b, EXTRA) } | a=term '@' b=factor { CHECK_VERSION(expr_ty, 5, "The '@' operator is", _PyAST_BinOp(a, MatMult, b, EXTRA)) } | factor factor[expr_ty] (memo): | '+' a=factor { _PyAST_UnaryOp(UAdd, a, EXTRA) } | '-' a=factor { _PyAST_UnaryOp(USub, a, EXTRA) } | '~' a=factor { _PyAST_UnaryOp(Invert, a, EXTRA) } | power | invalid_factor power[expr_ty]: | a=await_primary '**' b=factor { _PyAST_BinOp(a, Pow, b, EXTRA) } | await_primary # Primary elements # ---------------- # Primary elements are things like "obj.something.something", "obj[something]", "obj(something)", "obj" ... await_primary[expr_ty] (memo): | 'await' a=primary { CHECK_VERSION(expr_ty, 5, "Await expressions are", _PyAST_Await(a, EXTRA)) } | primary primary[expr_ty]: | a=primary '.' b=NAME { _PyAST_Attribute(a, b->v.Name.id, Load, EXTRA) } | a=primary b=genexp { _PyAST_Call(a, CHECK(asdl_expr_seq*, (asdl_expr_seq*)_PyPegen_singleton_seq(p, b)), NULL, EXTRA) } | a=primary '(' b=[arguments] ')' { _PyAST_Call(a, (b) ? ((expr_ty) b)->v.Call.args : NULL, (b) ? ((expr_ty) b)->v.Call.keywords : NULL, EXTRA) } | a=primary '[' b=slices ']' { _PyAST_Subscript(a, b, Load, EXTRA) } | atom slices[expr_ty]: | a=slice !',' { a } | a[asdl_expr_seq*]=','.(slice | starred_expression)+ [','] { _PyAST_Tuple(a, Load, EXTRA) } slice[expr_ty]: | a=[expression] ':' b=[expression] c=[':' d=[expression] { d }] { _PyAST_Slice(a, b, c, EXTRA) } | a=named_expression { a } atom[expr_ty]: | NAME | 'True' { _PyAST_Constant(Py_True, NULL, EXTRA) } | 'False' { _PyAST_Constant(Py_False, NULL, EXTRA) } | 'None' { _PyAST_Constant(Py_None, NULL, EXTRA) } | &(STRING|FSTRING_START|TSTRING_START) strings | NUMBER | &'(' (genexp | tuple | group) | &'[' (listcomp | list) | &'{' (dictcomp | setcomp | dict | set) | '...' { _PyAST_Constant(Py_Ellipsis, NULL, EXTRA) } group[expr_ty]: | '(' a=(yield_expr | named_expression) ')' { a } | invalid_group # Lambda functions # ---------------- lambdef[expr_ty]: | 'lambda' a=[lambda_params] ':' b=expression { _PyAST_Lambda((a) ? a : CHECK(arguments_ty, _PyPegen_empty_arguments(p)), b, EXTRA) } lambda_params[arguments_ty]: | invalid_lambda_parameters | lambda_parameters # lambda_parameters etc. duplicates parameters but without annotations # or type comments, and if there's no comma after a parameter, we expect # a colon, not a close parenthesis. (For more, see parameters above.) # lambda_parameters[arguments_ty]: | a=lambda_slash_no_default b[asdl_arg_seq*]=lambda_param_no_default* c=lambda_param_with_default* d=[lambda_star_etc] { CHECK_VERSION(arguments_ty, 8, "Positional-only parameters are", _PyPegen_make_arguments(p, a, NULL, b, c, d)) } | a=lambda_slash_with_default b=lambda_param_with_default* c=[lambda_star_etc] { CHECK_VERSION(arguments_ty, 8, "Positional-only parameters are", _PyPegen_make_arguments(p, NULL, a, NULL, b, c)) } | a[asdl_arg_seq*]=lambda_param_no_default+ b=lambda_param_with_default* c=[lambda_star_etc] { _PyPegen_make_arguments(p, NULL, NULL, a, b, c) } | a=lambda_param_with_default+ b=[lambda_star_etc] { _PyPegen_make_arguments(p, NULL, NULL, NULL, a, b)} | a=lambda_star_etc { _PyPegen_make_arguments(p, NULL, NULL, NULL, NULL, a) } lambda_slash_no_default[asdl_arg_seq*]: | a[asdl_arg_seq*]=lambda_param_no_default+ '/' ',' { a } | a[asdl_arg_seq*]=lambda_param_no_default+ '/' &':' { a } lambda_slash_with_default[SlashWithDefault*]: | a=lambda_param_no_default* b=lambda_param_with_default+ '/' ',' { _PyPegen_slash_with_default(p, (asdl_arg_seq *)a, b) } | a=lambda_param_no_default* b=lambda_param_with_default+ '/' &':' { _PyPegen_slash_with_default(p, (asdl_arg_seq *)a, b) } lambda_star_etc[StarEtc*]: | invalid_lambda_star_etc | '*' a=lambda_param_no_default b=lambda_param_maybe_default* c=[lambda_kwds] { _PyPegen_star_etc(p, a, b, c) } | '*' ',' b=lambda_param_maybe_default+ c=[lambda_kwds] { _PyPegen_star_etc(p, NULL, b, c) } | a=lambda_kwds { _PyPegen_star_etc(p, NULL, NULL, a) } lambda_kwds[arg_ty]: | invalid_lambda_kwds | '**' a=lambda_param_no_default { a } lambda_param_no_default[arg_ty]: | a=lambda_param ',' { a } | a=lambda_param &':' { a } lambda_param_with_default[NameDefaultPair*]: | a=lambda_param c=default ',' { _PyPegen_name_default_pair(p, a, c, NULL) } | a=lambda_param c=default &':' { _PyPegen_name_default_pair(p, a, c, NULL) } lambda_param_maybe_default[NameDefaultPair*]: | a=lambda_param c=default? ',' { _PyPegen_name_default_pair(p, a, c, NULL) } | a=lambda_param c=default? &':' { _PyPegen_name_default_pair(p, a, c, NULL) } lambda_param[arg_ty]: a=NAME { _PyAST_arg(a->v.Name.id, NULL, NULL, EXTRA) } # LITERALS # ======== fstring_middle[expr_ty]: | fstring_replacement_field | t=FSTRING_MIDDLE { _PyPegen_constant_from_token(p, t) } fstring_replacement_field[expr_ty]: | '{' a=annotated_rhs debug_expr='='? conversion=[fstring_conversion] format=[fstring_full_format_spec] rbrace='}' { _PyPegen_formatted_value(p, a, debug_expr, conversion, format, rbrace, EXTRA) } | invalid_fstring_replacement_field fstring_conversion[ResultTokenWithMetadata*]: | conv_token="!" conv=NAME { _PyPegen_check_fstring_conversion(p, conv_token, conv) } fstring_full_format_spec[ResultTokenWithMetadata*]: | colon=':' spec=fstring_format_spec* { _PyPegen_setup_full_format_spec(p, colon, (asdl_expr_seq *) spec, EXTRA) } fstring_format_spec[expr_ty]: | t=FSTRING_MIDDLE { _PyPegen_decoded_constant_from_token(p, t) } | fstring_replacement_field fstring[expr_ty]: | a=FSTRING_START b=fstring_middle* c=FSTRING_END { _PyPegen_joined_str(p, a, (asdl_expr_seq*)b, c) } tstring_format_spec_replacement_field[expr_ty]: | '{' a=annotated_rhs debug_expr='='? conversion=[fstring_conversion] format=[tstring_full_format_spec] rbrace='}' { _PyPegen_formatted_value(p, a, debug_expr, conversion, format, rbrace, EXTRA) } | invalid_tstring_replacement_field tstring_format_spec[expr_ty]: | t=TSTRING_MIDDLE { _PyPegen_decoded_constant_from_token(p, t) } | tstring_format_spec_replacement_field tstring_full_format_spec[ResultTokenWithMetadata*]: | colon=':' spec=tstring_format_spec* { _PyPegen_setup_full_format_spec(p, colon, (asdl_expr_seq *) spec, EXTRA) } tstring_replacement_field[expr_ty]: | '{' a=annotated_rhs debug_expr='='? conversion=[fstring_conversion] format=[tstring_full_format_spec] rbrace='}' { _PyPegen_interpolation(p, a, debug_expr, conversion, format, rbrace, EXTRA) } | invalid_tstring_replacement_field tstring_middle[expr_ty]: | tstring_replacement_field | t=TSTRING_MIDDLE { _PyPegen_constant_from_token(p, t) } tstring[expr_ty] (memo): | a=TSTRING_START b=tstring_middle* c=TSTRING_END { CHECK_VERSION( expr_ty, 14, "t-strings are", _PyPegen_template_str(p, a, (asdl_expr_seq*)b, c)) } string[expr_ty]: s[Token*]=STRING { _PyPegen_constant_from_string(p, s) } strings[expr_ty] (memo): | invalid_string_tstring_concat |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |