From cfb3beff8f8eae0d6126aca7b21bfb706af2bf82 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Tue, 25 Nov 2008 15:56:09 +0100 Subject: [PATCH] support 'yield' statement/expression in parser to provide at least a more meaningful error message for now --- Cython/Compiler/Parsing.py | 13 +++++++++++++ Cython/Compiler/Scanning.py | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py index 06c226d3..62461c75 100644 --- a/Cython/Compiler/Parsing.py +++ b/Cython/Compiler/Parsing.py @@ -269,6 +269,15 @@ def p_sizeof(s): s.expect(')') return node +def p_yield_expression(s): + # s.sy == "yield" + pos = s.position() + s.next() + if s.sy not in ('EOF', 'NEWLINE', ')'): + expr = p_expr(s) + s.error("generators ('yield') are not currently supported") + return Nodes.PassStatNode(pos) + #power: atom trailer* ('**' factor)* def p_power(s): @@ -473,6 +482,8 @@ def p_atom(s): s.next() if s.sy == ')': result = ExprNodes.TupleNode(pos, args = []) + elif s.sy == 'yield': + result = p_yield_expression(s) else: result = p_expr(s) s.expect(')') @@ -1355,6 +1366,8 @@ def p_simple_statement(s, first_statement = 0): node = p_import_statement(s) elif s.sy == 'from': node = p_from_import_statement(s, first_statement = first_statement) + elif s.sy == 'yield': + node = p_yield_expression(s) elif s.sy == 'assert': node = p_assert_statement(s) elif s.sy == 'pass': diff --git a/Cython/Compiler/Scanning.py b/Cython/Compiler/Scanning.py index ad620c26..e420fcfe 100644 --- a/Cython/Compiler/Scanning.py +++ b/Cython/Compiler/Scanning.py @@ -150,7 +150,7 @@ reserved_words = [ "print", "del", "pass", "break", "continue", "return", "raise", "import", "exec", "try", "except", "finally", "while", "if", "elif", "else", "for", "in", "assert", - "and", "or", "not", "is", "in", "lambda", "from", + "and", "or", "not", "is", "in", "lambda", "from", "yield", "cimport", "by", "with", "cpdef", "DEF", "IF", "ELIF", "ELSE" ] -- 2.26.2