module SyntaxTrees.Scala.Common where

import Data.List (intercalate)


newtype Var
  = Var String

newtype Ctor
  = Ctor String


newtype VarOp
  = VarOp String

newtype CtorOp
  = CtorOp String

newtype TypeClass
  = TypeClass String

newtype Package
  = Package [String]


data Literal
  = UnitLit
  | BoolLit Bool
  | IntLit String
  | FloatLit String
  | CharLit Char
  | StringLit String

data Modifier
  = Implicit
  | Lazy
  | Abstract
  | Private
  | Public
  | Protected
  | Override
  | Sealed
  | Open


data QVar
  = QVar (Maybe Package) Var

data QCtor
  = QCtor (Maybe Package) Ctor

data QVarOp
  = QVarOp (Maybe Package) VarOp

data QCtorOp
  = QCtorOp (Maybe Package) CtorOp

data QTypeClass
  = QTypeClass (Maybe Package) TypeClass


instance Show Var where
  show :: Var -> String
show (Var String
x) = String
x

instance Show Ctor where
  show :: Ctor -> String
show (Ctor String
x) = String
x

instance Show VarOp where
  show :: VarOp -> String
show (VarOp String
x) = String
x

instance Show CtorOp where
  show :: CtorOp -> String
show (CtorOp String
x) = String
x

instance Show TypeClass where
  show :: TypeClass -> String
show (TypeClass String
x) = String
x


instance Show Package where
  show :: Package -> String
show (Package [String]
x) = forall a. [a] -> [[a]] -> [a]
intercalate String
"." [String]
x

instance Show Literal where
  show :: Literal -> String
show Literal
UnitLit         = String
"()"
  show (BoolLit Bool
True)  = String
"true"
  show (BoolLit Bool
False) = String
"false"
  show (IntLit String
x)      = String
x
  show (FloatLit String
x)    = String
x
  show (CharLit Char
x)     = forall a. Show a => a -> String
show Char
x
  show (StringLit String
x)   = forall a. Show a => a -> String
show String
x


instance Show Modifier where
  show :: Modifier -> String
show Modifier
Implicit  = String
"implicit"
  show Modifier
Lazy      = String
"lazy"
  show Modifier
Abstract  = String
"abstract"
  show Modifier
Private   = String
"private"
  show Modifier
Public    = String
"public"
  show Modifier
Protected = String
"protected"
  show Modifier
Override  = String
"override"
  show Modifier
Sealed    = String
"sealed"
  show Modifier
Open      = String
"open"


instance Show QVar where
  show :: QVar -> String
show (QVar Maybe Package
x Var
y) = forall a b. (Show a, Show b) => Maybe a -> b -> String
showQualified Maybe Package
x Var
y

instance Show QCtor where
  show :: QCtor -> String
show (QCtor Maybe Package
x Ctor
y) = forall a b. (Show a, Show b) => Maybe a -> b -> String
showQualified Maybe Package
x Ctor
y

instance Show QVarOp where
  show :: QVarOp -> String
show (QVarOp Maybe Package
x VarOp
y) = forall a b. (Show a, Show b) => Maybe a -> b -> String
showQualified Maybe Package
x VarOp
y

instance Show QCtorOp where
  show :: QCtorOp -> String
show (QCtorOp Maybe Package
x CtorOp
y) = forall a b. (Show a, Show b) => Maybe a -> b -> String
showQualified Maybe Package
x CtorOp
y

instance Show QTypeClass where
  show :: QTypeClass -> String
show (QTypeClass Maybe Package
x TypeClass
y) = forall a b. (Show a, Show b) => Maybe a -> b -> String
showQualified Maybe Package
x TypeClass
y


showQualified :: (Show a, Show b) => Maybe a -> b -> String
showQualified :: forall a b. (Show a, Show b) => Maybe a -> b -> String
showQualified Maybe a
x b
y = forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap ((forall a. [a] -> [a] -> [a]
++ String
".") forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show) Maybe a
x forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show b
y