convertStmt (P.Advance func arg listeners) =
  let (convertedFunc, (stmts, n)) = runState (convertExpr func) (id, 1)
      (convertedArg, (stmts2, _)) = runState (convertExpr arg) (id, n)
  in stmts . stmts2 . \body -> E.Advance convertedFunc convertedArg (map (convertListener body) listeners)
  where
    convertListener :: E.BlockBody -> (String, P.LValue, [P.Statement]) -> (String, E.Block)
    convertListener body (listenerName, lval, statements) =
      let convertedLVal = convertLValue lval
      in (listenerName, E.Block Nothing convertedLVal (foldr ($) body (map convertStmt statements)))
convertStmt (P.Advance func arg listeners) =
  let (convertedFunc, (stmts, n)) = runState (convertExpr func) (id, 1)
      (convertedArg, (stmts2, _)) = runState (convertExpr arg) (id, n)
  in stmts . stmts2 . \body -> E.Advance convertedFunc convertedArg (map (convertListener body) listeners)
  where
    convertListener :: E.BlockBody -> (String, P.LValue, [P.Statement]) -> (String, E.Block)
    convertListener body (listenerName, lval, statements) =
      let convertedLVal = convertLValue lval
      in (listenerName, E.Block Nothing convertedLVal (foldr ($) body (map convertStmt statements)))
convertStmt (P.Advance func arg listeners) =
  let (convertedFunc, (stmts, n)) = runState (convertExpr func) (id, 1)
      (convertedArg, (stmts2, _)) = runState (convertExpr arg) (id, n)
  in stmts . stmts2 . \body -> E.Advance convertedFunc convertedArg (map (convertListener body) listeners)
  where
    convertListener :: E.BlockBody -> (String, P.LValue, [P.Statement]) -> (String, E.Block)
    convertListener body (listenerName, lval, statements) =
      let convertedLVal = convertLValue lval
      in (listenerName, E.Block Nothing convertedLVal (foldr ($) body (map convertStmt statements)))