]> crepu.dev Git - config.git/blame - djavu-asus/elpy/rpc-venv/lib/python3.11/site-packages/parso/python/grammar36.txt
ActualizaciĆ³n de Readme
[config.git] / djavu-asus / elpy / rpc-venv / lib / python3.11 / site-packages / parso / python / grammar36.txt
CommitLineData
53e6db90
DC
1# Grammar for Python
2
3# NOTE WELL: You should also follow all the steps listed at
4# https://docs.python.org/devguide/grammar.html
5
6# Start symbols for the grammar:
7# single_input is a single interactive statement;
8# file_input is a module or sequence of commands read from an input file;
9# eval_input is the input for the eval() functions.
10# NB: compound_stmt in single_input is followed by extra NEWLINE!
11single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE
12file_input: stmt* ENDMARKER
13eval_input: testlist NEWLINE* ENDMARKER
14decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE
15decorators: decorator+
16decorated: decorators (classdef | funcdef | async_funcdef)
17
18# NOTE: Francisco Souza/Reinoud Elhorst, using ASYNC/'await' keywords instead of
19# skipping python3.5+ compatibility, in favour of 3.7 solution
20async_funcdef: 'async' funcdef
21funcdef: 'def' NAME parameters ['->' test] ':' suite
22
23parameters: '(' [typedargslist] ')'
24typedargslist: (tfpdef ['=' test] (',' tfpdef ['=' test])* [',' [
25 '*' [tfpdef] (',' tfpdef ['=' test])* [',' ['**' tfpdef [',']]]
26 | '**' tfpdef [',']]]
27 | '*' [tfpdef] (',' tfpdef ['=' test])* [',' ['**' tfpdef [',']]]
28 | '**' tfpdef [','])
29tfpdef: NAME [':' test]
30varargslist: (vfpdef ['=' test] (',' vfpdef ['=' test])* [',' [
31 '*' [vfpdef] (',' vfpdef ['=' test])* [',' ['**' vfpdef [',']]]
32 | '**' vfpdef [',']]]
33 | '*' [vfpdef] (',' vfpdef ['=' test])* [',' ['**' vfpdef [',']]]
34 | '**' vfpdef [',']
35)
36vfpdef: NAME
37
38stmt: simple_stmt | compound_stmt | NEWLINE
39simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE
40small_stmt: (expr_stmt | del_stmt | pass_stmt | flow_stmt |
41 import_stmt | global_stmt | nonlocal_stmt | assert_stmt)
42expr_stmt: testlist_star_expr (annassign | augassign (yield_expr|testlist) |
43 ('=' (yield_expr|testlist_star_expr))*)
44annassign: ':' test ['=' test]
45testlist_star_expr: (test|star_expr) (',' (test|star_expr))* [',']
46augassign: ('+=' | '-=' | '*=' | '@=' | '/=' | '%=' | '&=' | '|=' | '^=' |
47 '<<=' | '>>=' | '**=' | '//=')
48# For normal and annotated assignments, additional restrictions enforced by the interpreter
49del_stmt: 'del' exprlist
50pass_stmt: 'pass'
51flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt | yield_stmt
52break_stmt: 'break'
53continue_stmt: 'continue'
54return_stmt: 'return' [testlist]
55yield_stmt: yield_expr
56raise_stmt: 'raise' [test ['from' test]]
57import_stmt: import_name | import_from
58import_name: 'import' dotted_as_names
59# note below: the ('.' | '...') is necessary because '...' is tokenized as ELLIPSIS
60import_from: ('from' (('.' | '...')* dotted_name | ('.' | '...')+)
61 'import' ('*' | '(' import_as_names ')' | import_as_names))
62import_as_name: NAME ['as' NAME]
63dotted_as_name: dotted_name ['as' NAME]
64import_as_names: import_as_name (',' import_as_name)* [',']
65dotted_as_names: dotted_as_name (',' dotted_as_name)*
66dotted_name: NAME ('.' NAME)*
67global_stmt: 'global' NAME (',' NAME)*
68nonlocal_stmt: 'nonlocal' NAME (',' NAME)*
69assert_stmt: 'assert' test [',' test]
70
71compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef | classdef | decorated | async_stmt
72async_stmt: 'async' (funcdef | with_stmt | for_stmt)
73if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite]
74while_stmt: 'while' test ':' suite ['else' ':' suite]
75for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite]
76try_stmt: ('try' ':' suite
77 ((except_clause ':' suite)+
78 ['else' ':' suite]
79 ['finally' ':' suite] |
80 'finally' ':' suite))
81with_stmt: 'with' with_item (',' with_item)* ':' suite
82with_item: test ['as' expr]
83# NB compile.c makes sure that the default except clause is last
84except_clause: 'except' [test ['as' NAME]]
85suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT
86
87test: or_test ['if' or_test 'else' test] | lambdef
88test_nocond: or_test | lambdef_nocond
89lambdef: 'lambda' [varargslist] ':' test
90lambdef_nocond: 'lambda' [varargslist] ':' test_nocond
91or_test: and_test ('or' and_test)*
92and_test: not_test ('and' not_test)*
93not_test: 'not' not_test | comparison
94comparison: expr (comp_op expr)*
95# <> isn't actually a valid comparison operator in Python. It's here for the
96# sake of a __future__ import described in PEP 401 (which really works :-)
97comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not'
98star_expr: '*' expr
99expr: xor_expr ('|' xor_expr)*
100xor_expr: and_expr ('^' and_expr)*
101and_expr: shift_expr ('&' shift_expr)*
102shift_expr: arith_expr (('<<'|'>>') arith_expr)*
103arith_expr: term (('+'|'-') term)*
104term: factor (('*'|'@'|'/'|'%'|'//') factor)*
105factor: ('+'|'-'|'~') factor | power
106power: atom_expr ['**' factor]
107atom_expr: ['await'] atom trailer*
108atom: ('(' [yield_expr|testlist_comp] ')' |
109 '[' [testlist_comp] ']' |
110 '{' [dictorsetmaker] '}' |
111 NAME | NUMBER | strings | '...' | 'None' | 'True' | 'False')
112testlist_comp: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] )
113trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
114subscriptlist: subscript (',' subscript)* [',']
115subscript: test | [test] ':' [test] [sliceop]
116sliceop: ':' [test]
117exprlist: (expr|star_expr) (',' (expr|star_expr))* [',']
118testlist: test (',' test)* [',']
119dictorsetmaker: ( ((test ':' test | '**' expr)
120 (comp_for | (',' (test ':' test | '**' expr))* [','])) |
121 ((test | star_expr)
122 (comp_for | (',' (test | star_expr))* [','])) )
123
124classdef: 'class' NAME ['(' [arglist] ')'] ':' suite
125
126arglist: argument (',' argument)* [',']
127
128# The reason that keywords are test nodes instead of NAME is that using NAME
129# results in an ambiguity. ast.c makes sure it's a NAME.
130# "test '=' test" is really "keyword '=' test", but we have no such token.
131# These need to be in a single rule to avoid grammar that is ambiguous
132# to our LL(1) parser. Even though 'test' includes '*expr' in star_expr,
133# we explicitly match '*' here, too, to give it proper precedence.
134# Illegal combinations and orderings are blocked in ast.c:
135# multiple (test comp_for) arguments are blocked; keyword unpackings
136# that precede iterable unpackings are blocked; etc.
137argument: ( test [comp_for] |
138 test '=' test |
139 '**' test |
140 '*' test )
141
142comp_iter: comp_for | comp_if
143sync_comp_for: 'for' exprlist 'in' or_test [comp_iter]
144comp_for: ['async'] sync_comp_for
145comp_if: 'if' test_nocond [comp_iter]
146
147# not used in grammar, but may appear in "node" passed from Parser to Compiler
148encoding_decl: NAME
149
150yield_expr: 'yield' [yield_arg]
151yield_arg: 'from' test | testlist
152
153strings: (STRING | fstring)+
154fstring: FSTRING_START fstring_content* FSTRING_END
155fstring_content: FSTRING_STRING | fstring_expr
156fstring_conversion: '!' NAME
157fstring_expr: '{' (testlist_comp | yield_expr) [ fstring_conversion ] [ fstring_format_spec ] '}'
158fstring_format_spec: ':' fstring_content*