on master help sign in
Use Megaparsec for expressions, remove `parsers` dep
5e9d8deJason Felice
idris.cabal−1
@@ -289,7 +289,6 @@ Library
289 , mtl >= 2.1 && < 2.3
289 , mtl >= 2.1 && < 2.3
290 , network < 2.7
290 , network < 2.7
291 , optparse-applicative >= 0.13 && < 0.15
291 , optparse-applicative >= 0.13 && < 0.15
292− , parsers >= 0.9 && < 0.13
293 , pretty < 1.2
292 , pretty < 1.2
294 , process < 1.7
293 , process < 1.7
295 , regex-tdfa >= 1.2
294 , regex-tdfa >= 1.2
src/Idris/Parser/Expr.hs+2−3
@@ -25,10 +25,10 @@ import Control.Monad.State.Strict
25import Data.Function (on)
25import Data.Function (on)
26import Data.List
26import Data.List
27import Data.Maybe
27import Data.Maybe
28−import Text.Parser.Expression
29import Text.Megaparsec ((<?>))
28import Text.Megaparsec ((<?>))
30import qualified Text.Megaparsec as P
29import qualified Text.Megaparsec as P
31import qualified Text.Megaparsec.Char as P
30import qualified Text.Megaparsec.Char as P
31+import qualified Text.Megaparsec.Expr as P
32
32
33-- | Allow implicit type declarations
33-- | Allow implicit type declarations
34allowImp :: SyntaxInfo -> SyntaxInfo
34allowImp :: SyntaxInfo -> SyntaxInfo
@@ -77,8 +77,7 @@ expr = pi
77-}
77-}
78opExpr :: SyntaxInfo -> IdrisParser PTerm
78opExpr :: SyntaxInfo -> IdrisParser PTerm
79opExpr syn = do i <- get
79opExpr syn = do i <- get
80− buildExpressionParser (table (idris_infixes i))
80+ P.makeExprParser (expr' syn) (table (idris_infixes i))
81− (expr' syn)
82
81
83{- | Parses either an internally defined expression or
82{- | Parses either an internally defined expression or
84 a user-defined one
83 a user-defined one
src/Idris/Parser/Helpers.hs−14
@@ -32,8 +32,6 @@ import Data.Maybe
32import qualified Data.Text as T
32import qualified Data.Text as T
33import Data.Void (Void(..))
33import Data.Void (Void(..))
34import System.FilePath
34import System.FilePath
35−import qualified Text.Parser.Char
36−import qualified Text.Parser.Combinators
37import qualified Text.PrettyPrint.ANSI.Leijen as PP
35import qualified Text.PrettyPrint.ANSI.Leijen as PP
38import Text.Megaparsec ((<?>))
36import Text.Megaparsec ((<?>))
39import qualified Text.Megaparsec as P
37import qualified Text.Megaparsec as P
@@ -59,18 +57,6 @@ type MonadicParsing m = (P.MonadParsec Void String m)
59someSpace' :: MonadicParsing m => m ()
57someSpace' :: MonadicParsing m => m ()
60someSpace' = many (simpleWhiteSpace <|> singleLineComment <|> multiLineComment) *> pure ()
58someSpace' = many (simpleWhiteSpace <|> singleLineComment <|> multiLineComment) *> pure ()
61
59
62−instance Text.Parser.Combinators.Parsing IdrisInnerParser where
63− eof = P.eof
64− unexpected msg = P.unexpected . P.Label . NonEmpty.fromList $ msg
65− try = P.try
66− (<?>) = (P.<?>)
67− notFollowedBy = P.notFollowedBy
68−
69−instance Text.Parser.Char.CharParsing IdrisInnerParser where
70− satisfy = P.satisfy
71− char = P.char
72− string = P.string
73−
74tokenFC :: MonadicParsing m => m a -> m (a, FC)
60tokenFC :: MonadicParsing m => m a -> m (a, FC)
75tokenFC p = do (FC fn (sl, sc) _) <- getFC --TODO: Update after fixing getFC
61tokenFC p = do (FC fn (sl, sc) _) <- getFC --TODO: Update after fixing getFC
76 -- See Issue #1594
62 -- See Issue #1594
src/Idris/Parser/Ops.hs+22−21
@@ -22,39 +22,39 @@ import Control.Monad.State.Strict
22import Data.Char (isAlpha)
22import Data.Char (isAlpha)
23import Data.List
23import Data.List
24import Data.List.NonEmpty (fromList)
24import Data.List.NonEmpty (fromList)
25−import Text.Parser.Expression
26import Text.Megaparsec ((<?>))
25import Text.Megaparsec ((<?>))
27import qualified Text.Megaparsec as P
26import qualified Text.Megaparsec as P
27+import qualified Text.Megaparsec.Expr as P
28
28
29-- | Creates table for fixity declarations to build expression parser
29-- | Creates table for fixity declarations to build expression parser
30-- using pre-build and user-defined operator/fixity declarations
30-- using pre-build and user-defined operator/fixity declarations
31−table :: [FixDecl] -> OperatorTable IdrisParser PTerm
31+table :: [FixDecl] -> [[P.Operator IdrisParser PTerm]]
32table fixes
32table fixes
33 = [[prefix "-" (\fc x -> PApp fc (PRef fc [fc] (sUN "negate")) [pexp x])]] ++
33 = [[prefix "-" (\fc x -> PApp fc (PRef fc [fc] (sUN "negate")) [pexp x])]] ++
34 toTable (reverse fixes) ++
34 toTable (reverse fixes) ++
35 [[noFixityBacktickOperator],
35 [[noFixityBacktickOperator],
36− [binary "$" AssocRight $ \fc _ x y -> flatten $ PApp fc x [pexp y]],
36+ [binary "$" P.InfixR $ \fc _ x y -> flatten $ PApp fc x [pexp y]],
37− [binary "=" AssocLeft $ \fc _ x y -> PApp fc (PRef fc [fc] eqTy) [pexp x, pexp y]],
37+ [binary "=" P.InfixL $ \fc _ x y -> PApp fc (PRef fc [fc] eqTy) [pexp x, pexp y]],
38 [noFixityOperator]]
38 [noFixityOperator]]
39 where
39 where
40 flatten :: PTerm -> PTerm -- flatten application
40 flatten :: PTerm -> PTerm -- flatten application
41 flatten (PApp fc (PApp _ f as) bs) = flatten (PApp fc f (as ++ bs))
41 flatten (PApp fc (PApp _ f as) bs) = flatten (PApp fc f (as ++ bs))
42 flatten t = t
42 flatten t = t
43
43
44− noFixityBacktickOperator :: Operator IdrisParser PTerm
44+ noFixityBacktickOperator :: P.Operator IdrisParser PTerm
45− noFixityBacktickOperator = flip Infix AssocNone $ do
45+ noFixityBacktickOperator = P.InfixN $ do
46 (n, fc) <- backtickOperator
46 (n, fc) <- backtickOperator
47 return $ \x y -> PApp fc (PRef fc [fc] n) [pexp x, pexp y]
47 return $ \x y -> PApp fc (PRef fc [fc] n) [pexp x, pexp y]
48
48
49 -- | Operator without fixity (throws an error)
49 -- | Operator without fixity (throws an error)
50− noFixityOperator :: Operator IdrisParser PTerm
50+ noFixityOperator :: P.Operator IdrisParser PTerm
51− noFixityOperator = flip Infix AssocNone $ do
51+ noFixityOperator = P.InfixN $ do
52 indentGt
52 indentGt
53 op <- P.try symbolicOperator
53 op <- P.try symbolicOperator
54 P.unexpected . P.Label . fromList $ "Operator without known fixity: " ++ op
54 P.unexpected . P.Label . fromList $ "Operator without known fixity: " ++ op
55
55
56 -- | Calculates table for fixity declarations
56 -- | Calculates table for fixity declarations
57− toTable :: [FixDecl] -> OperatorTable IdrisParser PTerm
57+ toTable :: [FixDecl] -> [[P.Operator IdrisParser PTerm]]
58 toTable fs = map (map toBin) (groupBy (\ (Fix x _) (Fix y _) -> prec x == prec y) fs)
58 toTable fs = map (map toBin) (groupBy (\ (Fix x _) (Fix y _) -> prec x == prec y) fs)
59
59
60 toBin (Fix (PrefixN _) op) = prefix op $ \fc x ->
60 toBin (Fix (PrefixN _) op) = prefix op $ \fc x ->
@@ -62,31 +62,32 @@ table fixes
62 toBin (Fix f op) = binary op (assoc f) $ \fc n x y ->
62 toBin (Fix f op) = binary op (assoc f) $ \fc n x y ->
63 PApp fc (PRef fc [] n) [pexp x,pexp y]
63 PApp fc (PRef fc [] n) [pexp x,pexp y]
64
64
65− assoc (Infixl _) = AssocLeft
65+ assoc (Infixl _) = P.InfixL
66− assoc (Infixr _) = AssocRight
66+ assoc (Infixr _) = P.InfixR
67− assoc (InfixN _) = AssocNone
67+ assoc (InfixN _) = P.InfixN
68
68
69 isBacktick :: String -> Bool
69 isBacktick :: String -> Bool
70 isBacktick (c : _) = c == '_' || isAlpha c
70 isBacktick (c : _) = c == '_' || isAlpha c
71 isBacktick _ = False
71 isBacktick _ = False
72
72
73− binary :: String -> Assoc -> (FC -> Name -> PTerm -> PTerm -> PTerm) -> Operator IdrisParser PTerm
73+ binary :: String -> (IdrisParser (PTerm -> PTerm -> PTerm) -> P.Operator IdrisParser PTerm) -> (FC -> Name -> PTerm -> PTerm -> PTerm) -> P.Operator IdrisParser PTerm
74− binary name assoc f
74+ binary name ctor f
75− | isBacktick name = flip Infix assoc $ P.try $ do
75+ | isBacktick name = ctor $ P.try $ do
76 (n, fc) <- backtickOperator
76 (n, fc) <- backtickOperator
77 guard $ show (nsroot n) == name
77 guard $ show (nsroot n) == name
78 return $ f fc n
78 return $ f fc n
79− | otherwise = flip Infix assoc $ do
79+ | otherwise = ctor $ do
80 indentGt
80 indentGt
81 fc <- reservedOpFC name
81 fc <- reservedOpFC name
82 indentGt
82 indentGt
83 return $ f fc (sUN name)
83 return $ f fc (sUN name)
84
84
85− prefix :: String -> (FC -> PTerm -> PTerm) -> Operator IdrisParser PTerm
85+ prefix :: String -> (FC -> PTerm -> PTerm) -> P.Operator IdrisParser PTerm
86− prefix name f = Prefix (do reservedOp name
86+ prefix name f = P.Prefix $ do
87+ reservedOp name
87− fc <- getFC
88+ fc <- getFC
88− indentGt
89+ indentGt
89− return (f fc))
90+ return (f fc)
90
91
91{- | Parses a function used as an operator -- enclosed in backticks
92{- | Parses a function used as an operator -- enclosed in backticks
92
93
src/Idris/REPL/Parser.hs+69−69
@@ -32,8 +32,8 @@ import Data.List
32import Data.List.Split (splitOn)
32import Data.List.Split (splitOn)
33import System.Console.ANSI (Color(..))
33import System.Console.ANSI (Color(..))
34import System.FilePath ((</>))
34import System.FilePath ((</>))
35−import Text.Parser.Char (anyChar, oneOf)
35+import qualified Text.Megaparsec as P
36−import Text.Parser.Combinators
36+import qualified Text.Megaparsec.Char as P
37
37
38parseCmd :: IState -> String -> String -> Either IP.ParseError (Either String Command)
38parseCmd :: IState -> String -> String -> Either IP.ParseError (Either String Command)
39parseCmd i inputname = IP.runparser pCmd i inputname . trim
39parseCmd i inputname = IP.runparser pCmd i inputname . trim
@@ -68,7 +68,7 @@ parserCommandsForHelp =
68 , nameArgCmd ["miss", "missing"] Missing "Show missing clauses"
68 , nameArgCmd ["miss", "missing"] Missing "Show missing clauses"
69 , (["doc"], NameArg, "Show internal documentation", cmd_doc)
69 , (["doc"], NameArg, "Show internal documentation", cmd_doc)
70 , (["mkdoc"], NamespaceArg, "Generate IdrisDoc for namespace(s) and dependencies"
70 , (["mkdoc"], NamespaceArg, "Generate IdrisDoc for namespace(s) and dependencies"
71− , genArg "namespace" (many anyChar) MakeDoc)
71+ , genArg "namespace" (P.many P.anyChar) MakeDoc)
72 , (["apropos"], SeqArgs (OptionalArg PkgArgs) NameArg, " Search names, types, and documentation"
72 , (["apropos"], SeqArgs (OptionalArg PkgArgs) NameArg, " Search names, types, and documentation"
73 , cmd_apropos)
73 , cmd_apropos)
74 , (["s", "search"], SeqArgs (OptionalArg PkgArgs) ExprArg
74 , (["s", "search"], SeqArgs (OptionalArg PkgArgs) ExprArg
@@ -170,7 +170,7 @@ parserCommands =
170 , "(Debugging) Try to unify two expressions", const $ do
170 , "(Debugging) Try to unify two expressions", const $ do
171 l <- IP.simpleExpr defaultSyntax
171 l <- IP.simpleExpr defaultSyntax
172 r <- IP.simpleExpr defaultSyntax
172 r <- IP.simpleExpr defaultSyntax
173− eof
173+ P.eof
174 return (Right (DebugUnify l r))
174 return (Right (DebugUnify l r))
175 )
175 )
176 ]
176 ]
@@ -189,25 +189,25 @@ proofArgCmd names command doc =
189 (names, NoArg, doc, proofArg command)
189 (names, NoArg, doc, proofArg command)
190
190
191pCmd :: IP.IdrisParser (Either String Command)
191pCmd :: IP.IdrisParser (Either String Command)
192−pCmd = choice [ do c <- cmd names; parser c
192+pCmd = P.choice [ do c <- cmd names; parser c
193− | (names, _, _, parser) <- parserCommandsForHelp ++ parserCommands ]
193+ | (names, _, _, parser) <- parserCommandsForHelp ++ parserCommands ]
194 <|> unrecognized
194 <|> unrecognized
195 <|> nop
195 <|> nop
196 <|> eval
196 <|> eval
197− where nop = do eof; return (Right NOP)
197+ where nop = do P.eof; return (Right NOP)
198 unrecognized = do
198 unrecognized = do
199 IP.lchar ':'
199 IP.lchar ':'
200− cmd <- many anyChar
200+ cmd <- P.many P.anyChar
201 let cmd' = takeWhile (/=' ') cmd
201 let cmd' = takeWhile (/=' ') cmd
202 return (Left $ "Unrecognized command: " ++ cmd')
202 return (Left $ "Unrecognized command: " ++ cmd')
203
203
204cmd :: [String] -> IP.IdrisParser String
204cmd :: [String] -> IP.IdrisParser String
205−cmd xs = try $ do
205+cmd xs = P.try $ do
206 IP.lchar ':'
206 IP.lchar ':'
207 docmd sorted_xs
207 docmd sorted_xs
208
208
209 where docmd [] = fail "Could not parse command"
209 where docmd [] = fail "Could not parse command"
210− docmd (x:xs) = try (IP.reserved x >> return x) <|> docmd xs
210+ docmd (x:xs) = P.try (IP.reserved x >> return x) <|> docmd xs
211
211
212 sorted_xs = sortBy (\x y -> compare (length y) (length x)) xs
212 sorted_xs = sortBy (\x y -> compare (length y) (length x)) xs
213
213
@@ -215,7 +215,7 @@ cmd xs = try $ do
215noArgs :: Command -> String -> IP.IdrisParser (Either String Command)
215noArgs :: Command -> String -> IP.IdrisParser (Either String Command)
216noArgs cmd name = do
216noArgs cmd name = do
217 let emptyArgs = do
217 let emptyArgs = do
218− eof
218+ P.eof
219 return (Right cmd)
219 return (Right cmd)
220
220
221 let failure = return (Left $ ":" ++ name ++ " takes no arguments")
221 let failure = return (Left $ ":" ++ name ++ " takes no arguments")
@@ -230,27 +230,27 @@ eval = do
230exprArg :: (PTerm -> Command) -> String -> IP.IdrisParser (Either String Command)
230exprArg :: (PTerm -> Command) -> String -> IP.IdrisParser (Either String Command)
231exprArg cmd name = do
231exprArg cmd name = do
232 let noArg = do
232 let noArg = do
233− eof
233+ P.eof
234 return $ Left ("Usage is :" ++ name ++ " <expression>")
234 return $ Left ("Usage is :" ++ name ++ " <expression>")
235
235
236 let justOperator = do
236 let justOperator = do
237 (op, fc) <- IP.symbolicOperatorFC
237 (op, fc) <- IP.symbolicOperatorFC
238− eof
238+ P.eof
239 return $ Right $ cmd (PRef fc [] (sUN op))
239 return $ Right $ cmd (PRef fc [] (sUN op))
240
240
241 let properArg = do
241 let properArg = do
242 t <- IP.fullExpr defaultSyntax
242 t <- IP.fullExpr defaultSyntax
243 return $ Right (cmd t)
243 return $ Right (cmd t)
244− try noArg <|> try justOperator <|> properArg
244+ P.try noArg <|> P.try justOperator <|> properArg
245
245
246genArg :: String -> IP.IdrisParser a -> (a -> Command)
246genArg :: String -> IP.IdrisParser a -> (a -> Command)
247 -> String -> IP.IdrisParser (Either String Command)
247 -> String -> IP.IdrisParser (Either String Command)
248genArg argName argParser cmd name = do
248genArg argName argParser cmd name = do
249− let emptyArgs = do eof; failure
249+ let emptyArgs = do P.eof; failure
250 oneArg = do arg <- argParser
250 oneArg = do arg <- argParser
251− eof
251+ P.eof
252 return (Right (cmd arg))
252 return (Right (cmd arg))
253− try emptyArgs <|> oneArg <|> failure
253+ P.try emptyArgs <|> oneArg <|> failure
254 where
254 where
255 failure = return $ Left ("Usage is :" ++ name ++ " <" ++ argName ++ ">")
255 failure = return $ Left ("Usage is :" ++ name ++ " <" ++ argName ++ ">")
256
256
@@ -259,7 +259,7 @@ nameArg = genArg "name" $ fst <$> IP.name
259fnNameArg = genArg "functionname" $ fst <$> IP.fnName
259fnNameArg = genArg "functionname" $ fst <$> IP.fnName
260
260
261strArg :: (String -> Command) -> String -> IP.IdrisParser (Either String Command)
261strArg :: (String -> Command) -> String -> IP.IdrisParser (Either String Command)
262−strArg = genArg "string" (many anyChar)
262+strArg = genArg "string" (P.many P.anyChar)
263
263
264moduleArg :: (FilePath -> Command) -> String -> IP.IdrisParser (Either String Command)
264moduleArg :: (FilePath -> Command) -> String -> IP.IdrisParser (Either String Command)
265moduleArg = genArg "module" (fmap (toPath . fst) IP.identifier)
265moduleArg = genArg "module" (fmap (toPath . fst) IP.identifier)
@@ -274,18 +274,18 @@ namespaceArg = genArg "namespace" (fmap (toNS . fst) IP.identifier)
274optArg :: (Opt -> Command) -> String -> IP.IdrisParser (Either String Command)
274optArg :: (Opt -> Command) -> String -> IP.IdrisParser (Either String Command)
275optArg cmd name = do
275optArg cmd name = do
276 let emptyArgs = do
276 let emptyArgs = do
277− eof
277+ P.eof
278 return $ Left ("Usage is :" ++ name ++ " <option>")
278 return $ Left ("Usage is :" ++ name ++ " <option>")
279
279
280 let oneArg = do
280 let oneArg = do
281 o <- pOption
281 o <- pOption
282 IP.whiteSpace
282 IP.whiteSpace
283− eof
283+ P.eof
284 return (Right (cmd o))
284 return (Right (cmd o))
285
285
286 let failure = return $ Left "Unrecognized setting"
286 let failure = return $ Left "Unrecognized setting"
287
287
288− try emptyArgs <|> oneArg <|> failure
288+ P.try emptyArgs <|> oneArg <|> failure
289
289
290 where
290 where
291 pOption :: IP.IdrisParser Opt
291 pOption :: IP.IdrisParser Opt
@@ -293,7 +293,7 @@ optArg cmd name = do
293
293
294proofArg :: (Bool -> Int -> Name -> Command) -> String -> IP.IdrisParser (Either String Command)
294proofArg :: (Bool -> Int -> Name -> Command) -> String -> IP.IdrisParser (Either String Command)
295proofArg cmd name = do
295proofArg cmd name = do
296− upd <- option False $ do
296+ upd <- P.option False $ do
297 IP.lchar '!'
297 IP.lchar '!'
298 return True
298 return True
299 l <- fst <$> IP.natural
299 l <- fst <$> IP.natural
@@ -304,17 +304,17 @@ cmd_doc :: String -> IP.IdrisParser (Either String Command)
304cmd_doc name = do
304cmd_doc name = do
305 let constant = do
305 let constant = do
306 c <- fmap fst IP.constant
306 c <- fmap fst IP.constant
307− eof
307+ P.eof
308 return $ Right (DocStr (Right c) FullDocs)
308 return $ Right (DocStr (Right c) FullDocs)
309
309
310 let pType = do
310 let pType = do
311 IP.reserved "Type"
311 IP.reserved "Type"
312− eof
312+ P.eof
313 return $ Right (DocStr (Left $ IP.mkName ("Type", "")) FullDocs)
313 return $ Right (DocStr (Left $ IP.mkName ("Type", "")) FullDocs)
314
314
315 let fnName = fnNameArg (\n -> DocStr (Left n) FullDocs) name
315 let fnName = fnNameArg (\n -> DocStr (Left n) FullDocs) name
316
316
317− try constant <|> pType <|> fnName
317+ P.try constant <|> pType <|> fnName
318
318
319cmd_consolewidth :: String -> IP.IdrisParser (Either String Command)
319cmd_consolewidth :: String -> IP.IdrisParser (Either String Command)
320cmd_consolewidth name = do
320cmd_consolewidth name = do
@@ -334,19 +334,19 @@ cmd_printdepth _ = do d <- optional (fmap (fromInteger . fst) IP.natural)
334
334
335cmd_execute :: String -> IP.IdrisParser (Either String Command)
335cmd_execute :: String -> IP.IdrisParser (Either String Command)
336cmd_execute name = do
336cmd_execute name = do
337− tm <- option maintm (IP.fullExpr defaultSyntax)
337+ tm <- P.option maintm (IP.fullExpr defaultSyntax)
338 return (Right (Execute tm))
338 return (Right (Execute tm))
339 where
339 where
340 maintm = PRef (fileFC "(repl)") [] (sNS (sUN "main") ["Main"])
340 maintm = PRef (fileFC "(repl)") [] (sNS (sUN "main") ["Main"])
341
341
342cmd_dynamic :: String -> IP.IdrisParser (Either String Command)
342cmd_dynamic :: String -> IP.IdrisParser (Either String Command)
343cmd_dynamic name = do
343cmd_dynamic name = do
344− let optArg = do l <- many anyChar
344+ let optArg = do l <- P.many P.anyChar
345 if (l /= "")
345 if (l /= "")
346 then return $ Right (DynamicLink l)
346 then return $ Right (DynamicLink l)
347 else return $ Right ListDynamic
347 else return $ Right ListDynamic
348 let failure = return $ Left $ "Usage is :" ++ name ++ " [<library>]"
348 let failure = return $ Left $ "Usage is :" ++ name ++ " [<library>]"
349− try optArg <|> failure
349+ P.try optArg <|> failure
350
350
351cmd_pprint :: String -> IP.IdrisParser (Either String Command)
351cmd_pprint :: String -> IP.IdrisParser (Either String Command)
352cmd_pprint name = do
352cmd_pprint name = do
@@ -376,43 +376,43 @@ cmd_compile name = do
376 let hasOneArg = do
376 let hasOneArg = do
377 i <- get
377 i <- get
378 f <- fst <$> IP.identifier
378 f <- fst <$> IP.identifier
379− eof
379+ P.eof
380 return $ Right (Compile defaultCodegen f)
380 return $ Right (Compile defaultCodegen f)
381
381
382 let hasTwoArgs = do
382 let hasTwoArgs = do
383 i <- get
383 i <- get
384 codegen <- codegenOption
384 codegen <- codegenOption
385 f <- fst <$> IP.identifier
385 f <- fst <$> IP.identifier
386− eof
386+ P.eof
387 return $ Right (Compile codegen f)
387 return $ Right (Compile codegen f)
388
388
389 let failure = return $ Left $ "Usage is :" ++ name ++ " [<codegen>] <filename>"
389 let failure = return $ Left $ "Usage is :" ++ name ++ " [<codegen>] <filename>"
390− try hasTwoArgs <|> try hasOneArg <|> failure
390+ P.try hasTwoArgs <|> P.try hasOneArg <|> failure
391
391
392cmd_addproof :: String -> IP.IdrisParser (Either String Command)
392cmd_addproof :: String -> IP.IdrisParser (Either String Command)
393cmd_addproof name = do
393cmd_addproof name = do
394− n <- option Nothing $ do
394+ n <- P.option Nothing $ do
395 x <- fst <$> IP.name
395 x <- fst <$> IP.name
396 return (Just x)
396 return (Just x)
397− eof
397+ P.eof
398 return (Right (AddProof n))
398 return (Right (AddProof n))
399
399
400cmd_log :: String -> IP.IdrisParser (Either String Command)
400cmd_log :: String -> IP.IdrisParser (Either String Command)
401cmd_log name = do
401cmd_log name = do
402 i <- fmap (fromIntegral . fst) IP.natural
402 i <- fmap (fromIntegral . fst) IP.natural
403− eof
403+ P.eof
404 return (Right (LogLvl i))
404 return (Right (LogLvl i))
405
405
406cmd_verb :: String -> IP.IdrisParser (Either String Command)
406cmd_verb :: String -> IP.IdrisParser (Either String Command)
407cmd_verb name = do
407cmd_verb name = do
408 i <- fmap (fromIntegral . fst) IP.natural
408 i <- fmap (fromIntegral . fst) IP.natural
409− eof
409+ P.eof
410 return (Right (Verbosity i))
410 return (Right (Verbosity i))
411
411
412cmd_cats :: String -> IP.IdrisParser (Either String Command)
412cmd_cats :: String -> IP.IdrisParser (Either String Command)
413cmd_cats name = do
413cmd_cats name = do
414− cs <- sepBy pLogCats (IP.whiteSpace)
414+ cs <- P.sepBy pLogCats (IP.whiteSpace)
415− eof
415+ P.eof
416 return $ Right $ LogCategory (concat cs)
416 return $ Right $ LogCategory (concat cs)
417 where
417 where
418 badCat = do
418 badCat = do
@@ -420,26 +420,26 @@ cmd_cats name = do
420 fail $ "Category: " ++ c ++ " is not recognised."
420 fail $ "Category: " ++ c ++ " is not recognised."
421
421
422 pLogCats :: IP.IdrisParser [LogCat]
422 pLogCats :: IP.IdrisParser [LogCat]
423− pLogCats = try (parserCats <$ IP.symbol (strLogCat IParse))
423+ pLogCats = P.try (parserCats <$ IP.symbol (strLogCat IParse))
424− <|> try (elabCats <$ IP.symbol (strLogCat IElab))
424+ <|> P.try (elabCats <$ IP.symbol (strLogCat IElab))
425− <|> try (codegenCats <$ IP.symbol (strLogCat ICodeGen))
425+ <|> P.try (codegenCats <$ IP.symbol (strLogCat ICodeGen))
426− <|> try ([ICoverage] <$ IP.symbol (strLogCat ICoverage))
426+ <|> P.try ([ICoverage] <$ IP.symbol (strLogCat ICoverage))
427− <|> try ([IIBC] <$ IP.symbol (strLogCat IIBC))
427+ <|> P.try ([IIBC] <$ IP.symbol (strLogCat IIBC))
428− <|> try ([IErasure] <$ IP.symbol (strLogCat IErasure))
428+ <|> P.try ([IErasure] <$ IP.symbol (strLogCat IErasure))
429 <|> badCat
429 <|> badCat
430
430
431cmd_let :: String -> IP.IdrisParser (Either String Command)
431cmd_let :: String -> IP.IdrisParser (Either String Command)
432cmd_let name = do
432cmd_let name = do
433− defn <- concat <$> many (IP.decl defaultSyntax)
433+ defn <- concat <$> P.many (IP.decl defaultSyntax)
434 return (Right (NewDefn defn))
434 return (Right (NewDefn defn))
435
435
436cmd_unlet :: String -> IP.IdrisParser (Either String Command)
436cmd_unlet :: String -> IP.IdrisParser (Either String Command)
437−cmd_unlet name = (Right . Undefine) `fmap` many (fst <$> IP.name)
437+cmd_unlet name = (Right . Undefine) `fmap` P.many (fst <$> IP.name)
438
438
439cmd_loadto :: String -> IP.IdrisParser (Either String Command)
439cmd_loadto :: String -> IP.IdrisParser (Either String Command)
440cmd_loadto name = do
440cmd_loadto name = do
441 toline <- fmap (fromInteger . fst) IP.natural
441 toline <- fmap (fromInteger . fst) IP.natural
442− f <- many anyChar;
442+ f <- P.many P.anyChar
443 return (Right (Load f (Just toline)))
443 return (Right (Load f (Just toline)))
444
444
445cmd_colour :: String -> IP.IdrisParser (Either String Command)
445cmd_colour :: String -> IP.IdrisParser (Either String Command)
@@ -461,27 +461,27 @@ cmd_colour name = fmap Right pSetColourCmd
461 pSetColourCmd :: IP.IdrisParser Command
461 pSetColourCmd :: IP.IdrisParser Command
462 pSetColourCmd = (do c <- pColourType
462 pSetColourCmd = (do c <- pColourType
463 let defaultColour = IdrisColour Nothing True False False False
463 let defaultColour = IdrisColour Nothing True False False False
464− opts <- sepBy pColourMod (IP.whiteSpace)
464+ opts <- P.sepBy pColourMod (IP.whiteSpace)
465 let colour = foldr ($) defaultColour $ reverse opts
465 let colour = foldr ($) defaultColour $ reverse opts
466 return $ SetColour c colour)
466 return $ SetColour c colour)
467− <|> try (IP.symbol "on" >> return ColourOn)
467+ <|> P.try (IP.symbol "on" >> return ColourOn)
468− <|> try (IP.symbol "off" >> return ColourOff)
468+ <|> P.try (IP.symbol "off" >> return ColourOff)
469
469
470 pColour :: IP.IdrisParser (Maybe Color)
470 pColour :: IP.IdrisParser (Maybe Color)
471 pColour = doColour colours
471 pColour = doColour colours
472 where doColour [] = fail "Unknown colour"
472 where doColour [] = fail "Unknown colour"
473− doColour ((s, c):cs) = (try (IP.symbol s) >> return c) <|> doColour cs
473+ doColour ((s, c):cs) = (P.try (IP.symbol s) >> return c) <|> doColour cs
474
474
475 pColourMod :: IP.IdrisParser (IdrisColour -> IdrisColour)
475 pColourMod :: IP.IdrisParser (IdrisColour -> IdrisColour)
476− pColourMod = try (doVivid <$ IP.symbol "vivid")
476+ pColourMod = P.try (doVivid <$ IP.symbol "vivid")
477− <|> try (doDull <$ IP.symbol "dull")
477+ <|> P.try (doDull <$ IP.symbol "dull")
478− <|> try (doUnderline <$ IP.symbol "underline")
478+ <|> P.try (doUnderline <$ IP.symbol "underline")
479− <|> try (doNoUnderline <$ IP.symbol "nounderline")
479+ <|> P.try (doNoUnderline <$ IP.symbol "nounderline")
480− <|> try (doBold <$ IP.symbol "bold")
480+ <|> P.try (doBold <$ IP.symbol "bold")
481− <|> try (doNoBold <$ IP.symbol "nobold")
481+ <|> P.try (doNoBold <$ IP.symbol "nobold")
482− <|> try (doItalic <$ IP.symbol "italic")
482+ <|> P.try (doItalic <$ IP.symbol "italic")
483− <|> try (doNoItalic <$ IP.symbol "noitalic")
483+ <|> P.try (doNoItalic <$ IP.symbol "noitalic")
484− <|> try (pColour >>= return . doSetColour)
484+ <|> P.try (pColour >>= return . doSetColour)
485 where doVivid i = i { vivid = True }
485 where doVivid i = i { vivid = True }
486 doDull i = i { vivid = False }
486 doDull i = i { vivid = False }
487 doUnderline i = i { underline = True }
487 doUnderline i = i { underline = True }
@@ -501,9 +501,9 @@ cmd_colour name = fmap Right pSetColourCmd
501 pColourType = doColourType colourTypes
501 pColourType = doColourType colourTypes
502 where doColourType [] = fail $ "Unknown colour category. Options: " ++
502 where doColourType [] = fail $ "Unknown colour category. Options: " ++
503 (concat . intersperse ", " . map fst) colourTypes
503 (concat . intersperse ", " . map fst) colourTypes
504− doColourType ((s,ct):cts) = (try (IP.symbol s) >> return ct) <|> doColourType cts
504+ doColourType ((s,ct):cts) = (P.try (IP.symbol s) >> return ct) <|> doColourType cts
505
505
506−idChar = oneOf (['a'..'z'] ++ ['A'..'Z'] ++ ['0'..'9'] ++ ['_'])
506+idChar = P.oneOf (['a'..'z'] ++ ['A'..'Z'] ++ ['0'..'9'] ++ ['_'])
507
507
508cmd_apropos :: String -> IP.IdrisParser (Either String Command)
508cmd_apropos :: String -> IP.IdrisParser (Either String Command)
509cmd_apropos = packageBasedCmd (some idChar) Apropos
509cmd_apropos = packageBasedCmd (some idChar) Apropos
@@ -511,11 +511,11 @@ cmd_apropos = packageBasedCmd (some idChar) Apropos
511packageBasedCmd :: IP.IdrisParser a -> ([PkgName] -> a -> Command)
511packageBasedCmd :: IP.IdrisParser a -> ([PkgName] -> a -> Command)
512 -> String -> IP.IdrisParser (Either String Command)
512 -> String -> IP.IdrisParser (Either String Command)
513packageBasedCmd valParser cmd name =
513packageBasedCmd valParser cmd name =
514− try (do IP.lchar '('
514+ P.try (do IP.lchar '('
515− pkgs <- sepBy (pkg <* IP.whiteSpace) (IP.lchar ',')
515+ pkgs <- P.sepBy (pkg <* IP.whiteSpace) (IP.lchar ',')
516− IP.lchar ')'
516+ IP.lchar ')'
517− val <- valParser
517+ val <- valParser
518− return (Right (cmd pkgs val)))
518+ return (Right (cmd pkgs val)))
519 <|> do val <- valParser
519 <|> do val <- valParser
520 return (Right (cmd [] val))
520 return (Right (cmd [] val))
521 where
521 where
@@ -527,14 +527,14 @@ cmd_search = packageBasedCmd
527
527
528cmd_proofsearch :: String -> IP.IdrisParser (Either String Command)
528cmd_proofsearch :: String -> IP.IdrisParser (Either String Command)
529cmd_proofsearch name = do
529cmd_proofsearch name = do
530− upd <- option False (True <$ IP.lchar '!')
530+ upd <- P.option False (True <$ IP.lchar '!')
531 l <- fmap (fromInteger . fst) IP.natural; n <- fst <$> IP.name
531 l <- fmap (fromInteger . fst) IP.natural; n <- fst <$> IP.name
532− hints <- many (fst <$> IP.fnName)
532+ hints <- P.many (fst <$> IP.fnName)
533 return (Right (DoProofSearch upd True l n hints))
533 return (Right (DoProofSearch upd True l n hints))
534
534
535cmd_refine :: String -> IP.IdrisParser (Either String Command)
535cmd_refine :: String -> IP.IdrisParser (Either String Command)
536cmd_refine name = do
536cmd_refine name = do
537− upd <- option False (do IP.lchar '!'; return True)
537+ upd <- P.option False (do IP.lchar '!'; return True)
538 l <- fmap (fromInteger . fst) IP.natural; n <- fst <$> IP.name
538 l <- fmap (fromInteger . fst) IP.natural; n <- fst <$> IP.name
539 hint <- fst <$> IP.fnName
539 hint <- fst <$> IP.fnName
540 return (Right (DoProofSearch upd False l n [hint]))
540 return (Right (DoProofSearch upd False l n [hint]))