@@ -8,7 +8,7 @@ import Data.List
8-- import qualified Data.Text as T
8-- import qualified Data.Text as T
9import Text.Parsec
9import Text.Parsec
11−data SExp = List [SExp]
11+data SExp = SexpList [SExp]
12 | StringAtom String
12 | StringAtom String
13 | BoolAtom Bool
13 | BoolAtom Bool
14 | IntegerAtom Integer
14 | IntegerAtom Integer
@@ -21,7 +21,7 @@ sExpToString (BoolAtom True) = ":True"
21sExpToString (BoolAtom False) = ":False"
21sExpToString (BoolAtom False) = ":False"
22sExpToString (IntegerAtom i) = printf "%d" i
22sExpToString (IntegerAtom i) = printf "%d" i
23sExpToString (SymbolAtom s) = ":" ++ s
23sExpToString (SymbolAtom s) = ":" ++ s
24−sExpToString (List l) = "(" ++ intercalate " " (map sExpToString l) ++ ")"
24+sExpToString (SexpList l) = "(" ++ intercalate " " (map sExpToString l) ++ ")"
26class SExpable a where
26class SExpable a where
27 toSExp :: a -> SExp
27 toSExp :: a -> SExp
@@ -29,9 +29,6 @@ class SExpable a where
29instance SExpable SExp where
29instance SExpable SExp where
30 toSExp a = a
30 toSExp a = a
32−instance SExpable () where
33− toSExp a = List [ StringAtom "Unit" ]
35instance SExpable Bool where
32instance SExpable Bool where
36 toSExp True = BoolAtom True
33 toSExp True = BoolAtom True
37 toSExp False = BoolAtom False
34 toSExp False = BoolAtom False
@@ -46,17 +43,17 @@ instance SExpable Int where
46 toSExp n = IntegerAtom (toInteger n)
43 toSExp n = IntegerAtom (toInteger n)
48instance (SExpable a) => SExpable (Maybe a) where
45instance (SExpable a) => SExpable (Maybe a) where
49− toSExp Nothing = List [SymbolAtom "Nothing"]
46+ toSExp Nothing = SexpList [SymbolAtom "Nothing"]
50− toSExp (Just a) = List [SymbolAtom "Just", toSExp a]
47+ toSExp (Just a) = SexpList [SymbolAtom "Just", toSExp a]
52instance (SExpable a) => SExpable [a] where
49instance (SExpable a) => SExpable [a] where
53− toSExp l = List (map toSExp l)
50+ toSExp l = SexpList (map toSExp l)
55instance (SExpable a, SExpable b) => SExpable (a, b) where
52instance (SExpable a, SExpable b) => SExpable (a, b) where
56− toSExp (l, r) = List [toSExp l, toSExp r]
53+ toSExp (l, r) = SexpList [toSExp l, toSExp r]
58instance (SExpable a, SExpable b, SExpable c) => SExpable (a, b, c) where
55instance (SExpable a, SExpable b, SExpable c) => SExpable (a, b, c) where
59− toSExp (l, m, n) = List [toSExp l, toSExp m, toSExp n]
56+ toSExp (l, m, n) = SexpList [toSExp l, toSExp m, toSExp n]
61escape :: String -> String
58escape :: String -> String
62escape = concatMap escapeChar
59escape = concatMap escapeChar
@@ -66,7 +63,7 @@ escape = concatMap escapeChar
66 escapeChar c = [c]
63 escapeChar c = [c]
68pSExp = do xs <- between (char '(') (char ')') (pSExp `sepBy` (char ' '))
65pSExp = do xs <- between (char '(') (char ')') (pSExp `sepBy` (char ' '))
69− return (List xs)
66+ return (SexpList xs)
72atom = do char ':'; x <- atomC; return x
69atom = do char ':'; x <- atomC; return x
@@ -93,15 +90,15 @@ data IdeSlaveCommand = REPLCompletions String
93 deriving Show
90 deriving Show
95sexpToCommand :: SExp -> Maybe IdeSlaveCommand
92sexpToCommand :: SExp -> Maybe IdeSlaveCommand
96−sexpToCommand (List (x:[])) = sexpToCommand x
93+sexpToCommand (SexpList (x:[])) = sexpToCommand x
97−sexpToCommand (List [SymbolAtom "interpret", StringAtom cmd]) = Just (Interpret cmd)
94+sexpToCommand (SexpList [SymbolAtom "interpret", StringAtom cmd]) = Just (Interpret cmd)
98−sexpToCommand (List [SymbolAtom "repl-completions", StringAtom prefix]) = Just (REPLCompletions prefix)
95+sexpToCommand (SexpList [SymbolAtom "repl-completions", StringAtom prefix]) = Just (REPLCompletions prefix)
99−sexpToCommand (List [SymbolAtom "load-file", StringAtom filename]) = Just (LoadFile filename)
96+sexpToCommand (SexpList [SymbolAtom "load-file", StringAtom filename]) = Just (LoadFile filename)
100sexpToCommand _ = Nothing
97sexpToCommand _ = Nothing
102parseMessage :: String -> (SExp, Integer)
99parseMessage :: String -> (SExp, Integer)
103parseMessage x = case receiveString x of
100parseMessage x = case receiveString x of
104− (List [cmd, (IntegerAtom id)]) ->
101+ (SexpList [cmd, (IntegerAtom id)]) ->
105 (cmd, id)
102 (cmd, id)
107receiveString :: String -> SExp
104receiveString :: String -> SExp
@@ -118,7 +115,7 @@ receiveString x =
119convSExp :: SExpable a => String -> a -> Integer -> String
116convSExp :: SExpable a => String -> a -> Integer -> String
120convSExp pre s id =
117convSExp pre s id =
121− let sex = List [SymbolAtom pre, toSExp s, IntegerAtom id] in
118+ let sex = SexpList [SymbolAtom pre, toSExp s, IntegerAtom id] in
122 let str = sExpToString sex in
119 let str = sExpToString sex in
123 (getHexLength str) ++ str
120 (getHexLength str) ++ str