{-# LANGUAGE ViewPatterns, MultiParamTypeClasses, FlexibleInstances #-}

module GHC.Util.View (
   fromParen', fromPParen'
  , View'(..)
  , Var_'(Var_'), PVar_'(PVar_'), PApp_'(PApp_'), App2'(App2'),LamConst1'(LamConst1')
) where

import HsSyn
import SrcLoc
import RdrName
import OccName
import BasicTypes

fromParen' :: LHsExpr GhcPs -> LHsExpr GhcPs
fromParen' :: LHsExpr GhcPs -> LHsExpr GhcPs
fromParen' (LL _ (HsPar _ x)) = LHsExpr GhcPs -> LHsExpr GhcPs
fromParen' LHsExpr GhcPs
x
fromParen' x :: LHsExpr GhcPs
x = LHsExpr GhcPs
x

fromPParen' :: Pat GhcPs -> Pat GhcPs
fromPParen' :: Pat GhcPs -> Pat GhcPs
fromPParen' (LL _ (ParPat _ x)) = Pat GhcPs -> Pat GhcPs
fromPParen' Pat GhcPs
x
fromPParen' x :: Pat GhcPs
x = Pat GhcPs
x

class View' a b where
  view' :: a -> b

data Var_'  = NoVar_' | Var_' String deriving Var_' -> Var_' -> Bool
(Var_' -> Var_' -> Bool) -> (Var_' -> Var_' -> Bool) -> Eq Var_'
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Var_' -> Var_' -> Bool
$c/= :: Var_' -> Var_' -> Bool
== :: Var_' -> Var_' -> Bool
$c== :: Var_' -> Var_' -> Bool
Eq
data PVar_' = NoPVar_' | PVar_' String
data PApp_' = NoPApp_' | PApp_' String [Pat GhcPs]
data App2'  = NoApp2'  | App2' (LHsExpr GhcPs) (LHsExpr GhcPs) (LHsExpr GhcPs)
data LamConst1' = NoLamConst1' | LamConst1' (LHsExpr GhcPs)

instance View' (LHsExpr GhcPs) LamConst1' where
  view' :: LHsExpr GhcPs -> LamConst1'
view' (LHsExpr GhcPs -> LHsExpr GhcPs
fromParen' -> (LL _ (HsLam _ (MG _ (L _ [LL _ (Match _ LambdaExpr [LL _ WildPat {}]
    (GRHSs _ [LL _ (GRHS _ [] x)] (LL _ (EmptyLocalBinds _))))]) FromSource)))) = LHsExpr GhcPs -> LamConst1'
LamConst1' LHsExpr GhcPs
x
  view' _ = LamConst1'
NoLamConst1'

instance View' (LHsExpr GhcPs) Var_' where
    view' :: LHsExpr GhcPs -> Var_'
view' (LHsExpr GhcPs -> LHsExpr GhcPs
fromParen' -> (LL _ (HsVar _ (LL _ (Unqual x))))) = String -> Var_'
Var_' (String -> Var_') -> String -> Var_'
forall a b. (a -> b) -> a -> b
$ OccName -> String
occNameString OccName
x
    view' _ = Var_'
NoVar_'

instance View' (LHsExpr GhcPs) App2' where
  view' :: LHsExpr GhcPs -> App2'
view' (LHsExpr GhcPs -> LHsExpr GhcPs
fromParen' -> LL _ (OpApp _ lhs op rhs)) = LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs -> App2'
App2' LHsExpr GhcPs
op LHsExpr GhcPs
lhs LHsExpr GhcPs
rhs
  view' (LHsExpr GhcPs -> LHsExpr GhcPs
fromParen' -> LL _ (HsApp _ (LL _ (HsApp _ f x)) y)) = LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs -> App2'
App2' LHsExpr GhcPs
f LHsExpr GhcPs
x LHsExpr GhcPs
y
  view' _ = App2'
NoApp2'

instance View' (Pat GhcPs) PVar_' where
  view' :: Pat GhcPs -> PVar_'
view' (Pat GhcPs -> Pat GhcPs
fromPParen' -> LL _ (VarPat _ (L _ x))) = String -> PVar_'
PVar_' (String -> PVar_') -> String -> PVar_'
forall a b. (a -> b) -> a -> b
$ OccName -> String
occNameString (RdrName -> OccName
rdrNameOcc RdrName
IdP GhcPs
x)
  view' _ = PVar_'
NoPVar_'

instance View' (Pat GhcPs) PApp_' where
  view' :: Pat GhcPs -> PApp_'
view' (Pat GhcPs -> Pat GhcPs
fromPParen' -> LL _ (ConPatIn (L _ x) (PrefixCon args))) =
    String -> [Pat GhcPs] -> PApp_'
PApp_' (OccName -> String
occNameString (OccName -> String) -> (RdrName -> OccName) -> RdrName -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RdrName -> OccName
rdrNameOcc (RdrName -> String) -> RdrName -> String
forall a b. (a -> b) -> a -> b
$ RdrName
IdP GhcPs
x) [Pat GhcPs]
args
  view' (Pat GhcPs -> Pat GhcPs
fromPParen' -> LL _ (ConPatIn (L _ x) (InfixCon lhs rhs))) =
    String -> [Pat GhcPs] -> PApp_'
PApp_' (OccName -> String
occNameString (OccName -> String) -> (RdrName -> OccName) -> RdrName -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RdrName -> OccName
rdrNameOcc (RdrName -> String) -> RdrName -> String
forall a b. (a -> b) -> a -> b
$ RdrName
IdP GhcPs
x) [Pat GhcPs
lhs, Pat GhcPs
rhs]
  view' _ = PApp_'
NoPApp_'