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