From: Stefan Behnel Date: Tue, 25 Nov 2008 14:56:09 +0000 (+0100) Subject: support 'yield' statement/expression in parser to provide at least a more meaningful... X-Git-Tag: 0.11-beta~220 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=cfb3beff8f8eae0d6126aca7b21bfb706af2bf82;p=cython.git support 'yield' statement/expression in parser to provide at least a more meaningful error message for now --- 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" ]