support 'yield' statement/expression in parser to provide at least a more meaningful...
authorStefan Behnel <scoder@users.berlios.de>
Tue, 25 Nov 2008 14:56:09 +0000 (15:56 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Tue, 25 Nov 2008 14:56:09 +0000 (15:56 +0100)
Cython/Compiler/Parsing.py
Cython/Compiler/Scanning.py

index 06c226d3c2f4d556f93cc25e8621a0c48d82713d..62461c7542340e3bae019f86e3a116df7df83a08 100644 (file)
@@ -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':
index ad620c260e3c94ff41d3b93b1e6004cadd4c5547..e420fcfec58b933d8cfbc37c680aa842c4c8031f 100644 (file)
@@ -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"
 ]