on master help sign in
Allow upper case letter in package name and only normalize for equality and on disk
4878fe4Vincent Hanquez
src/Idris/Imports.hs+14−7
@@ -18,7 +18,7 @@ import IRTS.System (getIdrisLibDir)
18
18
19import Control.Applicative ((<$>))
19import Control.Applicative ((<$>))
20import Control.Monad.State.Strict
20import Control.Monad.State.Strict
21−import Data.Char (isDigit, isLower)
21+import Data.Char (isDigit, isAlpha, toLower)
22import Data.List (isSuffixOf)
22import Data.List (isSuffixOf)
23import System.Directory
23import System.Directory
24import System.FilePath
24import System.FilePath
@@ -26,8 +26,15 @@ import System.FilePath
26data IFileType = IDR FilePath | LIDR FilePath | IBC FilePath IFileType
26data IFileType = IDR FilePath | LIDR FilePath | IBC FilePath IFileType
27 deriving (Show, Eq)
27 deriving (Show, Eq)
28
28
29−newtype PkgName = PkgName { unPkgName :: String }
29+newtype PkgName = PkgName String
30− deriving (Show, Eq)
30+
31+unPkgName :: PkgName -> String
32+unPkgName (PkgName s) = map toLower s
33+
34+instance Show PkgName where
35+ show (PkgName pkg) = pkg
36+instance Eq PkgName where
37+ a == b = unPkgName a == unPkgName b
31
38
32unInitializedPkgName :: PkgName
39unInitializedPkgName :: PkgName
33unInitializedPkgName = PkgName ""
40unInitializedPkgName = PkgName ""
@@ -35,10 +42,10 @@ unInitializedPkgName = PkgName ""
35pkgName :: String -> Either String PkgName
42pkgName :: String -> Either String PkgName
36pkgName "" = Left "empty package name"
43pkgName "" = Left "empty package name"
37pkgName s@(f:l)
44pkgName s@(f:l)
38− | not $ isLower f =
45+ | not $ isAlpha f =
39− Left "package name need to start by a lower alpha"
46+ Left "package name need to start by a letter"
40− | not $ all (\c -> isLower c || isDigit c || c `elem` "-_") l =
47+ | not $ all (\c -> isAlpha c || isDigit c || c `elem` "-_") l =
41− Left "package name need to contain only lower alpha, digits, and -_"
48+ Left "package name need to contain only letter, digits, and -_"
42 | otherwise = Right $ PkgName s
49 | otherwise = Right $ PkgName s
43
50
44-- | Get the index file name for a package name
51-- | Get the index file name for a package name
src/Idris/Package.hs+2−2
@@ -231,7 +231,7 @@ documentPkg copts (install,fp) = do
231 pkgDocDir <- makeAbsolute (iDocDir </> unPkgName (pkgname pkgdesc))
231 pkgDocDir <- makeAbsolute (iDocDir </> unPkgName (pkgname pkgdesc))
232 let out_dir = if install then pkgDocDir else outputDir
232 let out_dir = if install then pkgDocDir else outputDir
233 when install $ do
233 when install $ do
234− putStrLn $ unwords ["Attempting to install IdrisDocs for", unPkgName $ pkgname pkgdesc, "in:", out_dir]
234+ putStrLn $ unwords ["Attempting to install IdrisDocs for", show $ pkgname pkgdesc, "in:", out_dir]
235
235
236 docRes <- generateDocs ist mods out_dir
236 docRes <- generateDocs ist mods out_dir
237 case docRes of
237 case docRes of
@@ -367,7 +367,7 @@ testLib warn p f
367 case e of
367 case e of
368 ExitSuccess -> return True
368 ExitSuccess -> return True
369 _ -> do if warn
369 _ -> do if warn
370− then do putStrLn $ "Not building " ++ unPkgName p ++
370+ then do putStrLn $ "Not building " ++ show p ++
371 " due to missing library " ++ f
371 " due to missing library " ++ f
372 return False
372 return False
373 else fail $ "Missing library " ++ f
373 else fail $ "Missing library " ++ f
src/Idris/Package/Parser.hs+1−1
@@ -145,7 +145,7 @@ pClause = do reserved "executable"; lchar '=';
145 <|> do reserved "pkgs"; lchar '=';
145 <|> do reserved "pkgs"; lchar '=';
146 ps <- sepBy1 (pPkgName <* someSpace) (lchar ',')
146 ps <- sepBy1 (pPkgName <* someSpace) (lchar ',')
147 st <- get
147 st <- get
148− let pkgs = pureArgParser $ concatMap (\x -> ["-p", unPkgName x]) ps
148+ let pkgs = pureArgParser $ concatMap (\x -> ["-p", show x]) ps
149
149
150 put (st { pkgdeps = ps `union` (pkgdeps st)
150 put (st { pkgdeps = ps `union` (pkgdeps st)
151 , idris_opts = pkgs ++ idris_opts st})
151 , idris_opts = pkgs ++ idris_opts st})
src/Idris/Parser/Helpers.hs+2−2
@@ -398,8 +398,8 @@ operatorLetter = oneOf opChars
398-- | Parse a package name
398-- | Parse a package name
399packageName :: MonadicParsing m => m String
399packageName :: MonadicParsing m => m String
400packageName = (:) <$> oneOf firstChars <*> many (oneOf remChars)
400packageName = (:) <$> oneOf firstChars <*> many (oneOf remChars)
401− where firstChars = ['a'..'z']
401+ where firstChars = ['a'..'z'] ++ ['A'..'Z']
402− remChars = ['a'..'z'] ++ ['0'..'9'] ++ ['-','_']
402+ remChars = ['a'..'z'] ++ ['A'..'Z'] ++ ['0'..'9'] ++ ['-','_']
403
403
404commentMarkers :: [String]
404commentMarkers :: [String]
405commentMarkers = [ "--", "|||" ]
405commentMarkers = [ "--", "|||" ]
src/Idris/REPL.hs+1−2
@@ -65,7 +65,6 @@ import Idris.Help
65import Idris.IBC
65import Idris.IBC
66import qualified Idris.IdeMode as IdeMode
66import qualified Idris.IdeMode as IdeMode
67import Idris.IdrisDoc
67import Idris.IdrisDoc
68−import Idris.Imports
69import Idris.Info
68import Idris.Info
70import Idris.Inliner
69import Idris.Inliner
71import Idris.Interactive
70import Idris.Interactive
@@ -1374,7 +1373,7 @@ process fn (SetPrinterDepth d) = setDepth d
1374process fn (Apropos pkgs a) =
1373process fn (Apropos pkgs a) =
1375 do orig <- getIState
1374 do orig <- getIState
1376 when (not (null pkgs)) $
1375 when (not (null pkgs)) $
1377− iputStrLn $ "Searching packages: " ++ showSep ", " (map unPkgName pkgs)
1376+ iputStrLn $ "Searching packages: " ++ showSep ", " (map show pkgs)
1378 mapM_ loadPkgIndex pkgs
1377 mapM_ loadPkgIndex pkgs
1379 ist <- getIState
1378 ist <- getIState
1380 let mods = aproposModules ist (T.pack a)
1379 let mods = aproposModules ist (T.pack a)
src/Idris/TypeSearch.hs+2−2
@@ -26,7 +26,7 @@ import Idris.Delaborate (delabTy)
26import Idris.Docstrings (noDocs, overview)
26import Idris.Docstrings (noDocs, overview)
27import Idris.Elab.Type (elabType)
27import Idris.Elab.Type (elabType)
28import Idris.IBC
28import Idris.IBC
29−import Idris.Imports (PkgName, unPkgName)
29+import Idris.Imports (PkgName)
30import Idris.Output (iPrintResult, iRenderError, iRenderOutput, iRenderResult,
30import Idris.Output (iPrintResult, iRenderError, iRenderOutput, iRenderResult,
31 iputStrLn, prettyDocumentedIst)
31 iputStrLn, prettyDocumentedIst)
32
32
@@ -53,7 +53,7 @@ searchByType :: [PkgName] -> PTerm -> Idris ()
53searchByType pkgs pterm = do
53searchByType pkgs pterm = do
54 i <- getIState -- save original
54 i <- getIState -- save original
55 when (not (null pkgs)) $
55 when (not (null pkgs)) $
56− iputStrLn $ "Searching packages: " ++ showSep ", " (map unPkgName pkgs)
56+ iputStrLn $ "Searching packages: " ++ showSep ", " (map show pkgs)
57
57
58 mapM_ loadPkgIndex pkgs
58 mapM_ loadPkgIndex pkgs
59 pterm' <- addUsingConstraints syn emptyFC pterm
59 pterm' <- addUsingConstraints syn emptyFC pterm