Skip to content

Commit 09ba8d0

Browse files
committed
Add print statement, as example of soft keywords
1 parent d55a0af commit 09ba8d0

File tree

2 files changed

+1132
-907
lines changed

2 files changed

+1132
-907
lines changed

Grammar/python.gram

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ simple_stmt[asdl_seq*]:
6060
# will throw a SyntaxError.
6161
small_stmt[stmt_ty] (memo):
6262
| assignment
63-
| e=star_expressions { _Py_Expr(e, EXTRA) }
63+
| e=star_expressions &(';' | NEWLINE) { _Py_Expr(e, EXTRA) }
6464
| &'return' return_stmt
6565
| &('import' | 'from') import_stmt
6666
| &'raise' raise_stmt
@@ -72,6 +72,7 @@ small_stmt[stmt_ty] (memo):
7272
| 'continue' { _Py_Continue(EXTRA) }
7373
| &'global' global_stmt
7474
| &'nonlocal' nonlocal_stmt
75+
| print_stmt
7576
compound_stmt[stmt_ty]:
7677
| &('def' | '@' | ASYNC) function_def
7778
| &'if' if_stmt
@@ -81,6 +82,13 @@ compound_stmt[stmt_ty]:
8182
| &'try' try_stmt
8283
| &'while' while_stmt
8384

85+
# Another easter egg
86+
print_stmt[stmt_ty]:
87+
| a="print" b=','.expression+ [','] {
88+
_Py_Expr(
89+
_Py_Call(a, b, NULL, EXTRA),
90+
EXTRA) }
91+
8492
# NOTE: annotated_rhs may start with 'yield'; yield_expr must start with 'yield'
8593
assignment[stmt_ty]:
8694
| a=NAME ':' b=expression c=['=' d=annotated_rhs { d }] {

0 commit comments

Comments
 (0)