]> git.proxmox.com Git - mirror_edk2.git/blame - AppPkg/Applications/Python/Python-2.7.2/Lib/lib2to3/Grammar.txt
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.2 / Lib / lib2to3 / Grammar.txt
CommitLineData
4710c53d 1# Grammar for Python\r
2\r
3# Note: Changing the grammar specified in this file will most likely\r
4# require corresponding changes in the parser module\r
5# (../Modules/parsermodule.c). If you can't make the changes to\r
6# that module yourself, please co-ordinate the required changes\r
7# with someone who can; ask around on python-dev for help. Fred\r
8# Drake <fdrake@acm.org> will probably be listening there.\r
9\r
10# NOTE WELL: You should also follow all the steps listed in PEP 306,\r
11# "How to Change Python's Grammar"\r
12\r
13# Commands for Kees Blom's railroad program\r
14#diagram:token NAME\r
15#diagram:token NUMBER\r
16#diagram:token STRING\r
17#diagram:token NEWLINE\r
18#diagram:token ENDMARKER\r
19#diagram:token INDENT\r
20#diagram:output\input python.bla\r
21#diagram:token DEDENT\r
22#diagram:output\textwidth 20.04cm\oddsidemargin 0.0cm\evensidemargin 0.0cm\r
23#diagram:rules\r
24\r
25# Start symbols for the grammar:\r
26# file_input is a module or sequence of commands read from an input file;\r
27# single_input is a single interactive statement;\r
28# eval_input is the input for the eval() and input() functions.\r
29# NB: compound_stmt in single_input is followed by extra NEWLINE!\r
30file_input: (NEWLINE | stmt)* ENDMARKER\r
31single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE\r
32eval_input: testlist NEWLINE* ENDMARKER\r
33\r
34decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE\r
35decorators: decorator+\r
36decorated: decorators (classdef | funcdef)\r
37funcdef: 'def' NAME parameters ['->' test] ':' suite\r
38parameters: '(' [typedargslist] ')'\r
39typedargslist: ((tfpdef ['=' test] ',')*\r
40 ('*' [tname] (',' tname ['=' test])* [',' '**' tname] | '**' tname)\r
41 | tfpdef ['=' test] (',' tfpdef ['=' test])* [','])\r
42tname: NAME [':' test]\r
43tfpdef: tname | '(' tfplist ')'\r
44tfplist: tfpdef (',' tfpdef)* [',']\r
45varargslist: ((vfpdef ['=' test] ',')*\r
46 ('*' [vname] (',' vname ['=' test])* [',' '**' vname] | '**' vname)\r
47 | vfpdef ['=' test] (',' vfpdef ['=' test])* [','])\r
48vname: NAME\r
49vfpdef: vname | '(' vfplist ')'\r
50vfplist: vfpdef (',' vfpdef)* [',']\r
51\r
52stmt: simple_stmt | compound_stmt\r
53simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE\r
54small_stmt: (expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt |\r
55 import_stmt | global_stmt | exec_stmt | assert_stmt)\r
56expr_stmt: testlist_star_expr (augassign (yield_expr|testlist) |\r
57 ('=' (yield_expr|testlist_star_expr))*)\r
58testlist_star_expr: (test|star_expr) (',' (test|star_expr))* [',']\r
59augassign: ('+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^=' |\r
60 '<<=' | '>>=' | '**=' | '//=')\r
61# For normal assignments, additional restrictions enforced by the interpreter\r
62print_stmt: 'print' ( [ test (',' test)* [','] ] |\r
63 '>>' test [ (',' test)+ [','] ] )\r
64del_stmt: 'del' exprlist\r
65pass_stmt: 'pass'\r
66flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt | yield_stmt\r
67break_stmt: 'break'\r
68continue_stmt: 'continue'\r
69return_stmt: 'return' [testlist]\r
70yield_stmt: yield_expr\r
71raise_stmt: 'raise' [test ['from' test | ',' test [',' test]]]\r
72import_stmt: import_name | import_from\r
73import_name: 'import' dotted_as_names\r
74import_from: ('from' ('.'* dotted_name | '.'+)\r
75 'import' ('*' | '(' import_as_names ')' | import_as_names))\r
76import_as_name: NAME ['as' NAME]\r
77dotted_as_name: dotted_name ['as' NAME]\r
78import_as_names: import_as_name (',' import_as_name)* [',']\r
79dotted_as_names: dotted_as_name (',' dotted_as_name)*\r
80dotted_name: NAME ('.' NAME)*\r
81global_stmt: ('global' | 'nonlocal') NAME (',' NAME)*\r
82exec_stmt: 'exec' expr ['in' test [',' test]]\r
83assert_stmt: 'assert' test [',' test]\r
84\r
85compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef | classdef | decorated\r
86if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite]\r
87while_stmt: 'while' test ':' suite ['else' ':' suite]\r
88for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite]\r
89try_stmt: ('try' ':' suite\r
90 ((except_clause ':' suite)+\r
91 ['else' ':' suite]\r
92 ['finally' ':' suite] |\r
93 'finally' ':' suite))\r
94with_stmt: 'with' with_item (',' with_item)* ':' suite\r
95with_item: test ['as' expr]\r
96with_var: 'as' expr\r
97# NB compile.c makes sure that the default except clause is last\r
98except_clause: 'except' [test [(',' | 'as') test]]\r
99suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT\r
100\r
101# Backward compatibility cruft to support:\r
102# [ x for x in lambda: True, lambda: False if x() ]\r
103# even while also allowing:\r
104# lambda x: 5 if x else 2\r
105# (But not a mix of the two)\r
106testlist_safe: old_test [(',' old_test)+ [',']]\r
107old_test: or_test | old_lambdef\r
108old_lambdef: 'lambda' [varargslist] ':' old_test\r
109\r
110test: or_test ['if' or_test 'else' test] | lambdef\r
111or_test: and_test ('or' and_test)*\r
112and_test: not_test ('and' not_test)*\r
113not_test: 'not' not_test | comparison\r
114comparison: expr (comp_op expr)*\r
115comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not'\r
116star_expr: '*' expr\r
117expr: xor_expr ('|' xor_expr)*\r
118xor_expr: and_expr ('^' and_expr)*\r
119and_expr: shift_expr ('&' shift_expr)*\r
120shift_expr: arith_expr (('<<'|'>>') arith_expr)*\r
121arith_expr: term (('+'|'-') term)*\r
122term: factor (('*'|'/'|'%'|'//') factor)*\r
123factor: ('+'|'-'|'~') factor | power\r
124power: atom trailer* ['**' factor]\r
125atom: ('(' [yield_expr|testlist_gexp] ')' |\r
126 '[' [listmaker] ']' |\r
127 '{' [dictsetmaker] '}' |\r
128 '`' testlist1 '`' |\r
129 NAME | NUMBER | STRING+ | '.' '.' '.')\r
130listmaker: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] )\r
131testlist_gexp: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] )\r
132lambdef: 'lambda' [varargslist] ':' test\r
133trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME\r
134subscriptlist: subscript (',' subscript)* [',']\r
135subscript: test | [test] ':' [test] [sliceop]\r
136sliceop: ':' [test]\r
137exprlist: (expr|star_expr) (',' (expr|star_expr))* [',']\r
138testlist: test (',' test)* [',']\r
139dictsetmaker: ( (test ':' test (comp_for | (',' test ':' test)* [','])) |\r
140 (test (comp_for | (',' test)* [','])) )\r
141\r
142classdef: 'class' NAME ['(' [arglist] ')'] ':' suite\r
143\r
144arglist: (argument ',')* (argument [',']\r
145 |'*' test (',' argument)* [',' '**' test] \r
146 |'**' test)\r
147argument: test [comp_for] | test '=' test # Really [keyword '='] test\r
148\r
149comp_iter: comp_for | comp_if\r
150comp_for: 'for' exprlist 'in' testlist_safe [comp_iter]\r
151comp_if: 'if' old_test [comp_iter]\r
152\r
153testlist1: test (',' test)*\r
154\r
155# not used in grammar, but may appear in "node" passed from Parser to Compiler\r
156encoding_decl: NAME\r
157\r
158yield_expr: 'yield' [testlist]\r