-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathTuple.hs
More file actions
35 lines (28 loc) · 1.01 KB
/
Tuple.hs
File metadata and controls
35 lines (28 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{-# LANGUAGE CPP #-}
{-# 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
#if __GLASGOW_HASKELL__>=908
tupleBridge = typeName ^== "Tuple2" >> psTuple
#else
tupleBridge = doCheck haskType isTuple >> psTuple
#endif
data TupleParserState = Start | OpenFound | ColonFound | Tuple | NoTuple
deriving (Eq, Show)
step :: TupleParserState -> Char -> TupleParserState
step Start '(' = OpenFound
step Start _ = NoTuple
step OpenFound ',' = ColonFound
step OpenFound _ = NoTuple
step ColonFound ',' = ColonFound
step ColonFound ')' = Tuple
step ColonFound _ = NoTuple
step Tuple _ = NoTuple
step NoTuple _ = NoTuple
isTuple :: HaskellType -> Bool
isTuple = (== Tuple) . T.foldl' step Start . _typeName