on master help sign in
Merge pull request #313 from hannesm/cleanups

Cleanups

commitbe28b7fbbd605cc461d45f039c95a5cb60e304cc authorEdwin Brady <edwin.brady@gmail.com> dateSun 12 May 2013, 04:47 (13 years ago) parentf608369e24baaa
4 files changed+18−22
src/Idris/AbsSyntax.hs+2−4 src/Idris/IdeSlave.hs+14−17 src/Idris/REPL.hs+1−1 src/Main.hs+1
src/Idris/AbsSyntax.hs+2−4
@@ -27,8 +27,6 @@ import Debug.Trace
2727import Util.Pretty
2828import Util.System
2929
30−import Text.Printf (printf)
31−
3230getContext :: Idris Context
3331getContext = do i <- getIState; return (tt_ctxt i)
3432
@@ -252,7 +250,7 @@ iResult s = do i <- getIState
252250 "" -> return ()
253251 s -> liftIO $ putStrLn s
254252 IdeSlave n ->
255− let good = List [SymbolAtom "ok", toSExp s] in
253+ let good = SexpList [SymbolAtom "ok", toSExp s] in
256254 liftIO $ putStrLn $ convSExp "return" good n
257255
258256iFail :: String -> Idris ()
@@ -262,7 +260,7 @@ iFail s = do i <- getIState
262260 "" -> return ()
263261 s -> liftIO $ putStrLn s
264262 IdeSlave n ->
265− let good = List [SymbolAtom "error", toSExp s] in
263+ let good = SexpList [SymbolAtom "error", toSExp s] in
266264 liftIO $ putStrLn $ convSExp "return" good n
267265
268266iputStrLn :: String -> Idris ()
src/Idris/IdeSlave.hs+14−17
@@ -8,7 +8,7 @@ import Data.List
88-- import qualified Data.Text as T
99import Text.Parsec
1010
11−data SExp = List [SExp]
11+data SExp = SexpList [SExp]
1212 | StringAtom String
1313 | BoolAtom Bool
1414 | IntegerAtom Integer
@@ -21,7 +21,7 @@ sExpToString (BoolAtom True) = ":True"
2121sExpToString (BoolAtom False) = ":False"
2222sExpToString (IntegerAtom i) = printf "%d" i
2323sExpToString (SymbolAtom s) = ":" ++ s
24−sExpToString (List l) = "(" ++ intercalate " " (map sExpToString l) ++ ")"
24+sExpToString (SexpList l) = "(" ++ intercalate " " (map sExpToString l) ++ ")"
2525
2626class SExpable a where
2727 toSExp :: a -> SExp
@@ -29,9 +29,6 @@ class SExpable a where
2929instance SExpable SExp where
3030 toSExp a = a
3131
32−instance SExpable () where
33− toSExp a = List [ StringAtom "Unit" ]
34−
3532instance SExpable Bool where
3633 toSExp True = BoolAtom True
3734 toSExp False = BoolAtom False
@@ -46,17 +43,17 @@ instance SExpable Int where
4643 toSExp n = IntegerAtom (toInteger n)
4744
4845instance (SExpable a) => SExpable (Maybe a) where
49− toSExp Nothing = List [SymbolAtom "Nothing"]
50− toSExp (Just a) = List [SymbolAtom "Just", toSExp a]
46+ toSExp Nothing = SexpList [SymbolAtom "Nothing"]
47+ toSExp (Just a) = SexpList [SymbolAtom "Just", toSExp a]
5148
5249instance (SExpable a) => SExpable [a] where
53− toSExp l = List (map toSExp l)
50+ toSExp l = SexpList (map toSExp l)
5451
5552instance (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]
5754
5855instance (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]
6057
6158escape :: String -> String
6259escape = concatMap escapeChar
@@ -66,7 +63,7 @@ escape = concatMap escapeChar
6663 escapeChar c = [c]
6764
6865pSExp = do xs <- between (char '(') (char ')') (pSExp `sepBy` (char ' '))
69− return (List xs)
66+ return (SexpList xs)
7067 <|> atom
7168
7269atom = do char ':'; x <- atomC; return x
@@ -93,15 +90,15 @@ data IdeSlaveCommand = REPLCompletions String
9390 deriving Show
9491
9592sexpToCommand :: SExp -> Maybe IdeSlaveCommand
96−sexpToCommand (List (x:[])) = sexpToCommand x
97−sexpToCommand (List [SymbolAtom "interpret", StringAtom cmd]) = Just (Interpret cmd)
98−sexpToCommand (List [SymbolAtom "repl-completions", StringAtom prefix]) = Just (REPLCompletions prefix)
99−sexpToCommand (List [SymbolAtom "load-file", StringAtom filename]) = Just (LoadFile filename)
93+sexpToCommand (SexpList (x:[])) = sexpToCommand x
94+sexpToCommand (SexpList [SymbolAtom "interpret", StringAtom cmd]) = Just (Interpret cmd)
95+sexpToCommand (SexpList [SymbolAtom "repl-completions", StringAtom prefix]) = Just (REPLCompletions prefix)
96+sexpToCommand (SexpList [SymbolAtom "load-file", StringAtom filename]) = Just (LoadFile filename)
10097sexpToCommand _ = Nothing
10198
10299parseMessage :: String -> (SExp, Integer)
103100parseMessage x = case receiveString x of
104− (List [cmd, (IntegerAtom id)]) ->
101+ (SexpList [cmd, (IntegerAtom id)]) ->
105102 (cmd, id)
106103
107104receiveString :: String -> SExp
@@ -118,7 +115,7 @@ receiveString x =
118115
119116convSExp :: SExpable a => String -> a -> Integer -> String
120117convSExp 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
122119 let str = sExpToString sex in
123120 (getHexLength str) ++ str
124121
src/Idris/REPL.hs+1−1
@@ -110,7 +110,7 @@ ideslave orig mods
110110 (\e -> do iFail $ show e)
111111 Just (REPLCompletions str) ->
112112 do (unused, compls) <- replCompletion (reverse str, "")
113− let good = List [SymbolAtom "ok", toSExp (map replacement compls, reverse unused)]
113+ let good = SexpList [SymbolAtom "ok", toSExp (map replacement compls, reverse unused)]
114114 liftIO $ putStrLn $ convSExp "return" good id
115115 Just (LoadFile filename) ->
116116 do clearErr
src/Main.hs+1
@@ -91,6 +91,7 @@ usagemsg = "Idris version " ++ ver ++ "\n" ++
9191 "\t--log [level] Type debugging log level\n" ++
9292 "\t-S Do no further compilation of code generator output\n" ++
9393 "\t-c Compile to object files rather than an executable\n" ++
94+ "\t--ideslave Ideslave mode (for editors; in/ouput wrapped in s-expressions)\n" ++
9495 "\t--libdir Show library install directory and exit\n" ++
9596 "\t--link Show C library directories and exit (for C linking)\n" ++
9697 "\t--include Show C include directories and exit (for C linking)\n" ++