{-# LANGUAGE DataKinds         #-}
{-# LANGUAGE OverloadedStrings #-}

module Language.PureScript.Bridge.Tuple where

import qualified Data.Text                           as T


import           Language.PureScript.Bridge.Builder
import           Language.PureScript.Bridge.PSTypes  (psTuple)
import           Language.PureScript.Bridge.TypeInfo


tupleBridge :: BridgePart
tupleBridge :: BridgePart
tupleBridge = forall a. Getter HaskellType a -> (a -> Bool) -> BridgeBuilder ()
doCheck forall t. HasHaskType t => Lens' t HaskellType
haskType HaskellType -> Bool
isTuple forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *). MonadReader BridgeData m => m PSType
psTuple


data TupleParserState =
  Start | OpenFound | ColonFound | Tuple | NoTuple deriving (TupleParserState -> TupleParserState -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TupleParserState -> TupleParserState -> Bool
$c/= :: TupleParserState -> TupleParserState -> Bool
== :: TupleParserState -> TupleParserState -> Bool
$c== :: TupleParserState -> TupleParserState -> Bool
Eq, Int -> TupleParserState -> ShowS
[TupleParserState] -> ShowS
TupleParserState -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TupleParserState] -> ShowS
$cshowList :: [TupleParserState] -> ShowS
show :: TupleParserState -> String
$cshow :: TupleParserState -> String
showsPrec :: Int -> TupleParserState -> ShowS
$cshowsPrec :: Int -> TupleParserState -> ShowS
Show)

step :: TupleParserState -> Char -> TupleParserState
step :: TupleParserState -> Char -> TupleParserState
step TupleParserState
Start Char
'(' = TupleParserState
OpenFound
step TupleParserState
Start Char
_ = TupleParserState
NoTuple
step TupleParserState
OpenFound Char
',' = TupleParserState
ColonFound
step TupleParserState
OpenFound Char
_ = TupleParserState
NoTuple
step TupleParserState
ColonFound Char
',' = TupleParserState
ColonFound
step TupleParserState
ColonFound Char
')' = TupleParserState
Tuple
step TupleParserState
ColonFound Char
_ = TupleParserState
NoTuple
step TupleParserState
Tuple Char
_ = TupleParserState
NoTuple
step TupleParserState
NoTuple Char
_ = TupleParserState
NoTuple

isTuple :: HaskellType -> Bool
isTuple :: HaskellType -> Bool
isTuple = (forall a. Eq a => a -> a -> Bool
== TupleParserState
Tuple) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. (a -> Char -> a) -> a -> Text -> a
T.foldl' TupleParserState -> Char -> TupleParserState
step TupleParserState
Start forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (lang :: Language). TypeInfo lang -> Text
_typeName