Class: Gisele::Language::IfToCase
- Inherits:
-
Sexpr::Rewriter
- Object
- Sexpr::Rewriter
- Gisele::Language::IfToCase
- Defined in:
- lib/gisele/language/processors/if_to_case.rb
Instance Method Summary collapse
Instance Method Details
#on_else_clause(sexpr) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/gisele/language/processors/if_to_case.rb', line 40 def on_else_clause(sexpr) dost, = sexpr.sexpr_body # convert else to when and keep the markers base = \ [:when_clause, [:bool_expr, @condition], apply(dost)] sexpr(base, sexpr.tracking_markers) end |
#on_elsif_clause(sexpr) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/gisele/language/processors/if_to_case.rb', line 24 def on_elsif_clause(sexpr) condition, dost, = sexpr.sexpr_body # install new conditions for me and next elsif clauses condition = condition.last previous = @condition @condition = [:bool_and, negate(condition), @condition] # convert elsif to when and keep the markers base = \ [:when_clause, [:bool_expr, [:bool_and, condition, previous]], apply(dost) ] sexpr(base, sexpr.tracking_markers) end |
#on_if_st(sexpr) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/gisele/language/processors/if_to_case.rb', line 6 def on_if_st(sexpr) condition, dost, *clauses = sexpr.sexpr_body # create case_st with same markers as the if_st when_clause = [:when_clause, condition, apply(dost)] when_clause = sexpr(when_clause, sexpr.tracking_markers) base = [:case_st, nil, when_clause] base = sexpr(base, sexpr.tracking_markers) # this is the condition for elsif clauses @condition = negate(condition.last) # make injection now clauses.inject base do |memo,clause| memo << apply(clause) end end |