Commit d3e1ddfc authored by Robert Bradshaw's avatar Robert Bradshaw

Accept new for-from syntax.

parent 2eb59542
...@@ -1080,9 +1080,13 @@ def p_for_bounds(s): ...@@ -1080,9 +1080,13 @@ def p_for_bounds(s):
s.next() s.next()
iterator = p_for_iterator(s) iterator = p_for_iterator(s)
return { 'target': target, 'iterator': iterator } return { 'target': target, 'iterator': iterator }
elif s.sy == 'from': else:
s.next() if s.sy == 'from':
bound1 = p_bit_expr(s) s.next()
bound1 = p_bit_expr(s)
else:
# Support shorter "for a <= x < b" syntax
bound1, target = target, None
rel1 = p_for_from_relation(s) rel1 = p_for_from_relation(s)
name2_pos = s.position() name2_pos = s.position()
name2 = p_ident(s) name2 = p_ident(s)
...@@ -1090,12 +1094,15 @@ def p_for_bounds(s): ...@@ -1090,12 +1094,15 @@ def p_for_bounds(s):
rel2 = p_for_from_relation(s) rel2 = p_for_from_relation(s)
bound2 = p_bit_expr(s) bound2 = p_bit_expr(s)
step = p_for_from_step(s) step = p_for_from_step(s)
if not target.is_name: if target is None:
error(target.pos, target = ExprNodes.NameNode(name2_pos, name = name2)
"Target of for-from statement must be a variable name") else:
elif name2 != target.name: if not target.is_name:
error(name2_pos, error(target.pos,
"Variable name in for-from range does not match target") "Target of for-from statement must be a variable name")
elif name2 != target.name:
error(name2_pos,
"Variable name in for-from range does not match target")
if rel1[0] != rel2[0]: if rel1[0] != rel2[0]:
error(rel2_pos, error(rel2_pos,
"Relation directions in for-from do not match") "Relation directions in for-from do not match")
...@@ -1105,8 +1112,6 @@ def p_for_bounds(s): ...@@ -1105,8 +1112,6 @@ def p_for_bounds(s):
'relation2': rel2, 'relation2': rel2,
'bound2': bound2, 'bound2': bound2,
'step': step } 'step': step }
else:
s.error("Expected 'in' or 'from'")
def p_for_from_relation(s): def p_for_from_relation(s):
if s.sy in inequality_relations: if s.sy in inequality_relations:
......
...@@ -5,3 +5,8 @@ cdef void spam(): ...@@ -5,3 +5,8 @@ cdef void spam():
else: else:
k = j k = j
# new syntax
for 0 <= i < 10:
j = i
else:
j = k
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment