on master help sign in
Merge pull request #313 from hannesm/cleanups
be28b7fEdwin Brady
src/Idris/AbsSyntax.hs+2−4
@@ -27,8 +27,6 @@ import Debug.Trace
27import Util.Pretty
27import Util.Pretty
28import Util.System
28import Util.System
29
29
30−import Text.Printf (printf)
31−
32getContext :: Idris Context
30getContext :: Idris Context
33getContext = do i <- getIState; return (tt_ctxt i)
31getContext = do i <- getIState; return (tt_ctxt i)
34
32
@@ -252,7 +250,7 @@ iResult s = do i <- getIState
252 "" -> return ()
250 "" -> return ()
253 s -> liftIO $ putStrLn s
251 s -> liftIO $ putStrLn s
254 IdeSlave n ->
252 IdeSlave n ->
255− let good = List [SymbolAtom "ok", toSExp s] in
253+ let good = SexpList [SymbolAtom "ok", toSExp s] in
256 liftIO $ putStrLn $ convSExp "return" good n
254 liftIO $ putStrLn $ convSExp "return" good n
257
255
258iFail :: String -> Idris ()
256iFail :: String -> Idris ()
@@ -262,7 +260,7 @@ iFail s = do i <- getIState
262 "" -> return ()
260 "" -> return ()
263 s -> liftIO $ putStrLn s
261 s -> liftIO $ putStrLn s
264 IdeSlave n ->
262 IdeSlave n ->
265− let good = List [SymbolAtom "error", toSExp s] in
263+ let good = SexpList [SymbolAtom "error", toSExp s] in
266 liftIO $ putStrLn $ convSExp "return" good n
264 liftIO $ putStrLn $ convSExp "return" good n
267
265
268iputStrLn :: String -> Idris ()
266iputStrLn :: String -> Idris ()
src/Idris/IdeSlave.hs+14−17
@@ -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
10
10
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) ++ ")"
25
25
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
31
31
32−instance SExpable () where
33− toSExp a = List [ StringAtom "Unit" ]
34−
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)
47
44
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]
51
48
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)
54
51
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]
57
54
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]
60
57
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]
67
64
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)
70 <|> atom
67 <|> atom
71
68
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
94
91
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
101
98
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)
106
103
107receiveString :: String -> SExp
104receiveString :: String -> SExp
@@ -118,7 +115,7 @@ receiveString x =
118
115
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
124
121
src/Idris/REPL.hs+1−1
@@ -110,7 +110,7 @@ ideslave orig mods
110 (\e -> do iFail $ show e)
110 (\e -> do iFail $ show e)
111 Just (REPLCompletions str) ->
111 Just (REPLCompletions str) ->
112 do (unused, compls) <- replCompletion (reverse str, "")
112 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)]
114 liftIO $ putStrLn $ convSExp "return" good id
114 liftIO $ putStrLn $ convSExp "return" good id
115 Just (LoadFile filename) ->
115 Just (LoadFile filename) ->
116 do clearErr
116 do clearErr
src/Main.hs+1
@@ -91,6 +91,7 @@ usagemsg = "Idris version " ++ ver ++ "\n" ++
91 "\t--log [level] Type debugging log level\n" ++
91 "\t--log [level] Type debugging log level\n" ++
92 "\t-S Do no further compilation of code generator output\n" ++
92 "\t-S Do no further compilation of code generator output\n" ++
93 "\t-c Compile to object files rather than an executable\n" ++
93 "\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" ++
94 "\t--libdir Show library install directory and exit\n" ++
95 "\t--libdir Show library install directory and exit\n" ++
95 "\t--link Show C library directories and exit (for C linking)\n" ++
96 "\t--link Show C library directories and exit (for C linking)\n" ++
96 "\t--include Show C include directories and exit (for C linking)\n" ++
97 "\t--include Show C include directories and exit (for C linking)\n" ++