| OLD | NEW |
| 1 # Grammar for Python | 1 # Grammar for Python |
| 2 | 2 |
| 3 # Note: Changing the grammar specified in this file will most likely | 3 # Note: Changing the grammar specified in this file will most likely |
| 4 # require corresponding changes in the parser module | 4 # require corresponding changes in the parser module |
| 5 # (../Modules/parsermodule.c). If you can't make the changes to | 5 # (../Modules/parsermodule.c). If you can't make the changes to |
| 6 # that module yourself, please co-ordinate the required changes | 6 # that module yourself, please co-ordinate the required changes |
| 7 # with someone who can; ask around on python-dev for help. Fred | 7 # with someone who can; ask around on python-dev for help. Fred |
| 8 # Drake <[email protected]> will probably be listening there. | 8 # Drake <[email protected]> will probably be listening there. |
| 9 | 9 |
| 10 # NOTE WELL: You should also follow all the steps listed in PEP 306, | 10 # NOTE WELL: You should also follow all the steps listed in PEP 306, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 | 76 |
| 77 compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef
| classdef | decorated | 77 compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef
| classdef | decorated |
| 78 if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite] | 78 if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite] |
| 79 while_stmt: 'while' test ':' suite ['else' ':' suite] | 79 while_stmt: 'while' test ':' suite ['else' ':' suite] |
| 80 for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite] | 80 for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite] |
| 81 try_stmt: ('try' ':' suite | 81 try_stmt: ('try' ':' suite |
| 82 ((except_clause ':' suite)+ | 82 ((except_clause ':' suite)+ |
| 83 ['else' ':' suite] | 83 ['else' ':' suite] |
| 84 ['finally' ':' suite] | | 84 ['finally' ':' suite] | |
| 85 'finally' ':' suite)) | 85 'finally' ':' suite)) |
| 86 with_stmt: 'with' test [ with_var ] ':' suite | 86 with_stmt: 'with' with_item (',' with_item)* ':' suite |
| 87 with_var: 'as' expr | 87 with_item: test ['as' expr] |
| 88 # NB compile.c makes sure that the default except clause is last | 88 # NB compile.c makes sure that the default except clause is last |
| 89 except_clause: 'except' [test [('as' | ',') test]] | 89 except_clause: 'except' [test [('as' | ',') test]] |
| 90 suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT | 90 suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT |
| 91 | 91 |
| 92 # Backward compatibility cruft to support: | 92 # Backward compatibility cruft to support: |
| 93 # [ x for x in lambda: True, lambda: False if x() ] | 93 # [ x for x in lambda: True, lambda: False if x() ] |
| 94 # even while also allowing: | 94 # even while also allowing: |
| 95 # lambda x: 5 if x else 2 | 95 # lambda x: 5 if x else 2 |
| 96 # (But not a mix of the two) | 96 # (But not a mix of the two) |
| 97 testlist_safe: old_test [(',' old_test)+ [',']] | 97 testlist_safe: old_test [(',' old_test)+ [',']] |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 gen_iter: gen_for | gen_if | 142 gen_iter: gen_for | gen_if |
| 143 gen_for: 'for' exprlist 'in' or_test [gen_iter] | 143 gen_for: 'for' exprlist 'in' or_test [gen_iter] |
| 144 gen_if: 'if' old_test [gen_iter] | 144 gen_if: 'if' old_test [gen_iter] |
| 145 | 145 |
| 146 testlist1: test (',' test)* | 146 testlist1: test (',' test)* |
| 147 | 147 |
| 148 # not used in grammar, but may appear in "node" passed from Parser to Compiler | 148 # not used in grammar, but may appear in "node" passed from Parser to Compiler |
| 149 encoding_decl: NAME | 149 encoding_decl: NAME |
| 150 | 150 |
| 151 yield_expr: 'yield' [testlist] | 151 yield_expr: 'yield' [testlist] |
| OLD | NEW |