compToken tok = case tok of
  R.CmdTok t        -> mapM compCmd t >>= return . CmdTok
  R.ExpTok t        -> ExpTok <$> compToken t
  R.ArrRef mtag n t -> compToken t >>= \nt -> return $ ArrRef mtag n nt
  R.VarRef v        -> return $ VarRef v
  R.Block s p       -> return (Block (T.fromBlock s p))
  R.Lit s           -> return $! Lit (T.fromBStr s)
  R.LitInt i        -> return $! Lit (T.fromInt i)
  R.CatLst lst      -> mapM compToken lst >>= return . CatLst
compToken tok = case tok of
  R.CmdTok t        -> mapM compCmd t >>= return . CmdTok
  R.ExpTok t        -> ExpTok <$> compToken t
  R.ArrRef mtag n t -> compToken t >>= \nt -> return $ ArrRef mtag n nt
  R.VarRef v        -> return $ VarRef v
  R.Block s p       -> return (Block (T.fromBlock s p))
  R.Lit s           -> return $! Lit (T.fromBStr s)
  R.LitInt i        -> return $! Lit (T.fromInt i)
  R.CatLst lst      -> mapM compToken lst >>= return . CatLst
compToken tok = case tok of
  R.CmdTok t        -> mapM compCmd t >>= return . CmdTok
  R.ExpTok t        -> ExpTok <$> compToken t
  R.ArrRef mtag n t -> compToken t >>= \nt -> return $ ArrRef mtag n nt
  R.VarRef v        -> return $ VarRef v
  R.Block s p       -> return (Block (T.fromBlock s p))
  R.Lit s           -> return $! Lit (T.fromBStr s)
  R.LitInt i        -> return $! Lit (T.fromInt i)
  R.CatLst lst      -> mapM compToken lst >>= return . CatLst