mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-01-14 01:07:55 -05:00
fixing precedence order, so that you can nest range comprehensions
This commit is contained in:
@@ -32,7 +32,8 @@ prechigh
|
||||
left '.'
|
||||
right INDENT
|
||||
left OUTDENT
|
||||
right THROW FOR IN WHILE WHEN NEW SUPER ELSE
|
||||
right WHEN IN
|
||||
right THROW FOR WHILE NEW SUPER ELSE
|
||||
left UNLESS EXTENDS IF
|
||||
left ASSIGN '||=' '&&='
|
||||
right RETURN '=>'
|
||||
|
||||
@@ -360,10 +360,11 @@ module CoffeeScript
|
||||
write("#{idt}#{@from_var} = #{from_val};\n#{idt}#{@to_var} = #{to_val};\n#{idt}")
|
||||
end
|
||||
|
||||
def compile(o, fv)
|
||||
vars = "#{fv}=#{@from_var}"
|
||||
compare = "(#{@from_var} <= #{@to_var} ? #{fv} #{less_operator} #{@to_var} : #{fv} #{greater_operator} #{@to_var})"
|
||||
incr = "(#{@from_var} <= #{@to_var} ? #{fv} += 1 : #{fv} -= 1)"
|
||||
def compile(o, idx=nil)
|
||||
raise SyntaxError, "unexpected range literal" unless idx
|
||||
vars = "#{idx}=#{@from_var}"
|
||||
compare = "(#{@from_var} <= #{@to_var} ? #{idx} #{less_operator} #{@to_var} : #{idx} #{greater_operator} #{@to_var})"
|
||||
incr = "(#{@from_var} <= #{@to_var} ? #{idx} += 1 : #{idx} -= 1)"
|
||||
write("#{vars}; #{compare}; #{incr}")
|
||||
end
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
11
test/fixtures/execution/test_nested_comprehensions.coffee
vendored
Normal file
11
test/fixtures/execution/test_nested_comprehensions.coffee
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
multi_liner:
|
||||
for x in [3..5]
|
||||
for y in [3..5]
|
||||
[x, y]
|
||||
|
||||
single_liner:
|
||||
[x, y] for y in [3..5] for x in [3..5]
|
||||
|
||||
print(multi_liner.length is single_liner.length)
|
||||
print(5 is multi_liner[2][2][1])
|
||||
print(5 is single_liner[2][2][1])
|
||||
Reference in New Issue
Block a user