The cst module translates Python grammar rules into functions that can
be combined in order to create Python CSTs expressed in list form. The
specification of each function is therefore determined by the grammar
rule string. This can be retrieved from the docstring.
When the compound_stmt node is added you shall not add the NEWLINE
node as well because the presence can be deduced by the function from the
grammar rule.
Any rule function checks each input node. They are implemented to be
NOT redundancy tolerant i.e. each terminal py_symbol that can be omitted
shall be omitted. Only those terminals that are necessary to establish
more context information are mandatory.
|
|
toText(node_id)
Returns textual representation of a node id. |
|
|
|
|
py_cst(f)
Decorator used to filter arguments of cst module functions on
langlet-specific nodes. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
single_input(*args)
single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE |
|
|
|
|
file_input(*args)
file_input: (NEWLINE | stmt)* ENDMARKER |
|
|
|
|
eval_input(*args)
eval_input: testlist NEWLINE* ENDMARKER |
|
|
|
|
decorator(*args)
decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE |
|
|
|
|
|
|
|
funcdef(*args)
funcdef: [decorators] 'def' NAME parameters ':' suite |
|
|
|
|
parameters(*args)
parameters: '(' [varargslist] ')' |
|
|
|
|
varargslist(*args)
varargslist: (fpdef ['=' test] ',')* ('*' NAME [',' '**' NAME] | '**'
NAME) | fpdef ['=' test] (',' fpdef ['=' test])* [','] |
|
|
|
|
fpdef(*args)
fpdef: NAME | '(' fplist ')' |
|
|
|
|
fplist(*args)
fplist: fpdef (',' fpdef)* [','] |
|
|
|
|
stmt(*args)
stmt: simple_stmt | compound_stmt |
|
|
|
|
simple_stmt(*args)
simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE |
|
|
|
|
small_stmt(*args)
small_stmt: expr_stmt | print_stmt | del_stmt | pass_stmt |
flow_stmt | import_stmt | global_stmt | exec_stmt | assert_stmt |
|
|
|
|
expr_stmt(*args)
expr_stmt: testlist (augassign testlist | ('=' testlist)*) |
|
|
|
|
augassign(*args)
augassign: '+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^='
| '<<=' | '>>=' | '**=' | '//=' |
|
|
|
|
print_stmt(*args)
print_stmt: 'print' ( '>>' test [ (',' test)+ [','] ] | [ test
(',' test)* [','] ] ) |
|
|
|
|
del_stmt(*args)
del_stmt: 'del' exprlist |
|
|
|
|
|
|
|
flow_stmt(*args)
flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt |
yield_stmt |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
raise_stmt(*args)
raise_stmt: 'raise' [test [',' test [',' test]]] |
|
|
|
|
import_stmt(*args)
import_stmt: import_name | import_from |
|
|
|
|
import_name(*args)
import_name: 'import' dotted_as_names |
|
|
|
|
import_from(*args)
import_from: ('from' ('.'* dotted_name | '.'+) 'import' ('*' | '('
import_as_names ')' | import_as_names)) |
|
|
|
|
|
|
|
import_as_names(*args)
import_as_names: import_as_name (',' import_as_name)* [','] |
|
|
|
|
|
|
|
dotted_as_names(*args)
dotted_as_names: dotted_as_name (',' dotted_as_name)* |
|
|
|
|
|
|
|
global_stmt(*args)
global_stmt: 'global' NAME (',' NAME)* |
|
|
|
|
assert_stmt(*args)
assert_stmt: 'assert' test [',' test] |
|
|
|
|
exec_stmt(*args)
exec_stmt: 'exec' expr ['in' test [',' test]] |
|
|
|
|
compound_stmt(*args)
compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | funcdef |
classdef |
|
|
|
|
if_stmt(*args)
if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':'
suite] |
|
|
|
|
while_stmt(*args)
while_stmt: 'while' test ':' suite ['else' ':' suite] |
|
|
|
|
for_stmt(*args)
for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite] |
|
|
|
|
try_stmt(*args)
try_stmt: ('try' ':' suite (except_clause ':' suite)+ ['else' ':'
suite] ['finally' ':' suite] | 'try' ':' suite 'finally' ':' suite) |
|
|
|
|
with_stmt(*args)
with_stmt: 'with' test [ with_var ] ':' suite |
|
|
|
|
with_var(*args)
with_var: ('as' | NAME) expr |
|
|
|
|
|
|
|
suite(*args)
suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
old_test(*args)
old_test: or_test | old_lambdef |
|
|
|
|
old_lambdef(*args)
old_lambdef: 'lambda' [varargslist] ':' old_test |
|
|
|
|
test(*args)
test: or_test ['if' or_test 'else' test] | lambdef |
|
|
|
|
or_test(*args)
or_test: and_test ('or' and_test)* |
|
|
|
|
testlist(*args)
testlist: test (',' test)* [','] |
|
|
|
|
testlist_safe(*args)
testlist_safe: old_test [(',' old_test)+ [',']] |
|
|
|
|
and_test(*args)
and_test: not_test ('and' not_test)* |
|
|
|
|
not_test(*args)
not_test: 'not' not_test | comparison |
|
|
|
|
|
|
|
comparison(*args)
comparison: expr (comp_op expr)* |
|
|
|
|
expr(*args)
expr: xor_expr ('|' xor_expr)* |
|
|
|
|
xor_expr(*args)
xor_expr: and_expr ('^' and_expr)* |
|
|
|
|
and_expr(*args)
and_expr: shift_expr ('&' shift_expr)* |
|
|
|
|
shift_expr(*args)
shift_expr: arith_expr (('<<'|'>>') arith_expr)* |
|
|
|
|
arith_expr(*args)
arith_expr: term (('+'|'-') term)* |
|
|
|
|
term(*args)
term: factor (('*'|'/'|'%'|'//') factor)* |
|
|
|
|
factor(*args)
factor: ('+'|'-'|'~') factor | power |
|
|
|
|
power(*args)
power: atom trailer* ['**' factor] |
|
|
|
|
atom(*args)
atom: '(' [testlist_gexp | yield_expr] ')' | '[' [listmaker] ']' |
'{' [dictmaker] '}' | '`' testlist1 '`' | NAME | NUMBER | STRING+ |
|
|
|
|
exprlist(*args)
exprlist: expr (',' expr)* [','] |
|
|
|
|
lambdef(*args)
lambdef: 'lambda' [varargslist] ':' test |
|
|
|
|
|
|
|
listmaker(*args)
listmaker: test ( list_for | (',' test)* [','] ) |
|
|
|
|
trailer(*args)
trailer : '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME |
|
|
|
|
dictmaker(*args)
dictmaker: test ':' test (',' test ':' test)* [','] |
|
|
|
|
subscriptlist(*args)
subscriptlist: subscript (',' subscript)* [','] |
|
|
|
|
subscript(*args)
subscript: '.' '.' '.' | [test] ':' [test] [sliceop] | test |
|
|
|
|
|
|
|
classdef(*args)
classdef: 'class' NAME ['(' testlist ')'] ':' suite |
|
|
|
|
arglist(*args)
arglist: (argument ',')* (argument [',']| '*' test [',' '**' test] |
'**' test) |
|
|
|
|
argument(*args)
argument: test [gen_for] | test '=' test |
|
|
|
|
list_iter(*args)
list_iter: list_for | list_if |
|
|
|
|
list_for(*args)
list_for: 'for' exprlist 'in' testlist_safe [list_iter] |
|
|
|
|
list_if(*args)
list_if: 'if' old_test [list_iter] |
|
|
|
|
gen_iter(*args)
gen_iter: gen_for | gen_if |
|
|
|
|
gen_for(*args)
gen_for: 'for' exprlist 'in' or_test [gen_iter] |
|
|
|
|
gen_if(*args)
gen_if: 'if' old_test [gen_iter] |
|
|
|
|
|