on master help sign in
Merge branch 'master' of https://github.com/jmorag/Idris-dev into megaparsec7
0b669c7Jorge Acereda
idris.cabal+2−1
@@ -289,10 +289,11 @@ Library
289 , fingertree >= 0.1.4.1 && < 0.2
289 , fingertree >= 0.1.4.1 && < 0.2
290 , haskeline >= 0.7 && < 0.8
290 , haskeline >= 0.7 && < 0.8
291 , ieee754 >= 0.7 && < 0.9
291 , ieee754 >= 0.7 && < 0.9
292− , megaparsec >= 6.2 && < 7
292+ , megaparsec >= 7.0.4 && < 8
293 , mtl >= 2.1 && < 2.3
293 , mtl >= 2.1 && < 2.3
294 , network >= 2.7 && < 2.9
294 , network >= 2.7 && < 2.9
295 , optparse-applicative >= 0.13 && < 0.15
295 , optparse-applicative >= 0.13 && < 0.15
296+ , parser-combinators >= 1.0.0
296 , pretty < 1.2
297 , pretty < 1.2
297 , process < 1.7
298 , process < 1.7
298 , regex-tdfa >= 1.2
299 , regex-tdfa >= 1.2
src/Idris/Package/Parser.hs+1−2
@@ -27,14 +27,13 @@ import System.Exit
27import System.FilePath (isValid, takeExtension, takeFileName)
27import System.FilePath (isValid, takeExtension, takeFileName)
28import Text.Megaparsec ((<?>))
28import Text.Megaparsec ((<?>))
29import qualified Text.Megaparsec as P
29import qualified Text.Megaparsec as P
30−import qualified Text.Megaparsec.Char as P
31import qualified Text.PrettyPrint.ANSI.Leijen as PP
30import qualified Text.PrettyPrint.ANSI.Leijen as PP
32
31
33type PParser = Parser PkgDesc
32type PParser = Parser PkgDesc
34
33
35parseDesc :: FilePath -> IO PkgDesc
34parseDesc :: FilePath -> IO PkgDesc
36parseDesc fp = do
35parseDesc fp = do
37− when (not $ takeExtension fp == ".ipkg") $ do
36+ unless (takeExtension fp == ".ipkg") $ do
38 putStrLn $ unwords ["The presented iPKG file does not have a '.ipkg' extension:", show fp]
37 putStrLn $ unwords ["The presented iPKG file does not have a '.ipkg' extension:", show fp]
39 exitWith (ExitFailure 1)
38 exitWith (ExitFailure 1)
40 res <- doesFileExist fp
39 res <- doesFileExist fp
src/Idris/Parser.hs−1
@@ -60,7 +60,6 @@ import qualified System.Directory as Dir (doesFileExist, getModificationTime,
60import System.FilePath
60import System.FilePath
61import Text.Megaparsec ((<?>))
61import Text.Megaparsec ((<?>))
62import qualified Text.Megaparsec as P
62import qualified Text.Megaparsec as P
63−import qualified Text.Megaparsec.Char as P
64import qualified Text.PrettyPrint.ANSI.Leijen as PP
63import qualified Text.PrettyPrint.ANSI.Leijen as PP
65
64
66{-
65{-
src/Idris/Parser/Expr.hs+2−2
@@ -20,6 +20,7 @@ import Prelude hiding (pi)
20import Control.Applicative
20import Control.Applicative
21import Control.Arrow (left)
21import Control.Arrow (left)
22import Control.Monad
22import Control.Monad
23+import qualified Control.Monad.Combinators.Expr as P
23import Control.Monad.State.Strict
24import Control.Monad.State.Strict
24import Data.Function (on)
25import Data.Function (on)
25import Data.List
26import Data.List
@@ -27,7 +28,6 @@ import Data.Maybe
27import Text.Megaparsec ((<?>))
28import Text.Megaparsec ((<?>))
28import qualified Text.Megaparsec as P
29import qualified Text.Megaparsec as P
29import qualified Text.Megaparsec.Char as P
30import qualified Text.Megaparsec.Char as P
30−import qualified Text.Megaparsec.Expr as P
31
31
32-- | Allow implicit type declarations
32-- | Allow implicit type declarations
33allowImp :: SyntaxInfo -> SyntaxInfo
33allowImp :: SyntaxInfo -> SyntaxInfo
@@ -1406,7 +1406,7 @@ VerbatimString_t ::=
1406 -}
1406 -}
1407verbatimStringLiteral :: Parsing m => m String
1407verbatimStringLiteral :: Parsing m => m String
1408verbatimStringLiteral = token $ do P.try $ string "\"\"\""
1408verbatimStringLiteral = token $ do P.try $ string "\"\"\""
1409− str <- P.manyTill P.anyChar $ P.try (string "\"\"\"")
1409+ str <- P.manyTill P.anySingle $ P.try (string "\"\"\"")
1410 moreQuotes <- P.many $ P.char '"'
1410 moreQuotes <- P.many $ P.char '"'
1411 return $ str ++ moreQuotes
1411 return $ str ++ moreQuotes
1412
1412
src/Idris/Parser/Helpers.hs+1−1
@@ -397,7 +397,7 @@ popIndent = do ist <- get
397
397
398-- | Gets current indentation
398-- | Gets current indentation
399indent :: Parsing m => m Int
399indent :: Parsing m => m Int
400−indent = P.unPos . P.sourceColumn <$> P.getPosition
400+indent = P.unPos . P.sourceColumn <$> P.getSourcePos
401
401
402-- | Gets last indentation
402-- | Gets last indentation
403lastIndent :: (MonadState IState m) => m Int
403lastIndent :: (MonadState IState m) => m Int
src/Idris/Parser/Ops.hs+1−2
@@ -17,14 +17,13 @@ import Prelude hiding (pi)
17
17
18import Control.Applicative
18import Control.Applicative
19import Control.Monad
19import Control.Monad
20+import qualified Control.Monad.Combinators.Expr as P
20import Control.Monad.State.Strict
21import Control.Monad.State.Strict
21import Data.Char (isAlpha)
22import Data.Char (isAlpha)
22import Data.List
23import Data.List
23import Data.List.NonEmpty (fromList)
24import Data.List.NonEmpty (fromList)
24import Text.Megaparsec ((<?>))
25import Text.Megaparsec ((<?>))
25import qualified Text.Megaparsec as P
26import qualified Text.Megaparsec as P
26−import qualified Text.Megaparsec.Char as P
27−import qualified Text.Megaparsec.Expr as P
28
27
29-- | Creates table for fixity declarations to build expression parser
28-- | Creates table for fixity declarations to build expression parser
30-- using pre-build and user-defined operator/fixity declarations
29-- using pre-build and user-defined operator/fixity declarations
src/Idris/Parser/Stack.hs+9−8
@@ -57,23 +57,24 @@ type Parsing m = (P.MonadParsec Void String m, MonadWriter FC m)
57runparser :: Parser st res -> st -> String -> String -> Either ParseError res
57runparser :: Parser st res -> st -> String -> String -> Either ParseError res
58runparser p i inputname s =
58runparser p i inputname s =
59 case P.parse (runWriterT (evalStateT p i)) inputname s of
59 case P.parse (runWriterT (evalStateT p i)) inputname s of
60− Left err -> Left $ ParseError s err
60+ Left err -> Left $ ParseError err
61 Right v -> Right $ fst v
61 Right v -> Right $ fst v
62
62
63{- * Parse errors -}
63{- * Parse errors -}
64
64
65−data ParseError = ParseError String (P.ParseError (P.Token String) Void)
65+newtype ParseError = ParseError (P.ParseErrorBundle String Void)
66
66
67instance Message ParseError where
67instance Message ParseError where
68− messageExtent (ParseError _ err) = sourcePositionFC pos
68+ messageExtent (ParseError err) = sourcePositionFC pos
69 where
69 where
70+ (pos, _) = P.reachOffsetNoLine (P.errorOffset err') (P.bundlePosState err)
70− (pos NonEmpty.:| _) = P.errorPos err
71+ err' = NonEmpty.head . P.bundleErrors $ err
71− messageText (ParseError _ err) = PP.text . init . P.parseErrorTextPretty $ err
72+ messageText (ParseError err) = PP.text . init . P.errorBundlePretty $ err
72− messageSource (ParseError src _) = Just src
73+ messageSource (ParseError err) = Just . P.sourceName . P.pstateSourcePos . P.bundlePosState $ err
73
74
74-- | A fully formatted parse error, with caret and bar, etc.
75-- | A fully formatted parse error, with caret and bar, etc.
75prettyError :: ParseError -> String
76prettyError :: ParseError -> String
76−prettyError (ParseError s err) = P.parseErrorPretty' s err
77+prettyError (ParseError err) = P.errorBundlePretty err
77
78
78{- * Mark and restore -}
79{- * Mark and restore -}
79
80
@@ -104,7 +105,7 @@ sourcePositionFC (P.SourcePos name line column) =
104-- This is useful when the position is needed in a way unrelated to the
105-- This is useful when the position is needed in a way unrelated to the
105-- heirarchy of parsers. Prefer using @withExtent@ and friends.
106-- heirarchy of parsers. Prefer using @withExtent@ and friends.
106getFC :: Parsing m => m FC
107getFC :: Parsing m => m FC
107−getFC = sourcePositionFC <$> P.getPosition
108+getFC = sourcePositionFC <$> P.getSourcePos
108
109
109-- | Add an extent (widen) our current parsing context.
110-- | Add an extent (widen) our current parsing context.
110addExtent :: MonadWriter FC m => FC -> m ()
111addExtent :: MonadWriter FC m => FC -> m ()
src/Idris/REPL/Parser.hs+5−6
@@ -33,7 +33,6 @@ import Data.List.Split (splitOn)
33import System.Console.ANSI (Color(..))
33import System.Console.ANSI (Color(..))
34import System.FilePath ((</>))
34import System.FilePath ((</>))
35import qualified Text.Megaparsec as P
35import qualified Text.Megaparsec as P
36−import qualified Text.Megaparsec.Char as P
37
36
38parseCmd :: IState -> String -> String -> Either IP.ParseError (Either String Command)
37parseCmd :: IState -> String -> String -> Either IP.ParseError (Either String Command)
39parseCmd i inputname = IP.runparser pCmd i inputname . trim
38parseCmd i inputname = IP.runparser pCmd i inputname . trim
@@ -68,7 +67,7 @@ parserCommandsForHelp =
68 , nameArgCmd ["miss", "missing"] Missing "Show missing clauses"
67 , nameArgCmd ["miss", "missing"] Missing "Show missing clauses"
69 , (["doc"], NameArg, "Show internal documentation", cmd_doc)
68 , (["doc"], NameArg, "Show internal documentation", cmd_doc)
70 , (["mkdoc"], NamespaceArg, "Generate IdrisDoc for namespace(s) and dependencies"
69 , (["mkdoc"], NamespaceArg, "Generate IdrisDoc for namespace(s) and dependencies"
71− , genArg "namespace" (P.many P.anyChar) MakeDoc)
70+ , genArg "namespace" (P.many P.anySingle) MakeDoc)
72 , (["apropos"], SeqArgs (OptionalArg PkgArgs) NameArg, " Search names, types, and documentation"
71 , (["apropos"], SeqArgs (OptionalArg PkgArgs) NameArg, " Search names, types, and documentation"
73 , cmd_apropos)
72 , cmd_apropos)
74 , (["s", "search"], SeqArgs (OptionalArg PkgArgs) ExprArg
73 , (["s", "search"], SeqArgs (OptionalArg PkgArgs) ExprArg
@@ -198,7 +197,7 @@ pCmd = P.choice [ do c <- cmd names; parser c
198 where nop = do P.eof; return (Right NOP)
197 where nop = do P.eof; return (Right NOP)
199 unrecognized = do
198 unrecognized = do
200 IP.lchar ':'
199 IP.lchar ':'
201− cmd <- P.many P.anyChar
200+ cmd <- P.many P.anySingle
202 let cmd' = takeWhile (/=' ') cmd
201 let cmd' = takeWhile (/=' ') cmd
203 return (Left $ "Unrecognized command: " ++ cmd')
202 return (Left $ "Unrecognized command: " ++ cmd')
204
203
@@ -260,7 +259,7 @@ nameArg = genArg "name" IP.name
260fnNameArg = genArg "functionname" IP.fnName
259fnNameArg = genArg "functionname" IP.fnName
261
260
262strArg :: (String -> Command) -> String -> IP.IdrisParser (Either String Command)
261strArg :: (String -> Command) -> String -> IP.IdrisParser (Either String Command)
263−strArg = genArg "string" (P.many P.anyChar)
262+strArg = genArg "string" (P.many P.anySingle)
264
263
265moduleArg :: (FilePath -> Command) -> String -> IP.IdrisParser (Either String Command)
264moduleArg :: (FilePath -> Command) -> String -> IP.IdrisParser (Either String Command)
266moduleArg = genArg "module" (fmap toPath IP.identifier)
265moduleArg = genArg "module" (fmap toPath IP.identifier)
@@ -342,7 +341,7 @@ cmd_execute name = do
342
341
343cmd_dynamic :: String -> IP.IdrisParser (Either String Command)
342cmd_dynamic :: String -> IP.IdrisParser (Either String Command)
344cmd_dynamic name = do
343cmd_dynamic name = do
345− let optArg = do l <- P.many P.anyChar
344+ let optArg = do l <- P.many P.anySingle
346 if (l /= "")
345 if (l /= "")
347 then return $ Right (DynamicLink l)
346 then return $ Right (DynamicLink l)
348 else return $ Right ListDynamic
347 else return $ Right ListDynamic
@@ -440,7 +439,7 @@ cmd_unlet name = Right . Undefine <$> P.many IP.name
440cmd_loadto :: String -> IP.IdrisParser (Either String Command)
439cmd_loadto :: String -> IP.IdrisParser (Either String Command)
441cmd_loadto name = do
440cmd_loadto name = do
442 toline <- fromInteger <$> IP.natural
441 toline <- fromInteger <$> IP.natural
443− f <- P.many P.anyChar
442+ f <- P.many P.anySingle
444 return (Right (Load f (Just toline)))
443 return (Right (Load f (Just toline)))
445
444
446cmd_colour :: String -> IP.IdrisParser (Either String Command)
445cmd_colour :: String -> IP.IdrisParser (Either String Command)
stack.yaml+4−1
@@ -4,7 +4,10 @@ resolver: lts-12.21
4packages:
4packages:
5 - location: .
5 - location: .
6
6
7−extra-deps: []
7+extra-deps:
8+ - megaparsec-7.0.4
9+ - parser-combinators-1.0.0
10+
8
11
9flags:
12flags:
10 idris:
13 idris: