@@ -15,6 +15,7 @@ import Idris.Core.Binary ()
15import Idris.Core.TT
15import Idris.Core.TT
17import Control.Applicative hiding (Const)
17import Control.Applicative hiding (Const)
18+import Control.Arrow (left)
18import qualified Data.Binary as Binary
19import qualified Data.Binary as Binary
19import qualified Data.ByteString.Base64 as Base64
20import qualified Data.ByteString.Base64 as Base64
20import qualified Data.ByteString.Lazy as Lazy
21import qualified Data.ByteString.Lazy as Lazy
@@ -25,8 +26,8 @@ import qualified Data.Text as T
25import Numeric
26import Numeric
26import System.IO
27import System.IO
27import Text.Printf
28import Text.Printf
28−import qualified Text.Trifecta as P
29+import qualified Text.Megaparsec as P
29−import qualified Text.Trifecta.Delta as P
30+import qualified Text.Megaparsec.Char as P
31getNChar :: Handle -> Int -> String -> IO (String)
32getNChar :: Handle -> Int -> String -> IO (String)
32getNChar _ 0 s = return (reverse s)
33getNChar _ 0 s = return (reverse s)
@@ -205,28 +206,31 @@ escape = concatMap escapeChar
205 escapeChar '"' = "\\\""
206 escapeChar '"' = "\\\""
206 escapeChar c = [c]
207 escapeChar c = [c]
209+type Parser a = P.Parsec () String a
208pSExp = SexpList <$> P.between (P.char '(') (P.char ')') (pSExp `P.sepBy` (P.char ' '))
212pSExp = SexpList <$> P.between (P.char '(') (P.char ')') (pSExp `P.sepBy` (P.char ' '))
211atom = SexpList [] <$ P.string "nil"
216atom = SexpList [] <$ P.string "nil"
212 <|> P.char ':' *> atomC
217 <|> P.char ':' *> atomC
213 <|> StringAtom <$> P.between (P.char '"') (P.char '"') (P.many quotedChar)
218 <|> StringAtom <$> P.between (P.char '"') (P.char '"') (P.many quotedChar)
214− <|> do ints <- some P.digit
219+ <|> do ints <- some P.digitChar
215 case readDec ints of
220 case readDec ints of
216 ((num, ""):_) -> return (IntegerAtom (toInteger num))
221 ((num, ""):_) -> return (IntegerAtom (toInteger num))
217 _ -> return (StringAtom ints)
222 _ -> return (StringAtom ints)
219atomC = BoolAtom True <$ P.string "True"
225atomC = BoolAtom True <$ P.string "True"
220 <|> BoolAtom False <$ P.string "False"
226 <|> BoolAtom False <$ P.string "False"
221 <|> SymbolAtom <$> many (P.noneOf " \n\t\r\"()")
227 <|> SymbolAtom <$> many (P.noneOf " \n\t\r\"()")
229+quotedChar :: Parser Char
223quotedChar = P.try ('\\' <$ P.string "\\\\")
230quotedChar = P.try ('\\' <$ P.string "\\\\")
224 <|> P.try ('"' <$ P.string "\\\"")
231 <|> P.try ('"' <$ P.string "\\\"")
225 <|> P.noneOf "\""
232 <|> P.noneOf "\""
227−parseSExp :: String -> P.Result SExp
228−parseSExp = P.parseString pSExp (P.Directed (UTF8.fromString "(unknown)") 0 0 0 0)
230data Opt = ShowImpl | ErrContext deriving Show
234data Opt = ShowImpl | ErrContext deriving Show
232data WhatDocs = Overview | Full
236data WhatDocs = Overview | Full
@@ -321,10 +325,7 @@ parseMessage x = case receiveString x of
321 Left err -> Left err
325 Left err -> Left err
323receiveString :: String -> Either Err SExp
327receiveString :: String -> Either Err SExp
324−receiveString x =
328+receiveString = left (const $ Msg "parse failure") . P.parse pSExp "(unknown)"
326− P.Failure _ -> Left . Msg $ "parse failure"
327− P.Success r -> Right r
329convSExp :: SExpable a => String -> a -> Integer -> String
330convSExp :: SExpable a => String -> a -> Integer -> String
330convSExp pre s id =
331convSExp pre s id =