Skip to content

Commit 3997be4

Browse files
committed
Add single_input rule to grammar, for REPL.
1 parent 9f770c6 commit 3997be4

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

py/grammar.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
// # single_input is a single interactive statement;
77
// # file_input is a module or sequence of commands read from an input file;
88
// # eval_input is the input for the eval() functions.
9-
// # NB: compound_stmt in single_input is followed by extra NEWLINE!
10-
// single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE
9+
// # NB: compound_stmt in single_input is followed by extra NEWLINE! --> not in Micropython
10+
// single_input: NEWLINE | simple_stmt | compound_stmt
1111
// file_input: (NEWLINE | stmt)* ENDMARKER
1212
// eval_input: testlist NEWLINE* ENDMARKER
1313

14+
DEF_RULE(single_input, nc, or(3), tok(NEWLINE), rule(simple_stmt), rule(compound_stmt))
1415
DEF_RULE(file_input, nc, and(1), opt_rule(file_input_2))
1516
DEF_RULE(file_input_2, c(generic_all_nodes), one_or_more, rule(file_input_3))
1617
DEF_RULE(file_input_3, nc, or(2), tok(NEWLINE), rule(stmt))
@@ -129,6 +130,7 @@ DEF_RULE(name_list, nc, list, tok(NAME), tok(DEL_COMMA))
129130
DEF_RULE(assert_stmt, c(assert_stmt), and(3), tok(KW_ASSERT), rule(test), opt_rule(assert_stmt_extra))
130131
DEF_RULE(assert_stmt_extra, nc, and(2), tok(DEL_COMMA), rule(test))
131132

133+
// compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef | classdef | decorated
132134
// if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite]
133135
// while_stmt: 'while' test ':' suite ['else' ':' suite]
134136
// for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite]
@@ -139,6 +141,7 @@ DEF_RULE(assert_stmt_extra, nc, and(2), tok(DEL_COMMA), rule(test))
139141
// with_item: test ['as' expr]
140142
// suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT
141143

144+
DEF_RULE(compound_stmt, nc, or(8), rule(if_stmt), rule(while_stmt), rule(for_stmt), rule(try_stmt), rule(with_stmt), rule(funcdef), rule(classdef), rule(decorated))
142145
DEF_RULE(if_stmt, c(if_stmt), and(6), tok(KW_IF), rule(test), tok(DEL_COLON), rule(suite), opt_rule(if_stmt_elif_list), opt_rule(else_stmt))
143146
DEF_RULE(if_stmt_elif_list, nc, one_or_more, rule(if_stmt_elif))
144147
DEF_RULE(if_stmt_elif, nc, and(4), tok(KW_ELIF), rule(test), tok(DEL_COLON), rule(suite))

0 commit comments

Comments
 (0)