Stratego/XT JIRA  History | Log In     View a printable version of the current page. Get help!  
Issue Details (XML | Word)

Key: STR-68
Type: New Feature New Feature
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Arthur van Dam
Reporter: Arthur van Dam
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Stratego/XT

switch-case construct

Created: 2004-04-27 07:50   Updated: 2008-03-31 20:39
Component/s: Language concepts
Affects Version/s: None
Fix Version/s: 0.10

Original Estimate: Unknown Remaining Estimate: Unknown Time Spent: Unknown


 Description  « Hide
After introducing the if-then-else operator, a switch-case construct would be quite useful as well.
Syntax:
  switch s0
    case s1 : s1'
    case s2 : s2'
    // ...
    otherwise : s'
  end

Semantics:
s0 will be applied to the current term from right before the switch. Its result will be the input term for each case-condition strategy si.
The body strategies of the case branches, si', will be applied to the current term from right before the switch.
The case branches will be applied in their normal order until a case condition succeeds. If a body strategy of a selected case branch fails, no backtracking to other (next) branches occurs, the entire switch then fails. Other branches will only be selected if all previous case-condition strategies failed.
The optional default branch can only occur at the end and directly applies its body strategy s'.

Desugaring:
    ?t
  ; s0 => t0
  ; (where(<s1> t0)
     < <s1'> t
     + (where(<s2> t0)
        < <s2'> t
        +
           // ...
           + <s'> t // or fail if no default branch
          )
       )
    )

Open Problem:
Any bindings resulting from previously tried case-condition-strategies s1..si-1 should be unbound before trying si. This has to do with the general problem that no unbinding occurs on backtracking (STR-9).
The same holds for undefining any generated dynamic rules.
       

 All   Comments   Work Log   Change History      Sort Order:
Arthur van Dam [2004-04-28 11:03]
All branch conditions should apply to the original selector (thus use a BuildApp)