Permalink
Browse files

simplify [:case, ...] expression

  • Loading branch information...
1 parent 509a262 commit 3dd4600e23c23a36f7f5e4f25e06c2ea2fdd7043 @minad minad committed Sep 26, 2012
@@ -20,9 +20,8 @@ def on_if(condition, yes, no = nil)
def on_case(arg, *cases)
result = [:multi, [:code, arg ? "case (#{arg})" : 'case']]
cases.map do |c|
- condition, *exps = c
- result << [:code, condition == :else ? 'else' : "when #{condition}"]
- exps.each {|e| result << compile(e) }
+ condition, exp = c
+ result << [:code, condition == :else ? 'else' : "when #{condition}"] << compile(exp)
end
result << [:code, 'end']
result
View
@@ -44,7 +44,7 @@ module Grammar
Symbol | String
Case <<
- [Condition, 'Expression*']
+ [Condition, Expression]
Condition <<
String | :else
@@ -27,7 +27,7 @@ def on_if(condition, *cases)
end
def on_case(arg, *cases)
- [:case, arg, *cases.map {|condition, *exps| [condition, *exps.map {|e| compile(e) }] }]
+ [:case, arg, *cases.map {|condition, exp| [condition, compile(exp)] }]
end
def on_block(code, content)
@@ -56,14 +56,13 @@
it 'should process cond' do
@filter.call([:cond,
- ['cond1', [:exp11], [:exp12]],
+ ['cond1', [:exp1]],
['cond2', [:exp2]],
[:else, [:exp3]],
]).should.equal [:multi,
[:code, 'case'],
[:code, 'when cond1'],
- [:exp11],
- [:exp12],
+ [:exp1],
[:code, 'when cond2'],
[:exp2],
[:code, 'else'],
@@ -74,14 +73,13 @@
it 'should process case' do
@filter.call([:case, 'var',
- ['Array', [:exp11], [:exp12]],
+ ['Array', [:exp1]],
['String', [:exp2]],
[:else, [:exp3]],
]).should.equal [:multi,
[:code, 'case (var)'],
[:code, 'when Array'],
- [:exp11],
- [:exp12],
+ [:exp1],
[:code, 'when String'],
[:exp2],
[:code, 'else'],

0 comments on commit 3dd4600

Please sign in to comment.