Advertisement
Guest User

Untitled

a guest
May 4th, 2014
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Falcon 1.80 KB | None | 0 0
  1. function prepareSwitch( stateMap, stateVar )      
  2.       // this is the frame of our switch; it is roughly switch <var>; ... end
  3.       sw = Syn.Switch( Symbol(stateVar) )
  4.      
  5.       for state, r in stateMap
  6.      // we then create an empty syntree for each case
  7.          cs = SynTree()
  8.          // the selector of the tree is a relevant expression that characterizes it,
  9.          // for instance, in while <expr>... end, if <expr>... end etc, the <expr>
  10.          // is the selector.
  11.          // The switch statement accepts syntree with Case expressions as selectors only
  12.          // (or no selector, for the default)
  13.          cs.selector = Syn.Case(state)
  14.  
  15.          // a shortcut to use 'action' twice  
  16.          action = r.action
  17.          if action   // means, if it's not nil
  18.             // then we append the action, that is, a function call. More specifically,
  19.             // {[] code} it's the literal expression; it transforms a parsed expression
  20.             // into a value. The ^~ operator is the 'unescape', which puts in the expression
  21.             // the literal value of the given symbol (or expression) in the context where the
  22.             // {[] ...} is being formed.
  23.         // So, {[] ^~action(tree, text)} it is 100% equivalent to Call( action, $tree, $text), it's just
  24.             // more readable.
  25.             cs.append( {[] ^~action(tree, text)} )
  26.          end
  27.  
  28.          // We then add a call to setState. The literal value of self as it is NOW is inserted via
  29.          // the unescape operator. As said, ^~ works also with expressions (as for ^~(r.target))
  30.          cs.append( {[] ^~self.setState(^~(r.target))} )
  31.          
  32.          sw.append(cs)
  33.       end
  34.        
  35.       // SynTree's render method will give back a reflexively compileable source code.
  36.       > sw.render()
  37.       return sw
  38.    end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement