git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Use Text over String (#2418)
92c8c65Christoph Hegemann
examples/passing/StringEscapes.purs+2−1
@@ -13,5 +13,6 @@ main = do
13 assert singleCharacter
13 assert singleCharacter
14 assert hex
14 assert hex
15 assert decimal
15 assert decimal
16+-- TODO: Broken in #2418 should be fixed after #2434 is fixed
16− assert surrogatePair
17+-- assert surrogatePair
17 log "Done"
18 log "Done"
hierarchy/Main.hs+2−1
@@ -25,6 +25,7 @@ import Data.List (intercalate,nub,sort)
25import Data.Foldable (for_)
25import Data.Foldable (for_)
26import Data.Version (showVersion)
26import Data.Version (showVersion)
27import Data.Monoid ((<>))
27import Data.Monoid ((<>))
28+import qualified Data.Text as T
28
29
29import Options.Applicative (Parser)
30import Options.Applicative (Parser)
30import qualified Options.Applicative as Opts
31import qualified Options.Applicative as Opts
@@ -56,7 +57,7 @@ instance Ord SuperMap where
56 getCls = either id snd
57 getCls = either id snd
57
58
58runModuleName :: P.ModuleName -> String
59runModuleName :: P.ModuleName -> String
59−runModuleName (P.ModuleName pns) = intercalate "_" (P.runProperName `map` pns)
60+runModuleName (P.ModuleName pns) = intercalate "_" ((T.unpack . P.runProperName) `map` pns)
60
61
61readInput :: [FilePath] -> IO (Either P.MultipleErrors [P.Module])
62readInput :: [FilePath] -> IO (Either P.MultipleErrors [P.Module])
62readInput paths = do
63readInput paths = do
psc-docs/Main.hs+5−4
@@ -8,6 +8,7 @@ import Control.Arrow (first, second)
8import Control.Category ((>>>))
8import Control.Category ((>>>))
9import Control.Monad.Writer
9import Control.Monad.Writer
10import Data.Text (Text)
10import Data.Text (Text)
11+import qualified Data.Text as T
11import Data.Function (on)
12import Data.Function (on)
12import Data.List
13import Data.List
13import Data.Maybe (fromMaybe)
14import Data.Maybe (fromMaybe)
@@ -82,12 +83,12 @@ docgen (PSCDocsOptions fmt inputGlob output) = do
82 where
83 where
83 guardMissing [] = return ()
84 guardMissing [] = return ()
84 guardMissing [mn] = do
85 guardMissing [mn] = do
85− hPutStrLn stderr ("psc-docs: error: unknown module \"" ++ P.runModuleName mn ++ "\"")
86+ hPutStrLn stderr ("psc-docs: error: unknown module \"" ++ T.unpack (P.runModuleName mn) ++ "\"")
86 exitFailure
87 exitFailure
87 guardMissing mns = do
88 guardMissing mns = do
88 hPutStrLn stderr "psc-docs: error: unknown modules:"
89 hPutStrLn stderr "psc-docs: error: unknown modules:"
89 forM_ mns $ \mn ->
90 forM_ mns $ \mn ->
90− hPutStrLn stderr (" * " ++ P.runModuleName mn)
91+ hPutStrLn stderr (" * " ++ T.unpack (P.runModuleName mn))
91 exitFailure
92 exitFailure
92
93
93 successOrExit :: Either P.MultipleErrors a -> IO a
94 successOrExit :: Either P.MultipleErrors a -> IO a
@@ -186,11 +187,11 @@ parseItem :: String -> DocgenOutputItem
186parseItem s = case elemIndex ':' s of
187parseItem s = case elemIndex ':' s of
187 Just i ->
188 Just i ->
188 s # splitAt i
189 s # splitAt i
189− >>> first P.moduleNameFromString
190+ >>> first (P.moduleNameFromString . T.pack)
190 >>> second (drop 1)
191 >>> second (drop 1)
191 >>> IToFile
192 >>> IToFile
192 Nothing ->
193 Nothing ->
193− IToStdOut (P.moduleNameFromString s)
194+ IToStdOut (P.moduleNameFromString (T.pack s))
194
195
195 where
196 where
196 infixr 1 #
197 infixr 1 #
psc-docs/Tags.hs+3−1
@@ -1,9 +1,11 @@
1module Tags where
1module Tags where
2
2
3+import Control.Arrow (first)
4+import qualified Data.Text as T
3import qualified Language.PureScript as P
5import qualified Language.PureScript as P
4
6
5tags :: P.Module -> [(String, Int)]
7tags :: P.Module -> [(String, Int)]
6−tags = concatMap dtags . P.exportedDeclarations
8+tags = map (first T.unpack) . concatMap dtags . P.exportedDeclarations
7 where dtags (P.PositionedDeclaration sp _ d) = map tag $ names d
9 where dtags (P.PositionedDeclaration sp _ d) = map tag $ names d
8 where tag name = (name, line)
10 where tag name = (name, line)
9 line = P.sourcePosLine $ P.spanStart sp
11 line = P.sourcePosLine $ P.spanStart sp
purescript.cabal+1
@@ -312,6 +312,7 @@ library
312 PatternSynonyms
312 PatternSynonyms
313 RankNTypes
313 RankNTypes
314 RecordWildCards
314 RecordWildCards
315+ OverloadedStrings
315 ScopedTypeVariables
316 ScopedTypeVariables
316 TupleSections
317 TupleSections
317 ViewPatterns
318 ViewPatterns
src/Control/Monad/Supply/Class.hs+3−2
@@ -12,6 +12,7 @@ import Prelude.Compat
12import Control.Monad.Supply
12import Control.Monad.Supply
13import Control.Monad.State
13import Control.Monad.State
14import Control.Monad.Writer
14import Control.Monad.Writer
15+import Data.Text (Text, pack)
15
16
16class Monad m => MonadSupply m where
17class Monad m => MonadSupply m where
17 fresh :: m Integer
18 fresh :: m Integer
@@ -31,5 +32,5 @@ instance Monad m => MonadSupply (SupplyT m) where
31instance MonadSupply m => MonadSupply (StateT s m)
32instance MonadSupply m => MonadSupply (StateT s m)
32instance (Monoid w, MonadSupply m) => MonadSupply (WriterT w m)
33instance (Monoid w, MonadSupply m) => MonadSupply (WriterT w m)
33
34
34−freshName :: MonadSupply m => m String
35+freshName :: MonadSupply m => m Text
35−freshName = fmap (('$' :) . show) fresh
36+freshName = fmap (("$" <> ) . pack . show) fresh
src/Language/PureScript/AST/Declarations.hs+17−16
@@ -11,6 +11,7 @@ import Control.Monad.Identity
11
11
12import Data.Aeson.TH
12import Data.Aeson.TH
13import qualified Data.Map as M
13import qualified Data.Map as M
14+import Data.Text (Text)
14
15
15import Language.PureScript.AST.Binders
16import Language.PureScript.AST.Binders
16import Language.PureScript.AST.Literals
17import Language.PureScript.AST.Literals
@@ -47,7 +48,7 @@ data SimpleErrorMessage
47 | UnnecessaryFFIModule ModuleName FilePath
48 | UnnecessaryFFIModule ModuleName FilePath
48 | MissingFFIImplementations ModuleName [Ident]
49 | MissingFFIImplementations ModuleName [Ident]
49 | UnusedFFIImplementations ModuleName [Ident]
50 | UnusedFFIImplementations ModuleName [Ident]
50− | InvalidFFIIdentifier ModuleName String
51+ | InvalidFFIIdentifier ModuleName Text
51 | CannotGetFileInfo FilePath
52 | CannotGetFileInfo FilePath
52 | CannotReadFile FilePath
53 | CannotReadFile FilePath
53 | CannotWriteFile FilePath
54 | CannotWriteFile FilePath
@@ -68,7 +69,7 @@ data SimpleErrorMessage
68 | DeclConflict Name Name
69 | DeclConflict Name Name
69 | ExportConflict (Qualified Name) (Qualified Name)
70 | ExportConflict (Qualified Name) (Qualified Name)
70 | DuplicateModule ModuleName [SourceSpan]
71 | DuplicateModule ModuleName [SourceSpan]
71− | DuplicateTypeArgument String
72+ | DuplicateTypeArgument Text
72 | InvalidDoBind
73 | InvalidDoBind
73 | InvalidDoLet
74 | InvalidDoLet
74 | CycleInDeclaration Ident
75 | CycleInDeclaration Ident
@@ -89,7 +90,7 @@ data SimpleErrorMessage
89 | CannotDerive (Qualified (ProperName 'ClassName)) [Type]
90 | CannotDerive (Qualified (ProperName 'ClassName)) [Type]
90 | InvalidNewtypeInstance (Qualified (ProperName 'ClassName)) [Type]
91 | InvalidNewtypeInstance (Qualified (ProperName 'ClassName)) [Type]
91 | CannotFindDerivingType (ProperName 'TypeName)
92 | CannotFindDerivingType (ProperName 'TypeName)
92− | DuplicateLabel String (Maybe Expr)
93+ | DuplicateLabel Text (Maybe Expr)
93 | DuplicateValueDeclaration Ident
94 | DuplicateValueDeclaration Ident
94 | ArgListLengthsDiffer Ident
95 | ArgListLengthsDiffer Ident
95 | OverlappingArgNames (Maybe Ident)
96 | OverlappingArgNames (Maybe Ident)
@@ -98,8 +99,8 @@ data SimpleErrorMessage
98 | ExpectedType Type Kind
99 | ExpectedType Type Kind
99 | IncorrectConstructorArity (Qualified (ProperName 'ConstructorName))
100 | IncorrectConstructorArity (Qualified (ProperName 'ConstructorName))
100 | ExprDoesNotHaveType Expr Type
101 | ExprDoesNotHaveType Expr Type
101− | PropertyIsMissing String
102+ | PropertyIsMissing Text
102− | AdditionalProperty String
103+ | AdditionalProperty Text
103 | TypeSynonymInstance
104 | TypeSynonymInstance
104 | OrphanInstance Ident (Qualified (ProperName 'ClassName)) [Type]
105 | OrphanInstance Ident (Qualified (ProperName 'ClassName)) [Type]
105 | InvalidNewtype (ProperName 'TypeName)
106 | InvalidNewtype (ProperName 'TypeName)
@@ -107,10 +108,10 @@ data SimpleErrorMessage
107 | TransitiveExportError DeclarationRef [DeclarationRef]
108 | TransitiveExportError DeclarationRef [DeclarationRef]
108 | TransitiveDctorExportError DeclarationRef (ProperName 'ConstructorName)
109 | TransitiveDctorExportError DeclarationRef (ProperName 'ConstructorName)
109 | ShadowedName Ident
110 | ShadowedName Ident
110− | ShadowedTypeVar String
111+ | ShadowedTypeVar Text
111− | UnusedTypeVar String
112+ | UnusedTypeVar Text
112 | WildcardInferredType Type Context
113 | WildcardInferredType Type Context
113− | HoleInferredType String Type Context TypeSearch
114+ | HoleInferredType Text Type Context TypeSearch
114 | MissingTypeDeclaration Ident Type
115 | MissingTypeDeclaration Ident Type
115 | OverlappingPattern [[Binder]] Bool
116 | OverlappingPattern [[Binder]] Bool
116 | IncompleteExhaustivityCheck
117 | IncompleteExhaustivityCheck
@@ -124,7 +125,7 @@ data SimpleErrorMessage
124 | DuplicateImport ModuleName ImportDeclarationType (Maybe ModuleName)
125 | DuplicateImport ModuleName ImportDeclarationType (Maybe ModuleName)
125 | DuplicateImportRef Name
126 | DuplicateImportRef Name
126 | DuplicateExportRef Name
127 | DuplicateExportRef Name
127− | IntOutOfRange Integer String Integer Integer
128+ | IntOutOfRange Integer Text Integer Integer
128 | ImplicitQualifiedImport ModuleName ModuleName [DeclarationRef]
129 | ImplicitQualifiedImport ModuleName ModuleName [DeclarationRef]
129 | ImplicitImport ModuleName [DeclarationRef]
130 | ImplicitImport ModuleName [DeclarationRef]
130 | HidingImport ModuleName [DeclarationRef]
131 | HidingImport ModuleName [DeclarationRef]
@@ -144,7 +145,7 @@ data ErrorMessageHint
144 | ErrorInModule ModuleName
145 | ErrorInModule ModuleName
145 | ErrorInInstance (Qualified (ProperName 'ClassName)) [Type]
146 | ErrorInInstance (Qualified (ProperName 'ClassName)) [Type]
146 | ErrorInSubsumption Type Type
147 | ErrorInSubsumption Type Type
147− | ErrorCheckingAccessor Expr String
148+ | ErrorCheckingAccessor Expr Text
148 | ErrorCheckingType Expr Type
149 | ErrorCheckingType Expr Type
149 | ErrorCheckingKind Type
150 | ErrorCheckingKind Type
150 | ErrorCheckingGuard
151 | ErrorCheckingGuard
@@ -350,7 +351,7 @@ data Declaration
350 -- |
351 -- |
351 -- A data type declaration (data or newtype, name, arguments, data constructors)
352 -- A data type declaration (data or newtype, name, arguments, data constructors)
352 --
353 --
353− = DataDeclaration DataDeclType (ProperName 'TypeName) [(String, Maybe Kind)] [(ProperName 'ConstructorName, [Type])]
354+ = DataDeclaration DataDeclType (ProperName 'TypeName) [(Text, Maybe Kind)] [(ProperName 'ConstructorName, [Type])]
354 -- |
355 -- |
355 -- A minimal mutually recursive set of data type declarations
356 -- A minimal mutually recursive set of data type declarations
356 --
357 --
@@ -358,7 +359,7 @@ data Declaration
358 -- |
359 -- |
359 -- A type synonym declaration (name, arguments, type)
360 -- A type synonym declaration (name, arguments, type)
360 --
361 --
361− | TypeSynonymDeclaration (ProperName 'TypeName) [(String, Maybe Kind)] Type
362+ | TypeSynonymDeclaration (ProperName 'TypeName) [(Text, Maybe Kind)] Type
362 -- |
363 -- |
363 -- A type declaration for a value (name, ty)
364 -- A type declaration for a value (name, ty)
364 --
365 --
@@ -390,7 +391,7 @@ data Declaration
390 -- |
391 -- |
391 -- A type class declaration (name, argument, implies, member declarations)
392 -- A type class declaration (name, argument, implies, member declarations)
392 --
393 --
393− | TypeClassDeclaration (ProperName 'ClassName) [(String, Maybe Kind)] [Constraint] [FunctionalDependency] [Declaration]
394+ | TypeClassDeclaration (ProperName 'ClassName) [(Text, Maybe Kind)] [Constraint] [FunctionalDependency] [Declaration]
394 -- |
395 -- |
395 -- A type instance declaration (name, dependencies, class name, instance types, member
396 -- A type instance declaration (name, dependencies, class name, instance types, member
396 -- declarations)
397 -- declarations)
@@ -548,11 +549,11 @@ data Expr
548 -- Anonymous arguments will be removed during desugaring and expanded
549 -- Anonymous arguments will be removed during desugaring and expanded
549 -- into a lambda that reads a property from a record.
550 -- into a lambda that reads a property from a record.
550 --
551 --
551− | Accessor String Expr
552+ | Accessor Text Expr
552 -- |
553 -- |
553 -- Partial record update
554 -- Partial record update
554 --
555 --
555− | ObjectUpdate Expr [(String, Expr)]
556+ | ObjectUpdate Expr [(Text, Expr)]
556 -- |
557 -- |
557 -- Function introduction
558 -- Function introduction
558 --
559 --
@@ -625,7 +626,7 @@ data Expr
625 -- |
626 -- |
626 -- A typed hole that will be turned into a hint/error duing typechecking
627 -- A typed hole that will be turned into a hint/error duing typechecking
627 --
628 --
628− | Hole String
629+ | Hole Text
629 -- |
630 -- |
630 -- A value with source position information
631 -- A value with source position information
631 --
632 --
src/Language/PureScript/AST/Literals.hs+3−2
@@ -4,6 +4,7 @@
4module Language.PureScript.AST.Literals where
4module Language.PureScript.AST.Literals where
5
5
6import Prelude.Compat
6import Prelude.Compat
7+import Data.Text (Text)
7
8
8-- |
9-- |
9-- Data type for literal values. Parameterised so it can be used for Exprs and
10-- Data type for literal values. Parameterised so it can be used for Exprs and
@@ -17,7 +18,7 @@ data Literal a
17 -- |
18 -- |
18 -- A string literal
19 -- A string literal
19 --
20 --
20− | StringLiteral String
21+ | StringLiteral Text
21 -- |
22 -- |
22 -- A character literal
23 -- A character literal
23 --
24 --
@@ -33,5 +34,5 @@ data Literal a
33 -- |
34 -- |
34 -- An object literal
35 -- An object literal
35 --
36 --
36− | ObjectLiteral [(String, a)]
37+ | ObjectLiteral [(Text, a)]
37 deriving (Eq, Ord, Show, Functor)
38 deriving (Eq, Ord, Show, Functor)
src/Language/PureScript/AST/SourcePos.hs+10−7
@@ -9,6 +9,9 @@ import Prelude.Compat
9
9
10import Data.Aeson ((.=), (.:))
10import Data.Aeson ((.=), (.:))
11import qualified Data.Aeson as A
11import qualified Data.Aeson as A
12+import Data.Monoid
13+import qualified Data.Text as T
14+import Data.Text (Text)
12
15
13-- |
16-- |
14-- Source position information
17-- Source position information
@@ -24,10 +27,10 @@ data SourcePos = SourcePos
24 , sourcePosColumn :: Int
27 , sourcePosColumn :: Int
25 } deriving (Show, Eq, Ord)
28 } deriving (Show, Eq, Ord)
26
29
27−displaySourcePos :: SourcePos -> String
30+displaySourcePos :: SourcePos -> Text
28displaySourcePos sp =
31displaySourcePos sp =
29− "line " ++ show (sourcePosLine sp) ++
32+ "line " <> T.pack (show (sourcePosLine sp)) <>
30− ", column " ++ show (sourcePosColumn sp)
33+ ", column " <> T.pack (show (sourcePosColumn sp))
31
34
32instance A.ToJSON SourcePos where
35instance A.ToJSON SourcePos where
33 toJSON SourcePos{..} =
36 toJSON SourcePos{..} =
@@ -52,14 +55,14 @@ data SourceSpan = SourceSpan
52 , spanEnd :: SourcePos
55 , spanEnd :: SourcePos
53 } deriving (Show, Eq, Ord)
56 } deriving (Show, Eq, Ord)
54
57
55−displayStartEndPos :: SourceSpan -> String
58+displayStartEndPos :: SourceSpan -> Text
56displayStartEndPos sp =
59displayStartEndPos sp =
57− displaySourcePos (spanStart sp) ++ " - " ++
60+ displaySourcePos (spanStart sp) <> " - " <>
58 displaySourcePos (spanEnd sp)
61 displaySourcePos (spanEnd sp)
59
62
60−displaySourceSpan :: SourceSpan -> String
63+displaySourceSpan :: SourceSpan -> Text
61displaySourceSpan sp =
64displaySourceSpan sp =
62− spanName sp ++ " " ++
65+ T.pack (spanName sp) <> " " <>
63 displayStartEndPos sp
66 displayStartEndPos sp
64
67
65instance A.ToJSON SourceSpan where
68instance A.ToJSON SourceSpan where
src/Language/PureScript/CodeGen/JS.hs+25−23
@@ -10,16 +10,18 @@ module Language.PureScript.CodeGen.JS
10import Prelude.Compat
10import Prelude.Compat
11
11
12import Control.Arrow ((&&&))
12import Control.Arrow ((&&&))
13−import Control.Monad (replicateM, forM, void)
13+import Control.Monad (forM, replicateM, void)
14−import Control.Monad.Error.Class (MonadError(..))
14+import Control.Monad.Except (MonadError, throwError)
15import Control.Monad.Reader (MonadReader, asks)
15import Control.Monad.Reader (MonadReader, asks)
16import Control.Monad.Supply.Class
16import Control.Monad.Supply.Class
17
17
18import Data.List ((\\), delete, intersect, nub)
18import Data.List ((\\), delete, intersect, nub)
19−import Data.Maybe (isNothing, fromMaybe)
20import qualified Data.Foldable as F
19import qualified Data.Foldable as F
21import qualified Data.Map as M
20import qualified Data.Map as M
21+import Data.Maybe (fromMaybe, isNothing)
22+import Data.Monoid ((<>))
23+import Data.Text (Text)
22−import qualified Data.Traversable as T
24+import qualified Data.Text as T
23
25
24import Language.PureScript.AST.SourcePos
26import Language.PureScript.AST.SourcePos
25import Language.PureScript.CodeGen.JS.AST as AST
27import Language.PureScript.CodeGen.JS.AST as AST
@@ -51,10 +53,10 @@ moduleToJs (Module coms mn imps exps foreigns decls) foreign_ =
51 rethrow (addHint (ErrorInModule mn)) $ do
53 rethrow (addHint (ErrorInModule mn)) $ do
52 let usedNames = concatMap getNames decls
54 let usedNames = concatMap getNames decls
53 let mnLookup = renameImports usedNames imps
55 let mnLookup = renameImports usedNames imps
54− jsImports <- T.traverse (importToJs mnLookup) . delete (ModuleName [ProperName C.prim]) . (\\ [mn]) $ nub $ map snd imps
56+ jsImports <- traverse (importToJs mnLookup) . delete (ModuleName [ProperName C.prim]) . (\\ [mn]) $ nub $ map snd imps
55 let decls' = renameModules mnLookup decls
57 let decls' = renameModules mnLookup decls
56 jsDecls <- mapM bindToJs decls'
58 jsDecls <- mapM bindToJs decls'
57− optimized <- T.traverse (T.traverse optimize) jsDecls
59+ optimized <- traverse (traverse optimize) jsDecls
58 F.traverse_ (F.traverse_ checkIntegers) optimized
60 F.traverse_ (F.traverse_ checkIntegers) optimized
59 comments <- not <$> asks optionsNoComments
61 comments <- not <$> asks optionsNoComments
60 let strict = JSStringLiteral Nothing "use strict"
62 let strict = JSStringLiteral Nothing "use strict"
@@ -94,7 +96,7 @@ moduleToJs (Module coms mn imps exps foreigns decls) foreign_ =
94
96
95 freshModuleName :: Integer -> ModuleName -> [Ident] -> ModuleName
97 freshModuleName :: Integer -> ModuleName -> [Ident] -> ModuleName
96 freshModuleName i mn'@(ModuleName pns) used =
98 freshModuleName i mn'@(ModuleName pns) used =
97− let newName = ModuleName $ init pns ++ [ProperName $ runProperName (last pns) ++ "_" ++ show i]
99+ let newName = ModuleName $ init pns ++ [ProperName $ runProperName (last pns) <> "_" <> T.pack (show i)]
98 in if Ident (runModuleName newName) `elem` used
100 in if Ident (runModuleName newName) `elem` used
99 then freshModuleName (i + 1) mn' used
101 then freshModuleName (i + 1) mn' used
100 else newName
102 else newName
@@ -106,7 +108,7 @@ moduleToJs (Module coms mn imps exps foreigns decls) foreign_ =
106 importToJs :: M.Map ModuleName (Ann, ModuleName) -> ModuleName -> m JS
108 importToJs :: M.Map ModuleName (Ann, ModuleName) -> ModuleName -> m JS
107 importToJs mnLookup mn' = do
109 importToJs mnLookup mn' = do
108 let ((ss, _, _, _), mnSafe) = fromMaybe (internalError "Missing value in mnLookup") $ M.lookup mn' mnLookup
110 let ((ss, _, _, _), mnSafe) = fromMaybe (internalError "Missing value in mnLookup") $ M.lookup mn' mnLookup
109− let moduleBody = JSApp Nothing (JSVar Nothing "require") [JSStringLiteral Nothing (".." </> runModuleName mn')]
111+ let moduleBody = JSApp Nothing (JSVar Nothing "require") [JSStringLiteral Nothing (T.pack (".." </> T.unpack (runModuleName mn')))]
110 withPos ss $ JSVariableIntroduction Nothing (moduleNameToJs mnSafe) (Just moduleBody)
112 withPos ss $ JSVariableIntroduction Nothing (moduleNameToJs mnSafe) (Just moduleBody)
111
113
112 -- |
114 -- |
@@ -177,7 +179,7 @@ moduleToJs (Module coms mn imps exps foreigns decls) foreign_ =
177 accessor (Ident prop) = accessorString prop
179 accessor (Ident prop) = accessorString prop
178 accessor (GenIdent _ _) = internalError "GenIdent in accessor"
180 accessor (GenIdent _ _) = internalError "GenIdent in accessor"
179
181
180− accessorString :: String -> JS -> JS
182+ accessorString :: Text -> JS -> JS
181 accessorString prop | identNeedsEscaping prop = JSIndexer Nothing (JSStringLiteral Nothing prop)
183 accessorString prop | identNeedsEscaping prop = JSIndexer Nothing (JSStringLiteral Nothing prop)
182 | otherwise = JSAccessor Nothing prop
184 | otherwise = JSAccessor Nothing prop
183
185
@@ -234,7 +236,7 @@ moduleToJs (Module coms mn imps exps foreigns decls) foreign_ =
234 then foreignIdent ident
236 then foreignIdent ident
235 else varToJs qi
237 else varToJs qi
236 valueToJs' (Var (_, _, _, Just IsForeign) ident) =
238 valueToJs' (Var (_, _, _, Just IsForeign) ident) =
237− error $ "Encountered an unqualified reference to a foreign ident " ++ showQualified showIdent ident
239+ internalError $ "Encountered an unqualified reference to a foreign ident " ++ T.unpack (showQualified showIdent ident)
238 valueToJs' (Var _ ident) = return $ varToJs ident
240 valueToJs' (Var _ ident) = return $ varToJs ident
239 valueToJs' (Case (maybeSpan, _, _, _) values binders) = do
241 valueToJs' (Case (maybeSpan, _, _, _) values binders) = do
240 vals <- mapM valueToJs values
242 vals <- mapM valueToJs values
@@ -263,14 +265,14 @@ moduleToJs (Module coms mn imps exps foreigns decls) foreign_ =
263 , JSAssignment Nothing (JSAccessor Nothing "create" (JSVar Nothing (properToJs ctor))) createFn
265 , JSAssignment Nothing (JSAccessor Nothing "create" (JSVar Nothing (properToJs ctor))) createFn
264 ]
266 ]
265
267
266− iife :: String -> [JS] -> JS
268+ iife :: Text -> [JS] -> JS
267 iife v exprs = JSApp Nothing (JSFunction Nothing Nothing [] (JSBlock Nothing $ exprs ++ [JSReturn Nothing $ JSVar Nothing v])) []
269 iife v exprs = JSApp Nothing (JSFunction Nothing Nothing [] (JSBlock Nothing $ exprs ++ [JSReturn Nothing $ JSVar Nothing v])) []
268
270
269 literalToValueJS :: Literal (Expr Ann) -> m JS
271 literalToValueJS :: Literal (Expr Ann) -> m JS
270 literalToValueJS (NumericLiteral (Left i)) = return $ JSNumericLiteral Nothing (Left i)
272 literalToValueJS (NumericLiteral (Left i)) = return $ JSNumericLiteral Nothing (Left i)
271 literalToValueJS (NumericLiteral (Right n)) = return $ JSNumericLiteral Nothing (Right n)
273 literalToValueJS (NumericLiteral (Right n)) = return $ JSNumericLiteral Nothing (Right n)
272 literalToValueJS (StringLiteral s) = return $ JSStringLiteral Nothing s
274 literalToValueJS (StringLiteral s) = return $ JSStringLiteral Nothing s
273− literalToValueJS (CharLiteral c) = return $ JSStringLiteral Nothing [c]
275+ literalToValueJS (CharLiteral c) = return $ JSStringLiteral Nothing (T.singleton c)
274 literalToValueJS (BooleanLiteral b) = return $ JSBooleanLiteral Nothing b
276 literalToValueJS (BooleanLiteral b) = return $ JSBooleanLiteral Nothing b
275 literalToValueJS (ArrayLiteral xs) = JSArrayLiteral Nothing <$> mapM valueToJs xs
277 literalToValueJS (ArrayLiteral xs) = JSArrayLiteral Nothing <$> mapM valueToJs xs
276 literalToValueJS (ObjectLiteral ps) = JSObjectLiteral Nothing <$> mapM (sndM valueToJs) ps
278 literalToValueJS (ObjectLiteral ps) = JSObjectLiteral Nothing <$> mapM (sndM valueToJs) ps
@@ -278,7 +280,7 @@ moduleToJs (Module coms mn imps exps foreigns decls) foreign_ =
278 -- |
280 -- |
279 -- Shallow copy an object.
281 -- Shallow copy an object.
280 --
282 --
281− extendObj :: JS -> [(String, JS)] -> m JS
283+ extendObj :: JS -> [(Text, JS)] -> m JS
282 extendObj obj sts = do
284 extendObj obj sts = do
283 newObj <- freshName
285 newObj <- freshName
284 key <- freshName
286 key <- freshName
@@ -331,20 +333,20 @@ moduleToJs (Module coms mn imps exps foreigns decls) foreign_ =
331 return $ JSApp Nothing (JSFunction Nothing Nothing [] (JSBlock Nothing (assignments ++ concat jss ++ [JSThrow Nothing $ failedPatternError valNames])))
333 return $ JSApp Nothing (JSFunction Nothing Nothing [] (JSBlock Nothing (assignments ++ concat jss ++ [JSThrow Nothing $ failedPatternError valNames])))
332 []
334 []
333 where
335 where
334− go :: [String] -> [JS] -> [Binder Ann] -> m [JS]
336+ go :: [Text] -> [JS] -> [Binder Ann] -> m [JS]
335 go _ done [] = return done
337 go _ done [] = return done
336 go (v:vs) done' (b:bs) = do
338 go (v:vs) done' (b:bs) = do
337 done'' <- go vs done' bs
339 done'' <- go vs done' bs
338 binderToJs v done'' b
340 binderToJs v done'' b
339 go _ _ _ = internalError "Invalid arguments to bindersToJs"
341 go _ _ _ = internalError "Invalid arguments to bindersToJs"
340
342
341− failedPatternError :: [String] -> JS
343+ failedPatternError :: [Text] -> JS
342 failedPatternError names = JSUnary Nothing JSNew $ JSApp Nothing (JSVar Nothing "Error") [JSBinary Nothing Add (JSStringLiteral Nothing failedPatternMessage) (JSArrayLiteral Nothing $ zipWith valueError names vals)]
344 failedPatternError names = JSUnary Nothing JSNew $ JSApp Nothing (JSVar Nothing "Error") [JSBinary Nothing Add (JSStringLiteral Nothing failedPatternMessage) (JSArrayLiteral Nothing $ zipWith valueError names vals)]
343
345
344− failedPatternMessage :: String
346+ failedPatternMessage :: Text
345− failedPatternMessage = "Failed pattern match" ++ maybe "" (((" at " ++ runModuleName mn ++ " ") ++) . displayStartEndPos) maybeSpan ++ ": "
347+ failedPatternMessage = "Failed pattern match" <> maybe "" (((" at " <> runModuleName mn <> " ") <>) . displayStartEndPos) maybeSpan <> ": "
346
348
347− valueError :: String -> JS -> JS
349+ valueError :: Text -> JS -> JS
348 valueError _ l@(JSNumericLiteral _ _) = l
350 valueError _ l@(JSNumericLiteral _ _) = l
349 valueError _ l@(JSStringLiteral _ _) = l
351 valueError _ l@(JSStringLiteral _ _) = l
350 valueError _ l@(JSBooleanLiteral _ _) = l
352 valueError _ l@(JSBooleanLiteral _ _) = l
@@ -357,7 +359,7 @@ moduleToJs (Module coms mn imps exps foreigns decls) foreign_ =
357 return $ JSIfElse Nothing cond' (JSBlock Nothing [JSReturn Nothing done]) Nothing
359 return $ JSIfElse Nothing cond' (JSBlock Nothing [JSReturn Nothing done]) Nothing
358 guardsToJs (Right v) = return . JSReturn Nothing <$> valueToJs v
360 guardsToJs (Right v) = return . JSReturn Nothing <$> valueToJs v
359
361
360− binderToJs :: String -> [JS] -> Binder Ann -> m [JS]
362+ binderToJs :: Text -> [JS] -> Binder Ann -> m [JS]
361 binderToJs s done binder =
363 binderToJs s done binder =
362 let (ss, _, _, _) = extractBinderAnn binder in
364 let (ss, _, _, _) = extractBinderAnn binder in
363 traverse (withPos ss) =<< binderToJs' s done binder
365 traverse (withPos ss) =<< binderToJs' s done binder
@@ -366,7 +368,7 @@ moduleToJs (Module coms mn imps exps foreigns decls) foreign_ =
366 -- Generate code in the simplified Javascript intermediate representation for a pattern match
368 -- Generate code in the simplified Javascript intermediate representation for a pattern match
367 -- binder.
369 -- binder.
368 --
370 --
369− binderToJs' :: String -> [JS] -> Binder Ann -> m [JS]
371+ binderToJs' :: Text -> [JS] -> Binder Ann -> m [JS]
370 binderToJs' _ done NullBinder{} = return done
372 binderToJs' _ done NullBinder{} = return done
371 binderToJs' varName done (LiteralBinder _ l) =
373 binderToJs' varName done (LiteralBinder _ l) =
372 literalToBinderJS varName done l
374 literalToBinderJS varName done l
@@ -396,11 +398,11 @@ moduleToJs (Module coms mn imps exps foreigns decls) foreign_ =
396 js <- binderToJs varName done binder
398 js <- binderToJs varName done binder
397 return (JSVariableIntroduction Nothing (identToJs ident) (Just (JSVar Nothing varName)) : js)
399 return (JSVariableIntroduction Nothing (identToJs ident) (Just (JSVar Nothing varName)) : js)
398
400
399− literalToBinderJS :: String -> [JS] -> Literal (Binder Ann) -> m [JS]
401+ literalToBinderJS :: Text -> [JS] -> Literal (Binder Ann) -> m [JS]
400 literalToBinderJS varName done (NumericLiteral num) =
402 literalToBinderJS varName done (NumericLiteral num) =
401 return [JSIfElse Nothing (JSBinary Nothing EqualTo (JSVar Nothing varName) (JSNumericLiteral Nothing num)) (JSBlock Nothing done) Nothing]
403 return [JSIfElse Nothing (JSBinary Nothing EqualTo (JSVar Nothing varName) (JSNumericLiteral Nothing num)) (JSBlock Nothing done) Nothing]
402 literalToBinderJS varName done (CharLiteral c) =
404 literalToBinderJS varName done (CharLiteral c) =
403− return [JSIfElse Nothing (JSBinary Nothing EqualTo (JSVar Nothing varName) (JSStringLiteral Nothing [c])) (JSBlock Nothing done) Nothing]
405+ return [JSIfElse Nothing (JSBinary Nothing EqualTo (JSVar Nothing varName) (JSStringLiteral Nothing (T.singleton c))) (JSBlock Nothing done) Nothing]
404 literalToBinderJS varName done (StringLiteral str) =
406 literalToBinderJS varName done (StringLiteral str) =
405 return [JSIfElse Nothing (JSBinary Nothing EqualTo (JSVar Nothing varName) (JSStringLiteral Nothing str)) (JSBlock Nothing done) Nothing]
407 return [JSIfElse Nothing (JSBinary Nothing EqualTo (JSVar Nothing varName) (JSStringLiteral Nothing str)) (JSBlock Nothing done) Nothing]
406 literalToBinderJS varName done (BooleanLiteral True) =
408 literalToBinderJS varName done (BooleanLiteral True) =
@@ -409,7 +411,7 @@ moduleToJs (Module coms mn imps exps foreigns decls) foreign_ =
409 return [JSIfElse Nothing (JSUnary Nothing Not (JSVar Nothing varName)) (JSBlock Nothing done) Nothing]
411 return [JSIfElse Nothing (JSUnary Nothing Not (JSVar Nothing varName)) (JSBlock Nothing done) Nothing]
410 literalToBinderJS varName done (ObjectLiteral bs) = go done bs
412 literalToBinderJS varName done (ObjectLiteral bs) = go done bs
411 where
413 where
412− go :: [JS] -> [(String, Binder Ann)] -> m [JS]
414+ go :: [JS] -> [(Text, Binder Ann)] -> m [JS]
413 go done' [] = return done'
415 go done' [] = return done'
414 go done' ((prop, binder):bs') = do
416 go done' ((prop, binder):bs') = do
415 propVar <- freshName
417 propVar <- freshName
src/Language/PureScript/CodeGen/JS/AST.hs+15−13
@@ -5,7 +5,9 @@ module Language.PureScript.CodeGen.JS.AST where
5
5
6import Prelude.Compat
6import Prelude.Compat
7
7
8−import Control.Monad.Identity
8+import Control.Monad ((>=>))
9+import Control.Monad.Identity (Identity(..), runIdentity)
10+import Data.Text (Text)
9
11
10import Language.PureScript.AST (SourceSpan(..))
12import Language.PureScript.AST (SourceSpan(..))
11import Language.PureScript.Comments
13import Language.PureScript.Comments
@@ -130,7 +132,7 @@ data JS
130 -- |
132 -- |
131 -- A string literal
133 -- A string literal
132 --
134 --
133− | JSStringLiteral (Maybe SourceSpan) String
135+ | JSStringLiteral (Maybe SourceSpan) Text
134 -- |
136 -- |
135 -- A boolean literal
137 -- A boolean literal
136 --
138 --
@@ -154,15 +156,15 @@ data JS
154 -- |
156 -- |
155 -- An object literal
157 -- An object literal
156 --
158 --
157− | JSObjectLiteral (Maybe SourceSpan) [(String, JS)]
159+ | JSObjectLiteral (Maybe SourceSpan) [(Text, JS)]
158 -- |
160 -- |
159 -- An object property accessor expression
161 -- An object property accessor expression
160 --
162 --
161− | JSAccessor (Maybe SourceSpan) String JS
163+ | JSAccessor (Maybe SourceSpan) Text JS
162 -- |
164 -- |
163 -- A function introduction (optional name, arguments, body)
165 -- A function introduction (optional name, arguments, body)
164 --
166 --
165− | JSFunction (Maybe SourceSpan) (Maybe String) [String] JS
167+ | JSFunction (Maybe SourceSpan) (Maybe Text) [Text] JS
166 -- |
168 -- |
167 -- Function application
169 -- Function application
168 --
170 --
@@ -170,7 +172,7 @@ data JS
170 -- |
172 -- |
171 -- Variable
173 -- Variable
172 --
174 --
173− | JSVar (Maybe SourceSpan) String
175+ | JSVar (Maybe SourceSpan) Text
174 -- |
176 -- |
175 -- Conditional expression
177 -- Conditional expression
176 --
178 --
@@ -182,7 +184,7 @@ data JS
182 -- |
184 -- |
183 -- A variable introduction and optional initialization
185 -- A variable introduction and optional initialization
184 --
186 --
185− | JSVariableIntroduction (Maybe SourceSpan) String (Maybe JS)
187+ | JSVariableIntroduction (Maybe SourceSpan) Text (Maybe JS)
186 -- |
188 -- |
187 -- A variable assignment
189 -- A variable assignment
188 --
190 --
@@ -194,11 +196,11 @@ data JS
194 -- |
196 -- |
195 -- For loop
197 -- For loop
196 --
198 --
197− | JSFor (Maybe SourceSpan) String JS JS JS
199+ | JSFor (Maybe SourceSpan) Text JS JS JS
198 -- |
200 -- |
199 -- ForIn loop
201 -- ForIn loop
200 --
202 --
201− | JSForIn (Maybe SourceSpan) String JS JS
203+ | JSForIn (Maybe SourceSpan) Text JS JS
202 -- |
204 -- |
203 -- If-then-else statement
205 -- If-then-else statement
204 --
206 --
@@ -222,19 +224,19 @@ data JS
222 -- |
224 -- |
223 -- Labelled statement
225 -- Labelled statement
224 --
226 --
225− | JSLabel (Maybe SourceSpan) String JS
227+ | JSLabel (Maybe SourceSpan) Text JS
226 -- |
228 -- |
227 -- Break statement
229 -- Break statement
228 --
230 --
229− | JSBreak (Maybe SourceSpan) String
231+ | JSBreak (Maybe SourceSpan) Text
230 -- |
232 -- |
231 -- Continue statement
233 -- Continue statement
232 --
234 --
233− | JSContinue (Maybe SourceSpan) String
235+ | JSContinue (Maybe SourceSpan) Text
234 -- |
236 -- |
235 -- Raw Javascript (generated when parsing fails for an inline foreign import declaration)
237 -- Raw Javascript (generated when parsing fails for an inline foreign import declaration)
236 --
238 --
237− | JSRaw (Maybe SourceSpan) String
239+ | JSRaw (Maybe SourceSpan) Text
238 -- |
240 -- |
239 -- Commented Javascript
241 -- Commented Javascript
240 --
242 --
src/Language/PureScript/CodeGen/JS/Common.hs+46−44
@@ -6,15 +6,17 @@ module Language.PureScript.CodeGen.JS.Common where
6import Prelude.Compat
6import Prelude.Compat
7
7
8import Data.Char
8import Data.Char
9−import Data.List (intercalate)
9+import Data.Monoid ((<>))
10+import Data.Text (Text)
11+import qualified Data.Text as T
10
12
11import Language.PureScript.Crash
13import Language.PureScript.Crash
12import Language.PureScript.Names
14import Language.PureScript.Names
13
15
14−moduleNameToJs :: ModuleName -> String
16+moduleNameToJs :: ModuleName -> Text
15moduleNameToJs (ModuleName pns) =
17moduleNameToJs (ModuleName pns) =
16− let name = intercalate "_" (runProperName `map` pns)
18+ let name = T.intercalate "_" (runProperName `map` pns)
17− in if nameIsJsBuiltIn name then "$$" ++ name else name
19+ in if nameIsJsBuiltIn name then "$$" <> name else name
18
20
19-- |
21-- |
20-- Convert an Ident into a valid Javascript identifier:
22-- Convert an Ident into a valid Javascript identifier:
@@ -25,62 +27,62 @@ moduleNameToJs (ModuleName pns) =
25--
27--
26-- * Symbols are prefixed with '$' followed by a symbol name or their ordinal value.
28-- * Symbols are prefixed with '$' followed by a symbol name or their ordinal value.
27--
29--
28−identToJs :: Ident -> String
30+identToJs :: Ident -> Text
29identToJs (Ident name) = properToJs name
31identToJs (Ident name) = properToJs name
30identToJs (GenIdent _ _) = internalError "GenIdent in identToJs"
32identToJs (GenIdent _ _) = internalError "GenIdent in identToJs"
31
33
32−properToJs :: String -> String
34+properToJs :: Text -> Text
33properToJs name
35properToJs name
34− | nameIsJsReserved name || nameIsJsBuiltIn name = "$$" ++ name
36+ | nameIsJsReserved name || nameIsJsBuiltIn name = "$$" <> name
35− | otherwise = concatMap identCharToString name
37+ | otherwise = T.concatMap identCharToText name
36
38
37-- |
39-- |
38-- Test if a string is a valid JS identifier without escaping.
40-- Test if a string is a valid JS identifier without escaping.
39--
41--
40−identNeedsEscaping :: String -> Bool
42+identNeedsEscaping :: Text -> Bool
41−identNeedsEscaping s = s /= identToJs (Ident s) || null s
43+identNeedsEscaping s = s /= identToJs (Ident s) || T.null s
42
44
43-- |
45-- |
44-- Attempts to find a human-readable name for a symbol, if none has been specified returns the
46-- Attempts to find a human-readable name for a symbol, if none has been specified returns the
45-- ordinal value.
47-- ordinal value.
46--
48--
47−identCharToString :: Char -> String
49+identCharToText :: Char -> Text
48−identCharToString c | isAlphaNum c = [c]
50+identCharToText c | isAlphaNum c = T.singleton c
49−identCharToString '_' = "_"
51+identCharToText '_' = "_"
50−identCharToString '.' = "$dot"
52+identCharToText '.' = "$dot"
51−identCharToString '$' = "$dollar"
53+identCharToText '$' = "$dollar"
52−identCharToString '~' = "$tilde"
54+identCharToText '~' = "$tilde"
53−identCharToString '=' = "$eq"
55+identCharToText '=' = "$eq"
54−identCharToString '<' = "$less"
56+identCharToText '<' = "$less"
55−identCharToString '>' = "$greater"
57+identCharToText '>' = "$greater"
56−identCharToString '!' = "$bang"
58+identCharToText '!' = "$bang"
57−identCharToString '#' = "$hash"
59+identCharToText '#' = "$hash"
58−identCharToString '%' = "$percent"
60+identCharToText '%' = "$percent"
59−identCharToString '^' = "$up"
61+identCharToText '^' = "$up"
60−identCharToString '&' = "$amp"
62+identCharToText '&' = "$amp"
61−identCharToString '|' = "$bar"
63+identCharToText '|' = "$bar"
62−identCharToString '*' = "$times"
64+identCharToText '*' = "$times"
63−identCharToString '/' = "$div"
65+identCharToText '/' = "$div"
64−identCharToString '+' = "$plus"
66+identCharToText '+' = "$plus"
65−identCharToString '-' = "$minus"
67+identCharToText '-' = "$minus"
66−identCharToString ':' = "$colon"
68+identCharToText ':' = "$colon"
67−identCharToString '\\' = "$bslash"
69+identCharToText '\\' = "$bslash"
68−identCharToString '?' = "$qmark"
70+identCharToText '?' = "$qmark"
69−identCharToString '@' = "$at"
71+identCharToText '@' = "$at"
70−identCharToString '\'' = "$prime"
72+identCharToText '\'' = "$prime"
71−identCharToString c = '$' : show (ord c)
73+identCharToText c = '$' `T.cons` T.pack (show (ord c))
72
74
73-- |
75-- |
74-- Checks whether an identifier name is reserved in Javascript.
76-- Checks whether an identifier name is reserved in Javascript.
75--
77--
76−nameIsJsReserved :: String -> Bool
78+nameIsJsReserved :: Text -> Bool
77nameIsJsReserved name =
79nameIsJsReserved name =
78 name `elem` jsAnyReserved
80 name `elem` jsAnyReserved
79
81
80-- |
82-- |
81-- Checks whether a name matches a built-in value in Javascript.
83-- Checks whether a name matches a built-in value in Javascript.
82--
84--
83−nameIsJsBuiltIn :: String -> Bool
85+nameIsJsBuiltIn :: Text -> Bool
84nameIsJsBuiltIn name =
86nameIsJsBuiltIn name =
85 name `elem`
87 name `elem`
86 [ "arguments"
88 [ "arguments"
@@ -138,7 +140,7 @@ nameIsJsBuiltIn name =
138 , "WeakSet"
140 , "WeakSet"
139 ]
141 ]
140
142
141−jsAnyReserved :: [String]
143+jsAnyReserved :: [Text]
142jsAnyReserved =
144jsAnyReserved =
143 concat
145 concat
144 [ jsKeywords
146 [ jsKeywords
@@ -149,7 +151,7 @@ jsAnyReserved =
149 , jsLiterals
151 , jsLiterals
150 ]
152 ]
151
153
152−jsKeywords :: [String]
154+jsKeywords :: [Text]
153jsKeywords =
155jsKeywords =
154 [ "break"
156 [ "break"
155 , "case"
157 , "case"
@@ -185,7 +187,7 @@ jsKeywords =
185 , "with"
187 , "with"
186 ]
188 ]
187
189
188−jsSometimesReserved :: [String]
190+jsSometimesReserved :: [Text]
189jsSometimesReserved =
191jsSometimesReserved =
190 [ "await"
192 [ "await"
191 , "let"
193 , "let"
@@ -193,11 +195,11 @@ jsSometimesReserved =
193 , "yield"
195 , "yield"
194 ]
196 ]
195
197
196−jsFutureReserved :: [String]
198+jsFutureReserved :: [Text]
197jsFutureReserved =
199jsFutureReserved =
198 [ "enum" ]
200 [ "enum" ]
199
201
200−jsFutureReservedStrict :: [String]
202+jsFutureReservedStrict :: [Text]
201jsFutureReservedStrict =
203jsFutureReservedStrict =
202 [ "implements"
204 [ "implements"
203 , "interface"
205 , "interface"
@@ -207,7 +209,7 @@ jsFutureReservedStrict =
207 , "public"
209 , "public"
208 ]
210 ]
209
211
210−jsOldReserved :: [String]
212+jsOldReserved :: [Text]
211jsOldReserved =
213jsOldReserved =
212 [ "abstract"
214 [ "abstract"
213 , "boolean"
215 , "boolean"
@@ -227,7 +229,7 @@ jsOldReserved =
227 , "volatile"
229 , "volatile"
228 ]
230 ]
229
231
230−jsLiterals :: [String]
232+jsLiterals :: [Text]
231jsLiterals =
233jsLiterals =
232 [ "null"
234 [ "null"
233 , "true"
235 , "true"
src/Language/PureScript/CodeGen/JS/Optimizer/Common.hs+12−10
@@ -5,27 +5,29 @@ module Language.PureScript.CodeGen.JS.Optimizer.Common where
5
5
6import Prelude.Compat
6import Prelude.Compat
7
7
8+import Data.Text (Text)
9+import Data.List (foldl')
8import Data.Maybe (fromMaybe)
10import Data.Maybe (fromMaybe)
9
11
10import Language.PureScript.Crash
12import Language.PureScript.Crash
11import Language.PureScript.CodeGen.JS.AST
13import Language.PureScript.CodeGen.JS.AST
12
14
13applyAll :: [a -> a] -> a -> a
15applyAll :: [a -> a] -> a -> a
14−applyAll = foldl1 (.)
16+applyAll = foldl' (.) id
15
17
16−replaceIdent :: String -> JS -> JS -> JS
18+replaceIdent :: Text -> JS -> JS -> JS
17replaceIdent var1 js = everywhereOnJS replace
19replaceIdent var1 js = everywhereOnJS replace
18 where
20 where
19 replace (JSVar _ var2) | var1 == var2 = js
21 replace (JSVar _ var2) | var1 == var2 = js
20 replace other = other
22 replace other = other
21
23
22−replaceIdents :: [(String, JS)] -> JS -> JS
24+replaceIdents :: [(Text, JS)] -> JS -> JS
23replaceIdents vars = everywhereOnJS replace
25replaceIdents vars = everywhereOnJS replace
24 where
26 where
25 replace v@(JSVar _ var) = fromMaybe v $ lookup var vars
27 replace v@(JSVar _ var) = fromMaybe v $ lookup var vars
26 replace other = other
28 replace other = other
27
29
28−isReassigned :: String -> JS -> Bool
30+isReassigned :: Text -> JS -> Bool
29isReassigned var1 = everythingOnJS (||) check
31isReassigned var1 = everythingOnJS (||) check
30 where
32 where
31 check :: JS -> Bool
33 check :: JS -> Bool
@@ -42,7 +44,7 @@ isRebound js d = any (\v -> isReassigned v d || isUpdated v d) (everythingOnJS (
42 variablesOf (JSVar _ var) = [var]
44 variablesOf (JSVar _ var) = [var]
43 variablesOf _ = []
45 variablesOf _ = []
44
46
45−isUsed :: String -> JS -> Bool
47+isUsed :: Text -> JS -> Bool
46isUsed var1 = everythingOnJS (||) check
48isUsed var1 = everythingOnJS (||) check
47 where
49 where
48 check :: JS -> Bool
50 check :: JS -> Bool
@@ -50,13 +52,13 @@ isUsed var1 = everythingOnJS (||) check
50 check (JSAssignment _ target _) | var1 == targetVariable target = True
52 check (JSAssignment _ target _) | var1 == targetVariable target = True
51 check _ = False
53 check _ = False
52
54
53−targetVariable :: JS -> String
55+targetVariable :: JS -> Text
54targetVariable (JSVar _ var) = var
56targetVariable (JSVar _ var) = var
55targetVariable (JSAccessor _ _ tgt) = targetVariable tgt
57targetVariable (JSAccessor _ _ tgt) = targetVariable tgt
56targetVariable (JSIndexer _ _ tgt) = targetVariable tgt
58targetVariable (JSIndexer _ _ tgt) = targetVariable tgt
57targetVariable _ = internalError "Invalid argument to targetVariable"
59targetVariable _ = internalError "Invalid argument to targetVariable"
58
60
59−isUpdated :: String -> JS -> Bool
61+isUpdated :: Text -> JS -> Bool
60isUpdated var1 = everythingOnJS (||) check
62isUpdated var1 = everythingOnJS (||) check
61 where
63 where
62 check :: JS -> Bool
64 check :: JS -> Bool
@@ -67,16 +69,16 @@ removeFromBlock :: ([JS] -> [JS]) -> JS -> JS
67removeFromBlock go (JSBlock ss sts) = JSBlock ss (go sts)
69removeFromBlock go (JSBlock ss sts) = JSBlock ss (go sts)
68removeFromBlock _ js = js
70removeFromBlock _ js = js
69
71
70−isFn :: (String, String) -> JS -> Bool
72+isFn :: (Text, Text) -> JS -> Bool
71isFn (moduleName, fnName) (JSAccessor _ x (JSVar _ y)) =
73isFn (moduleName, fnName) (JSAccessor _ x (JSVar _ y)) =
72 x == fnName && y == moduleName
74 x == fnName && y == moduleName
73isFn (moduleName, fnName) (JSIndexer _ (JSStringLiteral _ x) (JSVar _ y)) =
75isFn (moduleName, fnName) (JSIndexer _ (JSStringLiteral _ x) (JSVar _ y)) =
74 x == fnName && y == moduleName
76 x == fnName && y == moduleName
75isFn _ _ = False
77isFn _ _ = False
76
78
77−isDict :: (String, String) -> JS -> Bool
79+isDict :: (Text, Text) -> JS -> Bool
78isDict (moduleName, dictName) (JSAccessor _ x (JSVar _ y)) = x == dictName && y == moduleName
80isDict (moduleName, dictName) (JSAccessor _ x (JSVar _ y)) = x == dictName && y == moduleName
79isDict _ _ = False
81isDict _ _ = False
80
82
81−isDict' :: [(String, String)] -> JS -> Bool
83+isDict' :: [(Text, Text)] -> JS -> Bool
82isDict' xs js = any (`isDict` js) xs
84isDict' xs js = any (`isDict` js) xs
src/Language/PureScript/CodeGen/JS/Optimizer/Inliner.hs+51−48
@@ -16,6 +16,9 @@ import Prelude.Compat
16import Control.Monad.Supply.Class (MonadSupply, freshName)
16import Control.Monad.Supply.Class (MonadSupply, freshName)
17
17
18import Data.Maybe (fromMaybe)
18import Data.Maybe (fromMaybe)
19+import Data.Monoid ((<>))
20+import Data.Text (Text)
21+import qualified Data.Text as T
19
22
20import Language.PureScript.CodeGen.JS.AST
23import Language.PureScript.CodeGen.JS.AST
21import Language.PureScript.CodeGen.JS.Optimizer.Common
24import Language.PureScript.CodeGen.JS.Optimizer.Common
@@ -164,25 +167,25 @@ inlineCommonOperators = applyAll $
164 ] ++
167 ] ++
165 [ fn | i <- [0..10], fn <- [ mkFn i, runFn i ] ]
168 [ fn | i <- [0..10], fn <- [ mkFn i, runFn i ] ]
166 where
169 where
167− binary :: (String, String) -> (String, String) -> BinaryOperator -> JS -> JS
170+ binary :: (Text, Text) -> (Text, Text) -> BinaryOperator -> JS -> JS
168 binary dict fns op = everywhereOnJS convert
171 binary dict fns op = everywhereOnJS convert
169 where
172 where
170 convert :: JS -> JS
173 convert :: JS -> JS
171 convert (JSApp ss (JSApp _ (JSApp _ fn [dict']) [x]) [y]) | isDict dict dict' && isFn fns fn = JSBinary ss op x y
174 convert (JSApp ss (JSApp _ (JSApp _ fn [dict']) [x]) [y]) | isDict dict dict' && isFn fns fn = JSBinary ss op x y
172 convert other = other
175 convert other = other
173− binary' :: String -> String -> BinaryOperator -> JS -> JS
176+ binary' :: Text -> Text -> BinaryOperator -> JS -> JS
174 binary' moduleName opString op = everywhereOnJS convert
177 binary' moduleName opString op = everywhereOnJS convert
175 where
178 where
176 convert :: JS -> JS
179 convert :: JS -> JS
177 convert (JSApp ss (JSApp _ fn [x]) [y]) | isFn (moduleName, opString) fn = JSBinary ss op x y
180 convert (JSApp ss (JSApp _ fn [x]) [y]) | isFn (moduleName, opString) fn = JSBinary ss op x y
178 convert other = other
181 convert other = other
179− unary :: (String, String) -> (String, String) -> UnaryOperator -> JS -> JS
182+ unary :: (Text, Text) -> (Text, Text) -> UnaryOperator -> JS -> JS
180 unary dicts fns op = everywhereOnJS convert
183 unary dicts fns op = everywhereOnJS convert
181 where
184 where
182 convert :: JS -> JS
185 convert :: JS -> JS
183 convert (JSApp ss (JSApp _ fn [dict']) [x]) | isDict dicts dict' && isFn fns fn = JSUnary ss op x
186 convert (JSApp ss (JSApp _ fn [dict']) [x]) | isDict dicts dict' && isFn fns fn = JSUnary ss op x
184 convert other = other
187 convert other = other
185− unary' :: String -> String -> UnaryOperator -> JS -> JS
188+ unary' :: Text -> Text -> UnaryOperator -> JS -> JS
186 unary' moduleName fnName op = everywhereOnJS convert
189 unary' moduleName fnName op = everywhereOnJS convert
187 where
190 where
188 convert :: JS -> JS
191 convert :: JS -> JS
@@ -203,14 +206,14 @@ inlineCommonOperators = applyAll $
203 Just (args, js) -> JSFunction ss Nothing args (JSBlock ss js)
206 Just (args, js) -> JSFunction ss Nothing args (JSBlock ss js)
204 Nothing -> orig
207 Nothing -> orig
205 convert other = other
208 convert other = other
206− collectArgs :: Int -> [String] -> JS -> Maybe ([String], [JS])
209+ collectArgs :: Int -> [Text] -> JS -> Maybe ([Text], [JS])
207 collectArgs 1 acc (JSFunction _ Nothing [oneArg] (JSBlock _ js)) | length acc == n - 1 = Just (reverse (oneArg : acc), js)
210 collectArgs 1 acc (JSFunction _ Nothing [oneArg] (JSBlock _ js)) | length acc == n - 1 = Just (reverse (oneArg : acc), js)
208 collectArgs m acc (JSFunction _ Nothing [oneArg] (JSBlock _ [JSReturn _ ret])) = collectArgs (m - 1) (oneArg : acc) ret
211 collectArgs m acc (JSFunction _ Nothing [oneArg] (JSBlock _ [JSReturn _ ret])) = collectArgs (m - 1) (oneArg : acc) ret
209 collectArgs _ _ _ = Nothing
212 collectArgs _ _ _ = Nothing
210
213
211− isNFn :: String -> Int -> JS -> Bool
214+ isNFn :: Text -> Int -> JS -> Bool
212− isNFn prefix n (JSVar _ name) = name == (prefix ++ show n)
215+ isNFn prefix n (JSVar _ name) = name == (prefix <> T.pack (show n))
213− isNFn prefix n (JSAccessor _ name (JSVar _ dataFunctionUncurried)) | dataFunctionUncurried == C.dataFunctionUncurried = name == (prefix ++ show n)
216+ isNFn prefix n (JSAccessor _ name (JSVar _ dataFunctionUncurried)) | dataFunctionUncurried == C.dataFunctionUncurried = name == (prefix <> T.pack (show n))
214 isNFn _ _ _ = False
217 isNFn _ _ _ = False
215
218
216 runFn :: Int -> JS -> JS
219 runFn :: Int -> JS -> JS
@@ -231,11 +234,11 @@ inlineCommonOperators = applyAll $
231 convert (JSApp _ (JSApp _ op' [x]) [y]) | p op' = f x y
234 convert (JSApp _ (JSApp _ op' [x]) [y]) | p op' = f x y
232 convert other = other
235 convert other = other
233
236
234− isModFn :: (String, String) -> JS -> Bool
237+ isModFn :: (Text, Text) -> JS -> Bool
235 isModFn (m, op) (JSAccessor _ op' (JSVar _ m')) = m == m' && op == op'
238 isModFn (m, op) (JSAccessor _ op' (JSVar _ m')) = m == m' && op == op'
236 isModFn _ _ = False
239 isModFn _ _ = False
237
240
238− isModFnWithDict :: (String, String) -> JS -> Bool
241+ isModFnWithDict :: (Text, Text) -> JS -> Bool
239 isModFnWithDict (m, op) (JSApp _ (JSAccessor _ op' (JSVar _ m')) [(JSVar _ _)]) = m == m' && op == op'
242 isModFnWithDict (m, op) (JSApp _ (JSAccessor _ op' (JSVar _ m')) [(JSVar _ _)]) = m == m' && op == op'
240 isModFnWithDict _ _ = False
243 isModFnWithDict _ _ = False
241
244
@@ -260,115 +263,115 @@ inlineFnComposition = everywhereOnJSTopDownM convert
260 isFnCompose dict' fn = isDict semigroupoidFn dict' && isFn fnCompose fn
263 isFnCompose dict' fn = isDict semigroupoidFn dict' && isFn fnCompose fn
261 isFnComposeFlipped :: JS -> JS -> Bool
264 isFnComposeFlipped :: JS -> JS -> Bool
262 isFnComposeFlipped dict' fn = isDict semigroupoidFn dict' && isFn fnComposeFlipped fn
265 isFnComposeFlipped dict' fn = isDict semigroupoidFn dict' && isFn fnComposeFlipped fn
263− fnCompose :: (String, String)
266+ fnCompose :: (Text, Text)
264 fnCompose = (C.controlSemigroupoid, C.compose)
267 fnCompose = (C.controlSemigroupoid, C.compose)
265− fnComposeFlipped :: (String, String)
268+ fnComposeFlipped :: (Text, Text)
266 fnComposeFlipped = (C.controlSemigroupoid, C.composeFlipped)
269 fnComposeFlipped = (C.controlSemigroupoid, C.composeFlipped)
267
270
268−semiringNumber :: (String, String)
271+semiringNumber :: (Text, Text)
269semiringNumber = (C.dataSemiring, C.semiringNumber)
272semiringNumber = (C.dataSemiring, C.semiringNumber)
270
273
271−semiringInt :: (String, String)
274+semiringInt :: (Text, Text)
272semiringInt = (C.dataSemiring, C.semiringInt)
275semiringInt = (C.dataSemiring, C.semiringInt)
273
276
274−ringNumber :: (String, String)
277+ringNumber :: (Text, Text)
275ringNumber = (C.dataRing, C.ringNumber)
278ringNumber = (C.dataRing, C.ringNumber)
276
279
277−ringInt :: (String, String)
280+ringInt :: (Text, Text)
278ringInt = (C.dataRing, C.ringInt)
281ringInt = (C.dataRing, C.ringInt)
279
282
280−euclideanRingNumber :: (String, String)
283+euclideanRingNumber :: (Text, Text)
281euclideanRingNumber = (C.dataEuclideanRing, C.euclideanRingNumber)
284euclideanRingNumber = (C.dataEuclideanRing, C.euclideanRingNumber)
282
285
283−euclideanRingInt :: (String, String)
286+euclideanRingInt :: (Text, Text)
284euclideanRingInt = (C.dataEuclideanRing, C.euclideanRingInt)
287euclideanRingInt = (C.dataEuclideanRing, C.euclideanRingInt)
285
288
286−eqNumber :: (String, String)
289+eqNumber :: (Text, Text)
287eqNumber = (C.dataEq, C.eqNumber)
290eqNumber = (C.dataEq, C.eqNumber)
288
291
289−eqInt :: (String, String)
292+eqInt :: (Text, Text)
290eqInt = (C.dataEq, C.eqInt)
293eqInt = (C.dataEq, C.eqInt)
291
294
292−eqString :: (String, String)
295+eqString :: (Text, Text)
293eqString = (C.dataEq, C.eqString)
296eqString = (C.dataEq, C.eqString)
294
297
295−eqChar :: (String, String)
298+eqChar :: (Text, Text)
296eqChar = (C.dataEq, C.eqChar)
299eqChar = (C.dataEq, C.eqChar)
297
300
298−eqBoolean :: (String, String)
301+eqBoolean :: (Text, Text)
299eqBoolean = (C.dataEq, C.eqBoolean)
302eqBoolean = (C.dataEq, C.eqBoolean)
300
303
301−ordBoolean :: (String, String)
304+ordBoolean :: (Text, Text)
302ordBoolean = (C.dataOrd, C.ordBoolean)
305ordBoolean = (C.dataOrd, C.ordBoolean)
303
306
304−ordNumber :: (String, String)
307+ordNumber :: (Text, Text)
305ordNumber = (C.dataOrd, C.ordNumber)
308ordNumber = (C.dataOrd, C.ordNumber)
306
309
307−ordInt :: (String, String)
310+ordInt :: (Text, Text)
308ordInt = (C.dataOrd, C.ordInt)
311ordInt = (C.dataOrd, C.ordInt)
309
312
310−ordString :: (String, String)
313+ordString :: (Text, Text)
311ordString = (C.dataOrd, C.ordString)
314ordString = (C.dataOrd, C.ordString)
312
315
313−ordChar :: (String, String)
316+ordChar :: (Text, Text)
314ordChar = (C.dataOrd, C.ordChar)
317ordChar = (C.dataOrd, C.ordChar)
315
318
316−semigroupString :: (String, String)
319+semigroupString :: (Text, Text)
317semigroupString = (C.dataSemigroup, C.semigroupString)
320semigroupString = (C.dataSemigroup, C.semigroupString)
318
321
319−boundedBoolean :: (String, String)
322+boundedBoolean :: (Text, Text)
320boundedBoolean = (C.dataBounded, C.boundedBoolean)
323boundedBoolean = (C.dataBounded, C.boundedBoolean)
321
324
322−heytingAlgebraBoolean :: (String, String)
325+heytingAlgebraBoolean :: (Text, Text)
323heytingAlgebraBoolean = (C.dataHeytingAlgebra, C.heytingAlgebraBoolean)
326heytingAlgebraBoolean = (C.dataHeytingAlgebra, C.heytingAlgebraBoolean)
324
327
325−semigroupoidFn :: (String, String)
328+semigroupoidFn :: (Text, Text)
326semigroupoidFn = (C.controlSemigroupoid, C.semigroupoidFn)
329semigroupoidFn = (C.controlSemigroupoid, C.semigroupoidFn)
327
330
328−opAdd :: (String, String)
331+opAdd :: (Text, Text)
329opAdd = (C.dataSemiring, C.add)
332opAdd = (C.dataSemiring, C.add)
330
333
331−opMul :: (String, String)
334+opMul :: (Text, Text)
332opMul = (C.dataSemiring, C.mul)
335opMul = (C.dataSemiring, C.mul)
333
336
334−opEq :: (String, String)
337+opEq :: (Text, Text)
335opEq = (C.dataEq, C.eq)
338opEq = (C.dataEq, C.eq)
336
339
337−opNotEq :: (String, String)
340+opNotEq :: (Text, Text)
338opNotEq = (C.dataEq, C.notEq)
341opNotEq = (C.dataEq, C.notEq)
339
342
340−opLessThan :: (String, String)
343+opLessThan :: (Text, Text)
341opLessThan = (C.dataOrd, C.lessThan)
344opLessThan = (C.dataOrd, C.lessThan)
342
345
343−opLessThanOrEq :: (String, String)
346+opLessThanOrEq :: (Text, Text)
344opLessThanOrEq = (C.dataOrd, C.lessThanOrEq)
347opLessThanOrEq = (C.dataOrd, C.lessThanOrEq)
345
348
346−opGreaterThan :: (String, String)
349+opGreaterThan :: (Text, Text)
347opGreaterThan = (C.dataOrd, C.greaterThan)
350opGreaterThan = (C.dataOrd, C.greaterThan)
348
351
349−opGreaterThanOrEq :: (String, String)
352+opGreaterThanOrEq :: (Text, Text)
350opGreaterThanOrEq = (C.dataOrd, C.greaterThanOrEq)
353opGreaterThanOrEq = (C.dataOrd, C.greaterThanOrEq)
351
354
352−opAppend :: (String, String)
355+opAppend :: (Text, Text)
353opAppend = (C.dataSemigroup, C.append)
356opAppend = (C.dataSemigroup, C.append)
354
357
355−opSub :: (String, String)
358+opSub :: (Text, Text)
356opSub = (C.dataRing, C.sub)
359opSub = (C.dataRing, C.sub)
357
360
358−opNegate :: (String, String)
361+opNegate :: (Text, Text)
359opNegate = (C.dataRing, C.negate)
362opNegate = (C.dataRing, C.negate)
360
363
361−opDiv :: (String, String)
364+opDiv :: (Text, Text)
362opDiv = (C.dataEuclideanRing, C.div)
365opDiv = (C.dataEuclideanRing, C.div)
363
366
364−opMod :: (String, String)
367+opMod :: (Text, Text)
365opMod = (C.dataEuclideanRing, C.mod)
368opMod = (C.dataEuclideanRing, C.mod)
366
369
367−opConj :: (String, String)
370+opConj :: (Text, Text)
368opConj = (C.dataHeytingAlgebra, C.conj)
371opConj = (C.dataHeytingAlgebra, C.conj)
369
372
370−opDisj :: (String, String)
373+opDisj :: (Text, Text)
371opDisj = (C.dataHeytingAlgebra, C.disj)
374opDisj = (C.dataHeytingAlgebra, C.disj)
372
375
373−opNot :: (String, String)
376+opNot :: (Text, Text)
374opNot = (C.dataHeytingAlgebra, C.not)
377opNot = (C.dataHeytingAlgebra, C.not)
src/Language/PureScript/CodeGen/JS/Optimizer/TCO.hs+12−11
@@ -5,7 +5,8 @@ module Language.PureScript.CodeGen.JS.Optimizer.TCO (tco) where
5
5
6import Prelude.Compat
6import Prelude.Compat
7
7
8−import Data.Monoid
8+import Data.Text (Text)
9+import Data.Monoid ((<>), getAny, Any(..))
9
10
10import Language.PureScript.Options
11import Language.PureScript.Options
11import Language.PureScript.CodeGen.JS.AST
12import Language.PureScript.CodeGen.JS.AST
@@ -20,14 +21,14 @@ tco opts | optionsNoTco opts = id
20tco' :: JS -> JS
21tco' :: JS -> JS
21tco' = everywhereOnJS convert
22tco' = everywhereOnJS convert
22 where
23 where
23− tcoLabel :: String
24+ tcoLabel :: Text
24 tcoLabel = "tco"
25 tcoLabel = "tco"
25
26
26− tcoVar :: String -> String
27+ tcoVar :: Text -> Text
27− tcoVar arg = "__tco_" ++ arg
28+ tcoVar arg = "__tco_" <> arg
28
29
29− copyVar :: String -> String
30+ copyVar :: Text -> Text
30− copyVar arg = "__copy_" ++ arg
31+ copyVar arg = "__copy_" <> arg
31
32
32 convert :: JS -> JS
33 convert :: JS -> JS
33 convert js@(JSVariableIntroduction ss name (Just fn@JSFunction {})) =
34 convert js@(JSVariableIntroduction ss name (Just fn@JSFunction {})) =
@@ -42,7 +43,7 @@ tco' = everywhereOnJS convert
42 | otherwise -> js
43 | otherwise -> js
43 convert js = js
44 convert js = js
44
45
45− collectAllFunctionArgs :: [[String]] -> (JS -> JS) -> JS -> ([[String]], JS, JS -> JS)
46+ collectAllFunctionArgs :: [[Text]] -> (JS -> JS) -> JS -> ([[Text]], JS, JS -> JS)
46 collectAllFunctionArgs allArgs f (JSFunction s1 ident args (JSBlock s2 (body@(JSReturn _ _):_))) =
47 collectAllFunctionArgs allArgs f (JSFunction s1 ident args (JSBlock s2 (body@(JSReturn _ _):_))) =
47 collectAllFunctionArgs (args : allArgs) (\b -> f (JSFunction s1 ident (map copyVar args) (JSBlock s2 [b]))) body
48 collectAllFunctionArgs (args : allArgs) (\b -> f (JSFunction s1 ident (map copyVar args) (JSBlock s2 [b]))) body
48 collectAllFunctionArgs allArgs f (JSFunction ss ident args body@(JSBlock _ _)) =
49 collectAllFunctionArgs allArgs f (JSFunction ss ident args body@(JSBlock _ _)) =
@@ -53,7 +54,7 @@ tco' = everywhereOnJS convert
53 (args : allArgs, body, f . JSReturn s1 . JSFunction s2 ident (map copyVar args))
54 (args : allArgs, body, f . JSReturn s1 . JSFunction s2 ident (map copyVar args))
54 collectAllFunctionArgs allArgs f body = (allArgs, body, f)
55 collectAllFunctionArgs allArgs f body = (allArgs, body, f)
55
56
56− isTailCall :: String -> JS -> Bool
57+ isTailCall :: Text -> JS -> Bool
57 isTailCall ident js =
58 isTailCall ident js =
58 let
59 let
59 numSelfCalls = everythingOnJS (+) countSelfCalls js
60 numSelfCalls = everythingOnJS (+) countSelfCalls js
@@ -81,7 +82,7 @@ tco' = everywhereOnJS convert
81 countSelfCallsWithFnArgs :: JS -> Int
82 countSelfCallsWithFnArgs :: JS -> Int
82 countSelfCallsWithFnArgs ret = if isSelfCallWithFnArgs ident ret [] then 1 else 0
83 countSelfCallsWithFnArgs ret = if isSelfCallWithFnArgs ident ret [] then 1 else 0
83
84
84− toLoop :: String -> [String] -> JS -> JS
85+ toLoop :: Text -> [Text] -> JS -> JS
85 toLoop ident allArgs js = JSBlock rootSS $
86 toLoop ident allArgs js = JSBlock rootSS $
86 map (\arg -> JSVariableIntroduction rootSS arg (Just (JSVar rootSS (copyVar arg)))) allArgs ++
87 map (\arg -> JSVariableIntroduction rootSS arg (Just (JSVar rootSS (copyVar arg)))) allArgs ++
87 [ JSLabel rootSS tcoLabel $ JSWhile rootSS (JSBooleanLiteral rootSS True) (JSBlock rootSS [ everywhereOnJS loopify js ]) ]
88 [ JSLabel rootSS tcoLabel $ JSWhile rootSS (JSBooleanLiteral rootSS True) (JSBlock rootSS [ everywhereOnJS loopify js ]) ]
@@ -103,12 +104,12 @@ tco' = everywhereOnJS convert
103 collectSelfCallArgs allArgumentValues (JSApp _ fn args') = collectSelfCallArgs (args' : allArgumentValues) fn
104 collectSelfCallArgs allArgumentValues (JSApp _ fn args') = collectSelfCallArgs (args' : allArgumentValues) fn
104 collectSelfCallArgs allArgumentValues _ = allArgumentValues
105 collectSelfCallArgs allArgumentValues _ = allArgumentValues
105
106
106− isSelfCall :: String -> JS -> Bool
107+ isSelfCall :: Text -> JS -> Bool
107 isSelfCall ident (JSApp _ (JSVar _ ident') _) = ident == ident'
108 isSelfCall ident (JSApp _ (JSVar _ ident') _) = ident == ident'
108 isSelfCall ident (JSApp _ fn _) = isSelfCall ident fn
109 isSelfCall ident (JSApp _ fn _) = isSelfCall ident fn
109 isSelfCall _ _ = False
110 isSelfCall _ _ = False
110
111
111− isSelfCallWithFnArgs :: String -> JS -> [JS] -> Bool
112+ isSelfCallWithFnArgs :: Text -> JS -> [JS] -> Bool
112 isSelfCallWithFnArgs ident (JSVar _ ident') args | ident == ident' && any hasFunction args = True
113 isSelfCallWithFnArgs ident (JSVar _ ident') args | ident == ident' && any hasFunction args = True
113 isSelfCallWithFnArgs ident (JSApp _ fn args) acc = isSelfCallWithFnArgs ident fn (args ++ acc)
114 isSelfCallWithFnArgs ident (JSApp _ fn args) acc = isSelfCallWithFnArgs ident fn (args ++ acc)
114 isSelfCallWithFnArgs _ _ _ = False
115 isSelfCallWithFnArgs _ _ _ = False
src/Language/PureScript/Comments.hs+3−2
@@ -6,12 +6,13 @@
6module Language.PureScript.Comments where
6module Language.PureScript.Comments where
7
7
8import Prelude.Compat
8import Prelude.Compat
9+import Data.Text (Text)
9
10
10import Data.Aeson.TH
11import Data.Aeson.TH
11
12
12data Comment
13data Comment
13− = LineComment String
14+ = LineComment Text
14− | BlockComment String
15+ | BlockComment Text
15 deriving (Show, Eq, Ord)
16 deriving (Show, Eq, Ord)
16
17
17$(deriveJSON (defaultOptions { sumEncoding = ObjectWithSingleField }) ''Comment)
18$(deriveJSON (defaultOptions { sumEncoding = ObjectWithSingleField }) ''Comment)
src/Language/PureScript/Constants.hs+123−123
@@ -2,316 +2,316 @@
2module Language.PureScript.Constants where
2module Language.PureScript.Constants where
3
3
4import Prelude.Compat
4import Prelude.Compat
5−
5+import Data.Text (Text)
6import Language.PureScript.Names
6import Language.PureScript.Names
7
7
8-- Operators
8-- Operators
9
9
10−($) :: String
10+($) :: Text
11($) = "$"
11($) = "$"
12
12
13−apply :: String
13+apply :: Text
14apply = "apply"
14apply = "apply"
15
15
16−(#) :: String
16+(#) :: Text
17(#) = "#"
17(#) = "#"
18
18
19−applyFlipped :: String
19+applyFlipped :: Text
20applyFlipped = "applyFlipped"
20applyFlipped = "applyFlipped"
21
21
22−(<>) :: String
22+(<>) :: Text
23(<>) = "<>"
23(<>) = "<>"
24
24
25−(++) :: String
25+(++) :: Text
26(++) = "++"
26(++) = "++"
27
27
28−append :: String
28+append :: Text
29append = "append"
29append = "append"
30
30
31−(>>=) :: String
31+(>>=) :: Text
32(>>=) = ">>="
32(>>=) = ">>="
33
33
34−bind :: String
34+bind :: Text
35bind = "bind"
35bind = "bind"
36
36
37−(+) :: String
37+(+) :: Text
38(+) = "+"
38(+) = "+"
39
39
40−add :: String
40+add :: Text
41add = "add"
41add = "add"
42
42
43−(-) :: String
43+(-) :: Text
44(-) = "-"
44(-) = "-"
45
45
46−sub :: String
46+sub :: Text
47sub = "sub"
47sub = "sub"
48
48
49−(*) :: String
49+(*) :: Text
50(*) = "*"
50(*) = "*"
51
51
52−mul :: String
52+mul :: Text
53mul = "mul"
53mul = "mul"
54
54
55−(/) :: String
55+(/) :: Text
56(/) = "/"
56(/) = "/"
57
57
58−div :: String
58+div :: Text
59div = "div"
59div = "div"
60
60
61−(%) :: String
61+(%) :: Text
62(%) = "%"
62(%) = "%"
63
63
64−mod :: String
64+mod :: Text
65mod = "mod"
65mod = "mod"
66
66
67−(<) :: String
67+(<) :: Text
68(<) = "<"
68(<) = "<"
69
69
70−lessThan :: String
70+lessThan :: Text
71lessThan = "lessThan"
71lessThan = "lessThan"
72
72
73−(>) :: String
73+(>) :: Text
74(>) = ">"
74(>) = ">"
75
75
76−greaterThan :: String
76+greaterThan :: Text
77greaterThan = "greaterThan"
77greaterThan = "greaterThan"
78
78
79−(<=) :: String
79+(<=) :: Text
80(<=) = "<="
80(<=) = "<="
81
81
82−lessThanOrEq :: String
82+lessThanOrEq :: Text
83lessThanOrEq = "lessThanOrEq"
83lessThanOrEq = "lessThanOrEq"
84
84
85−(>=) :: String
85+(>=) :: Text
86(>=) = ">="
86(>=) = ">="
87
87
88−greaterThanOrEq :: String
88+greaterThanOrEq :: Text
89greaterThanOrEq = "greaterThanOrEq"
89greaterThanOrEq = "greaterThanOrEq"
90
90
91−(==) :: String
91+(==) :: Text
92(==) = "=="
92(==) = "=="
93
93
94−eq :: String
94+eq :: Text
95eq = "eq"
95eq = "eq"
96
96
97−(/=) :: String
97+(/=) :: Text
98(/=) = "/="
98(/=) = "/="
99
99
100−notEq :: String
100+notEq :: Text
101notEq = "notEq"
101notEq = "notEq"
102
102
103−compare :: String
103+compare :: Text
104compare = "compare"
104compare = "compare"
105
105
106−(&&) :: String
106+(&&) :: Text
107(&&) = "&&"
107(&&) = "&&"
108
108
109−conj :: String
109+conj :: Text
110conj = "conj"
110conj = "conj"
111
111
112−(||) :: String
112+(||) :: Text
113(||) = "||"
113(||) = "||"
114
114
115−disj :: String
115+disj :: Text
116disj = "disj"
116disj = "disj"
117
117
118−unsafeIndex :: String
118+unsafeIndex :: Text
119unsafeIndex = "unsafeIndex"
119unsafeIndex = "unsafeIndex"
120
120
121−or :: String
121+or :: Text
122or = "or"
122or = "or"
123
123
124−and :: String
124+and :: Text
125and = "and"
125and = "and"
126
126
127−xor :: String
127+xor :: Text
128xor = "xor"
128xor = "xor"
129
129
130−(<<<) :: String
130+(<<<) :: Text
131(<<<) = "<<<"
131(<<<) = "<<<"
132
132
133−compose :: String
133+compose :: Text
134compose = "compose"
134compose = "compose"
135
135
136−(>>>) :: String
136+(>>>) :: Text
137(>>>) = ">>>"
137(>>>) = ">>>"
138
138
139−composeFlipped :: String
139+composeFlipped :: Text
140composeFlipped = "composeFlipped"
140composeFlipped = "composeFlipped"
141
141
142-- Functions
142-- Functions
143
143
144−negate :: String
144+negate :: Text
145negate = "negate"
145negate = "negate"
146
146
147−not :: String
147+not :: Text
148not = "not"
148not = "not"
149
149
150−shl :: String
150+shl :: Text
151shl = "shl"
151shl = "shl"
152
152
153−shr :: String
153+shr :: Text
154shr = "shr"
154shr = "shr"
155
155
156−zshr :: String
156+zshr :: Text
157zshr = "zshr"
157zshr = "zshr"
158
158
159−complement :: String
159+complement :: Text
160complement = "complement"
160complement = "complement"
161
161
162-- Prelude Values
162-- Prelude Values
163
163
164−zero :: String
164+zero :: Text
165zero = "zero"
165zero = "zero"
166
166
167−one :: String
167+one :: Text
168one = "one"
168one = "one"
169
169
170−bottom :: String
170+bottom :: Text
171bottom = "bottom"
171bottom = "bottom"
172
172
173−top :: String
173+top :: Text
174top = "top"
174top = "top"
175
175
176−return :: String
176+return :: Text
177return = "return"
177return = "return"
178
178
179−pure' :: String
179+pure' :: Text
180pure' = "pure"
180pure' = "pure"
181
181
182−returnEscaped :: String
182+returnEscaped :: Text
183returnEscaped = "$return"
183returnEscaped = "$return"
184
184
185−untilE :: String
185+untilE :: Text
186untilE = "untilE"
186untilE = "untilE"
187
187
188−whileE :: String
188+whileE :: Text
189whileE = "whileE"
189whileE = "whileE"
190
190
191−runST :: String
191+runST :: Text
192runST = "runST"
192runST = "runST"
193
193
194−stRefValue :: String
194+stRefValue :: Text
195stRefValue = "value"
195stRefValue = "value"
196
196
197−newSTRef :: String
197+newSTRef :: Text
198newSTRef = "newSTRef"
198newSTRef = "newSTRef"
199
199
200−readSTRef :: String
200+readSTRef :: Text
201readSTRef = "readSTRef"
201readSTRef = "readSTRef"
202
202
203−writeSTRef :: String
203+writeSTRef :: Text
204writeSTRef = "writeSTRef"
204writeSTRef = "writeSTRef"
205
205
206−modifySTRef :: String
206+modifySTRef :: Text
207modifySTRef = "modifySTRef"
207modifySTRef = "modifySTRef"
208
208
209−mkFn :: String
209+mkFn :: Text
210mkFn = "mkFn"
210mkFn = "mkFn"
211
211
212−runFn :: String
212+runFn :: Text
213runFn = "runFn"
213runFn = "runFn"
214
214
215−unit :: String
215+unit :: Text
216unit = "unit"
216unit = "unit"
217
217
218-- Prim values
218-- Prim values
219
219
220−undefined :: String
220+undefined :: Text
221undefined = "undefined"
221undefined = "undefined"
222
222
223-- Type Class Dictionary Names
223-- Type Class Dictionary Names
224
224
225−monadEffDictionary :: String
225+monadEffDictionary :: Text
226monadEffDictionary = "monadEff"
226monadEffDictionary = "monadEff"
227
227
228−applicativeEffDictionary :: String
228+applicativeEffDictionary :: Text
229applicativeEffDictionary = "applicativeEff"
229applicativeEffDictionary = "applicativeEff"
230
230
231−bindEffDictionary :: String
231+bindEffDictionary :: Text
232bindEffDictionary = "bindEff"
232bindEffDictionary = "bindEff"
233
233
234−semiringNumber :: String
234+semiringNumber :: Text
235semiringNumber = "semiringNumber"
235semiringNumber = "semiringNumber"
236
236
237−semiringInt :: String
237+semiringInt :: Text
238semiringInt = "semiringInt"
238semiringInt = "semiringInt"
239
239
240−ringNumber :: String
240+ringNumber :: Text
241ringNumber = "ringNumber"
241ringNumber = "ringNumber"
242
242
243−ringInt :: String
243+ringInt :: Text
244ringInt = "ringInt"
244ringInt = "ringInt"
245
245
246−moduloSemiringNumber :: String
246+moduloSemiringNumber :: Text
247moduloSemiringNumber = "moduloSemiringNumber"
247moduloSemiringNumber = "moduloSemiringNumber"
248
248
249−moduloSemiringInt :: String
249+moduloSemiringInt :: Text
250moduloSemiringInt = "moduloSemiringInt"
250moduloSemiringInt = "moduloSemiringInt"
251
251
252−euclideanRingNumber :: String
252+euclideanRingNumber :: Text
253euclideanRingNumber = "euclideanRingNumber"
253euclideanRingNumber = "euclideanRingNumber"
254
254
255−euclideanRingInt :: String
255+euclideanRingInt :: Text
256euclideanRingInt = "euclideanRingInt"
256euclideanRingInt = "euclideanRingInt"
257
257
258−ordBoolean :: String
258+ordBoolean :: Text
259ordBoolean = "ordBoolean"
259ordBoolean = "ordBoolean"
260
260
261−ordNumber :: String
261+ordNumber :: Text
262ordNumber = "ordNumber"
262ordNumber = "ordNumber"
263
263
264−ordInt :: String
264+ordInt :: Text
265ordInt = "ordInt"
265ordInt = "ordInt"
266
266
267−ordString :: String
267+ordString :: Text
268ordString = "ordString"
268ordString = "ordString"
269
269
270−ordChar :: String
270+ordChar :: Text
271ordChar = "ordChar"
271ordChar = "ordChar"
272
272
273−eqNumber :: String
273+eqNumber :: Text
274eqNumber = "eqNumber"
274eqNumber = "eqNumber"
275
275
276−eqInt :: String
276+eqInt :: Text
277eqInt = "eqInt"
277eqInt = "eqInt"
278
278
279−eqString :: String
279+eqString :: Text
280eqString = "eqString"
280eqString = "eqString"
281
281
282−eqChar :: String
282+eqChar :: Text
283eqChar = "eqChar"
283eqChar = "eqChar"
284
284
285−eqBoolean :: String
285+eqBoolean :: Text
286eqBoolean = "eqBoolean"
286eqBoolean = "eqBoolean"
287
287
288−boundedBoolean :: String
288+boundedBoolean :: Text
289boundedBoolean = "boundedBoolean"
289boundedBoolean = "boundedBoolean"
290
290
291−booleanAlgebraBoolean :: String
291+booleanAlgebraBoolean :: Text
292booleanAlgebraBoolean = "booleanAlgebraBoolean"
292booleanAlgebraBoolean = "booleanAlgebraBoolean"
293
293
294−heytingAlgebraBoolean :: String
294+heytingAlgebraBoolean :: Text
295heytingAlgebraBoolean = "heytingAlgebraBoolean"
295heytingAlgebraBoolean = "heytingAlgebraBoolean"
296
296
297−semigroupString :: String
297+semigroupString :: Text
298semigroupString = "semigroupString"
298semigroupString = "semigroupString"
299
299
300−semigroupoidFn :: String
300+semigroupoidFn :: Text
301semigroupoidFn = "semigroupoidFn"
301semigroupoidFn = "semigroupoidFn"
302
302
303-- Generic Deriving
303-- Generic Deriving
304
304
305−generic :: String
305+generic :: Text
306generic = "Generic"
306generic = "Generic"
307
307
308−toSpine :: String
308+toSpine :: Text
309toSpine = "toSpine"
309toSpine = "toSpine"
310
310
311−fromSpine :: String
311+fromSpine :: Text
312fromSpine = "fromSpine"
312fromSpine = "fromSpine"
313
313
314−toSignature :: String
314+toSignature :: Text
315toSignature = "toSignature"
315toSignature = "toSignature"
316
316
317-- IsSymbol class
317-- IsSymbol class
@@ -321,12 +321,12 @@ pattern IsSymbol = Qualified (Just (ModuleName [ProperName "Data", ProperName "S
321
321
322-- Main module
322-- Main module
323
323
324−main :: String
324+main :: Text
325main = "main"
325main = "main"
326
326
327-- Prim
327-- Prim
328
328
329−partial :: String
329+partial :: Text
330partial = "Partial"
330partial = "Partial"
331
331
332pattern Partial :: Qualified (ProperName 'ClassName)
332pattern Partial :: Qualified (ProperName 'ClassName)
@@ -337,67 +337,67 @@ pattern Fail = Qualified (Just (ModuleName [ProperName "Prim"])) (ProperName "Fa
337
337
338-- Code Generation
338-- Code Generation
339
339
340−__superclass_ :: String
340+__superclass_ :: Text
341__superclass_ = "__superclass_"
341__superclass_ = "__superclass_"
342
342
343−__unused :: String
343+__unused :: Text
344__unused = "__unused"
344__unused = "__unused"
345
345
346-- Modules
346-- Modules
347
347
348−prim :: String
348+prim :: Text
349prim = "Prim"
349prim = "Prim"
350
350
351−prelude :: String
351+prelude :: Text
352prelude = "Prelude"
352prelude = "Prelude"
353
353
354−dataArray :: String
354+dataArray :: Text
355dataArray = "Data_Array"
355dataArray = "Data_Array"
356
356
357−eff :: String
357+eff :: Text
358eff = "Control_Monad_Eff"
358eff = "Control_Monad_Eff"
359
359
360−st :: String
360+st :: Text
361st = "Control_Monad_ST"
361st = "Control_Monad_ST"
362
362
363−controlApplicative :: String
363+controlApplicative :: Text
364controlApplicative = "Control_Applicative"
364controlApplicative = "Control_Applicative"
365
365
366−controlSemigroupoid :: String
366+controlSemigroupoid :: Text
367controlSemigroupoid = "Control_Semigroupoid"
367controlSemigroupoid = "Control_Semigroupoid"
368
368
369−controlBind :: String
369+controlBind :: Text
370controlBind = "Control_Bind"
370controlBind = "Control_Bind"
371
371
372−dataBounded :: String
372+dataBounded :: Text
373dataBounded = "Data_Bounded"
373dataBounded = "Data_Bounded"
374
374
375−dataSemigroup :: String
375+dataSemigroup :: Text
376dataSemigroup = "Data_Semigroup"
376dataSemigroup = "Data_Semigroup"
377
377
378−dataHeytingAlgebra :: String
378+dataHeytingAlgebra :: Text
379dataHeytingAlgebra = "Data_HeytingAlgebra"
379dataHeytingAlgebra = "Data_HeytingAlgebra"
380
380
381−dataEq :: String
381+dataEq :: Text
382dataEq = "Data_Eq"
382dataEq = "Data_Eq"
383
383
384−dataOrd :: String
384+dataOrd :: Text
385dataOrd = "Data_Ord"
385dataOrd = "Data_Ord"
386
386
387−dataSemiring :: String
387+dataSemiring :: Text
388dataSemiring = "Data_Semiring"
388dataSemiring = "Data_Semiring"
389
389
390−dataRing :: String
390+dataRing :: Text
391dataRing = "Data_Ring"
391dataRing = "Data_Ring"
392
392
393−dataEuclideanRing :: String
393+dataEuclideanRing :: Text
394dataEuclideanRing = "Data_EuclideanRing"
394dataEuclideanRing = "Data_EuclideanRing"
395
395
396−dataFunction :: String
396+dataFunction :: Text
397dataFunction = "Data_Function"
397dataFunction = "Data_Function"
398
398
399−dataFunctionUncurried :: String
399+dataFunctionUncurried :: Text
400dataFunctionUncurried = "Data_Function_Uncurried"
400dataFunctionUncurried = "Data_Function_Uncurried"
401
401
402−dataIntBits :: String
402+dataIntBits :: Text
403dataIntBits = "Data_Int_Bits"
403dataIntBits = "Data_Int_Bits"
src/Language/PureScript/CoreFn/Expr.hs+3−2
@@ -6,6 +6,7 @@ module Language.PureScript.CoreFn.Expr where
6import Prelude.Compat
6import Prelude.Compat
7
7
8import Control.Arrow ((***))
8import Control.Arrow ((***))
9+import Data.Text (Text)
9
10
10import Language.PureScript.AST.Literals
11import Language.PureScript.AST.Literals
11import Language.PureScript.CoreFn.Binders
12import Language.PureScript.CoreFn.Binders
@@ -26,11 +27,11 @@ data Expr a
26 -- |
27 -- |
27 -- A record property accessor
28 -- A record property accessor
28 --
29 --
29− | Accessor a String (Expr a)
30+ | Accessor a Text (Expr a)
30 -- |
31 -- |
31 -- Partial record update
32 -- Partial record update
32 --
33 --
33− | ObjectUpdate a (Expr a) [(String, Expr a)]
34+ | ObjectUpdate a (Expr a) [(Text, Expr a)]
34 -- |
35 -- |
35 -- Function introduction
36 -- Function introduction
36 --
37 --
src/Language/PureScript/CoreFn/ToJSON.hs+13−11
@@ -1,3 +1,4 @@
1+{-# LANGUAGE NoOverloadedStrings #-}
1-- |
2-- |
2-- Dump the core functional representation in JSON format for consumption
3-- Dump the core functional representation in JSON format for consumption
3-- by third-party code generators
4-- by third-party code generators
@@ -10,7 +11,8 @@ import Prelude.Compat
10
11
11import Data.Aeson
12import Data.Aeson
12import Data.Version (Version, showVersion)
13import Data.Version (Version, showVersion)
13−import Data.Text (pack)
14+import Data.Text (Text)
15+import qualified Data.Text as T
14
16
15import Language.PureScript.AST.Literals
17import Language.PureScript.AST.Literals
16import Language.PureScript.CoreFn
18import Language.PureScript.CoreFn
@@ -31,26 +33,26 @@ identToJSON = toJSON . runIdent
31properNameToJSON :: ProperName a -> Value
33properNameToJSON :: ProperName a -> Value
32properNameToJSON = toJSON . runProperName
34properNameToJSON = toJSON . runProperName
33
35
34−qualifiedToJSON :: (a -> String) -> Qualified a -> Value
36+qualifiedToJSON :: (a -> Text) -> Qualified a -> Value
35qualifiedToJSON f = toJSON . showQualified f
37qualifiedToJSON f = toJSON . showQualified f
36
38
37moduleNameToJSON :: ModuleName -> Value
39moduleNameToJSON :: ModuleName -> Value
38moduleNameToJSON = toJSON . runModuleName
40moduleNameToJSON = toJSON . runModuleName
39
41
40moduleToJSON :: Version -> Module a -> Value
42moduleToJSON :: Version -> Module a -> Value
41−moduleToJSON v m = object [ pack "imports" .= map (moduleNameToJSON . snd) (moduleImports m)
43+moduleToJSON v m = object [ T.pack "imports" .= map (moduleNameToJSON . snd) (moduleImports m)
42− , pack "exports" .= map identToJSON (moduleExports m)
44+ , T.pack "exports" .= map identToJSON (moduleExports m)
43− , pack "foreign" .= map (identToJSON . fst) (moduleForeign m)
45+ , T.pack "foreign" .= map (identToJSON . fst) (moduleForeign m)
44− , pack "decls" .= map bindToJSON (moduleDecls m)
46+ , T.pack "decls" .= map bindToJSON (moduleDecls m)
45− , pack "builtWith" .= toJSON (showVersion v)
47+ , T.pack "builtWith" .= toJSON (showVersion v)
46 ]
48 ]
47
49
48bindToJSON :: Bind a -> Value
50bindToJSON :: Bind a -> Value
49−bindToJSON (NonRec _ n e) = object [ pack (runIdent n) .= exprToJSON e ]
51+bindToJSON (NonRec _ n e) = object [ runIdent n .= exprToJSON e ]
50−bindToJSON (Rec bs) = object $ map (\((_, n), e) -> pack (runIdent n) .= exprToJSON e) bs
52+bindToJSON (Rec bs) = object $ map (\((_, n), e) -> runIdent n .= exprToJSON e) bs
51
53
52−recordToJSON :: (a -> Value) -> [(String, a)] -> Value
54+recordToJSON :: (a -> Value) -> [(Text, a)] -> Value
53−recordToJSON f = object . map (\(label, a) -> pack label .= f a)
55+recordToJSON f = object . map (\(label, a) -> label .= f a)
54
56
55exprToJSON :: Expr a -> Value
57exprToJSON :: Expr a -> Value
56exprToJSON (Var _ i) = toJSON ( "Var"
58exprToJSON (Var _ i) = toJSON ( "Var"
src/Language/PureScript/Docs/AsMarkdown.hs+3−2
@@ -14,6 +14,7 @@ import Control.Monad.Writer (Writer, tell, execWriter)
14
14
15import Data.Foldable (for_)
15import Data.Foldable (for_)
16import Data.List (partition)
16import Data.List (partition)
17+import qualified Data.Text as T
17
18
18import Language.PureScript.Docs.RenderedCode
19import Language.PureScript.Docs.RenderedCode
19import Language.PureScript.Docs.Types
20import Language.PureScript.Docs.Types
@@ -37,13 +38,13 @@ modulesAsMarkdown = mapM_ moduleAsMarkdown
37
38
38moduleAsMarkdown :: Module -> Docs
39moduleAsMarkdown :: Module -> Docs
39moduleAsMarkdown Module{..} = do
40moduleAsMarkdown Module{..} = do
40− headerLevel 2 $ "Module " ++ P.runModuleName modName
41+ headerLevel 2 $ "Module " ++ T.unpack (P.runModuleName modName)
41 spacer
42 spacer
42 for_ modComments tell'
43 for_ modComments tell'
43 mapM_ (declAsMarkdown modName) modDeclarations
44 mapM_ (declAsMarkdown modName) modDeclarations
44 spacer
45 spacer
45 for_ modReExports $ \(mn, decls) -> do
46 for_ modReExports $ \(mn, decls) -> do
46− headerLevel 3 $ "Re-exported from " ++ P.runModuleName mn ++ ":"
47+ headerLevel 3 $ "Re-exported from " ++ T.unpack (P.runModuleName mn) ++ ":"
47 spacer
48 spacer
48 mapM_ (declAsMarkdown mn) decls
49 mapM_ (declAsMarkdown mn) decls
49
50
src/Language/PureScript/Docs/Convert.hs+2−1
@@ -18,6 +18,7 @@ import Control.Monad.Error.Class (MonadError)
18import Control.Monad.State (runStateT)
18import Control.Monad.State (runStateT)
19import Control.Monad.Writer.Strict (runWriterT)
19import Control.Monad.Writer.Strict (runWriterT)
20import qualified Data.Map as Map
20import qualified Data.Map as Map
21+import qualified Data.Text as T
21
22
22import Language.PureScript.Docs.Convert.ReExports (updateReExports)
23import Language.PureScript.Docs.Convert.ReExports (updateReExports)
23import Language.PureScript.Docs.Convert.Single (convertSingleModule, collectBookmarks)
24import Language.PureScript.Docs.Convert.Single (convertSingleModule, collectBookmarks)
@@ -170,7 +171,7 @@ insertValueTypes env m =
170
171
171runParser :: P.TokenParser a -> String -> Either String a
172runParser :: P.TokenParser a -> String -> Either String a
172runParser p s = either (Left . show) Right $ do
173runParser p s = either (Left . show) Right $ do
173− ts <- P.lex "" s
174+ ts <- P.lex "" (T.pack s)
174 P.runTokenParser "" (p <* eof) ts
175 P.runTokenParser "" (p <* eof) ts
175
176
176-- |
177-- |
src/Language/PureScript/Docs/Convert/ReExports.hs+15−14
@@ -4,7 +4,7 @@ module Language.PureScript.Docs.Convert.ReExports
4
4
5import Prelude.Compat
5import Prelude.Compat
6
6
7−import Control.Arrow ((&&&), second)
7+import Control.Arrow ((&&&), first, second)
8import Control.Monad
8import Control.Monad
9import Control.Monad.Reader.Class (MonadReader, ask)
9import Control.Monad.Reader.Class (MonadReader, ask)
10import Control.Monad.State.Class (MonadState, gets, modify)
10import Control.Monad.State.Class (MonadState, gets, modify)
@@ -16,6 +16,7 @@ import Data.Map (Map)
16import Data.Maybe (mapMaybe)
16import Data.Maybe (mapMaybe)
17import Data.Monoid ((<>))
17import Data.Monoid ((<>))
18import qualified Data.Map as Map
18import qualified Data.Map as Map
19+import qualified Data.Text as T
19
20
20import Language.PureScript.Docs.Types
21import Language.PureScript.Docs.Types
21import qualified Language.PureScript as P
22import qualified Language.PureScript as P
@@ -52,7 +53,7 @@ updateReExports env order = execState action
52 Just v' ->
53 Just v' ->
53 pure v'
54 pure v'
54 Nothing ->
55 Nothing ->
55− internalError ("Module missing: " ++ P.runModuleName mn)
56+ internalError ("Module missing: " ++ T.unpack (P.runModuleName mn))
56
57
57-- |
58-- |
58-- Collect all of the re-exported declarations for a single module.
59-- Collect all of the re-exported declarations for a single module.
@@ -69,7 +70,7 @@ getReExports ::
69getReExports env mn =
70getReExports env mn =
70 case Map.lookup mn env of
71 case Map.lookup mn env of
71 Nothing ->
72 Nothing ->
72− internalError ("Module missing: " ++ P.runModuleName mn)
73+ internalError ("Module missing: " ++ T.unpack (P.runModuleName mn))
73 Just (_, imports, exports) -> do
74 Just (_, imports, exports) -> do
74 allExports <- runReaderT (collectDeclarations imports exports) mn
75 allExports <- runReaderT (collectDeclarations imports exports) mn
75 pure (filter notLocal allExports)
76 pure (filter notLocal allExports)
@@ -188,7 +189,7 @@ lookupValueDeclaration importedFrom ident = do
188 decls <- lookupModuleDeclarations "lookupValueDeclaration" importedFrom
189 decls <- lookupModuleDeclarations "lookupValueDeclaration" importedFrom
189 let
190 let
190 rs =
191 rs =
191− filter (\d -> declTitle d == P.showIdent ident
192+ filter (\d -> declTitle d == T.unpack (P.showIdent ident)
192 && (isValue d || isValueAlias d)) decls
193 && (isValue d || isValueAlias d)) decls
193 errOther other =
194 errOther other =
194 internalErrorInModule
195 internalErrorInModule
@@ -214,7 +215,7 @@ lookupValueDeclaration importedFrom ident = do
214 (declChildren d))
215 (declChildren d))
215
216
216 matchesIdent cdecl =
217 matchesIdent cdecl =
217− cdeclTitle cdecl == P.showIdent ident
218+ cdeclTitle cdecl == T.unpack (P.showIdent ident)
218
219
219 matchesAndIsTypeClassMember =
220 matchesAndIsTypeClassMember =
220 uncurry (&&) . (matchesIdent &&& isTypeClassMember)
221 uncurry (&&) . (matchesIdent &&& isTypeClassMember)
@@ -238,7 +239,7 @@ lookupValueOpDeclaration
238 -> m (P.ModuleName, [Declaration])
239 -> m (P.ModuleName, [Declaration])
239lookupValueOpDeclaration importedFrom op = do
240lookupValueOpDeclaration importedFrom op = do
240 decls <- lookupModuleDeclarations "lookupValueOpDeclaration" importedFrom
241 decls <- lookupModuleDeclarations "lookupValueOpDeclaration" importedFrom
241− case filter (\d -> declTitle d == P.showOp op && isValueAlias d) decls of
242+ case filter (\d -> declTitle d == T.unpack (P.showOp op) && isValueAlias d) decls of
242 [d] ->
243 [d] ->
243 pure (importedFrom, [d])
244 pure (importedFrom, [d])
244 other ->
245 other ->
@@ -258,7 +259,7 @@ lookupTypeDeclaration ::
258lookupTypeDeclaration importedFrom ty = do
259lookupTypeDeclaration importedFrom ty = do
259 decls <- lookupModuleDeclarations "lookupTypeDeclaration" importedFrom
260 decls <- lookupModuleDeclarations "lookupTypeDeclaration" importedFrom
260 let
261 let
261− ds = filter (\d -> declTitle d == P.runProperName ty && isType d) decls
262+ ds = filter (\d -> declTitle d == T.unpack (P.runProperName ty) && isType d) decls
262 case ds of
263 case ds of
263 [d] ->
264 [d] ->
264 pure (importedFrom, [d])
265 pure (importedFrom, [d])
@@ -274,7 +275,7 @@ lookupTypeOpDeclaration
274lookupTypeOpDeclaration importedFrom tyOp = do
275lookupTypeOpDeclaration importedFrom tyOp = do
275 decls <- lookupModuleDeclarations "lookupTypeOpDeclaration" importedFrom
276 decls <- lookupModuleDeclarations "lookupTypeOpDeclaration" importedFrom
276 let
277 let
277− ds = filter (\d -> declTitle d == ("type " ++ P.showOp tyOp) && isTypeAlias d) decls
278+ ds = filter (\d -> declTitle d == ("type " ++ T.unpack (P.showOp tyOp)) && isTypeAlias d) decls
278 case ds of
279 case ds of
279 [d] ->
280 [d] ->
280 pure (importedFrom, [d])
281 pure (importedFrom, [d])
@@ -290,7 +291,7 @@ lookupTypeClassDeclaration
290lookupTypeClassDeclaration importedFrom tyClass = do
291lookupTypeClassDeclaration importedFrom tyClass = do
291 decls <- lookupModuleDeclarations "lookupTypeClassDeclaration" importedFrom
292 decls <- lookupModuleDeclarations "lookupTypeClassDeclaration" importedFrom
292 let
293 let
293− ds = filter (\d -> declTitle d == P.runProperName tyClass
294+ ds = filter (\d -> declTitle d == T.unpack (P.runProperName tyClass)
294 && isTypeClass d)
295 && isTypeClass d)
295 decls
296 decls
296 case ds of
297 case ds of
@@ -317,7 +318,7 @@ lookupModuleDeclarations definedIn moduleName = do
317 Nothing ->
318 Nothing ->
318 internalErrorInModule
319 internalErrorInModule
319 (definedIn ++ ": module missing: "
320 (definedIn ++ ": module missing: "
320− ++ P.runModuleName moduleName)
321+ ++ T.unpack (P.runModuleName moduleName))
321 Just mdl ->
322 Just mdl ->
322 pure (allDeclarations mdl)
323 pure (allDeclarations mdl)
323
324
@@ -447,7 +448,7 @@ filterDataConstructors
447 -> Map P.ModuleName [Declaration]
448 -> Map P.ModuleName [Declaration]
448 -> Map P.ModuleName [Declaration]
449 -> Map P.ModuleName [Declaration]
449filterDataConstructors =
450filterDataConstructors =
450− filterExportedChildren isDataConstructor P.runProperName
451+ filterExportedChildren isDataConstructor (T.unpack . P.runProperName)
451
452
452-- |
453-- |
453-- Given a list of exported type class member names, remove any data
454-- Given a list of exported type class member names, remove any data
@@ -459,7 +460,7 @@ filterTypeClassMembers
459 -> Map P.ModuleName [Declaration]
460 -> Map P.ModuleName [Declaration]
460 -> Map P.ModuleName [Declaration]
461 -> Map P.ModuleName [Declaration]
461filterTypeClassMembers =
462filterTypeClassMembers =
462− filterExportedChildren isTypeClassMember P.showIdent
463+ filterExportedChildren isTypeClassMember (T.unpack . P.showIdent)
463
464
464filterExportedChildren
465filterExportedChildren
465 :: (Functor f)
466 :: (Functor f)
@@ -492,7 +493,7 @@ internalErrorInModule
492internalErrorInModule msg = do
493internalErrorInModule msg = do
493 mn <- ask
494 mn <- ask
494 internalError
495 internalError
495− ("while collecting re-exports for module: " ++ P.runModuleName mn ++
496+ ("while collecting re-exports for module: " ++ T.unpack (P.runModuleName mn) ++
496 ", " ++ msg)
497 ", " ++ msg)
497
498
498-- |
499-- |
@@ -503,7 +504,7 @@ typeClassConstraintFor :: Declaration -> Maybe P.Constraint
503typeClassConstraintFor Declaration{..} =
504typeClassConstraintFor Declaration{..} =
504 case declInfo of
505 case declInfo of
505 TypeClassDeclaration tyArgs _ ->
506 TypeClassDeclaration tyArgs _ ->
506− Just (P.Constraint (P.Qualified Nothing (P.ProperName declTitle)) (mkConstraint tyArgs) Nothing)
507+ Just (P.Constraint (P.Qualified Nothing (P.ProperName (T.pack declTitle))) (mkConstraint (map (first T.pack) tyArgs)) Nothing)
507 _ ->
508 _ ->
508 Nothing
509 Nothing
509 where
510 where
src/Language/PureScript/Docs/Convert/Single.hs+22−16
@@ -5,16 +5,22 @@ module Language.PureScript.Docs.Convert.Single
5
5
6import Prelude.Compat
6import Prelude.Compat
7
7
8+import Control.Arrow (first)
8import Control.Category ((>>>))
9import Control.Category ((>>>))
9import Control.Monad
10import Control.Monad
10
11
11import Data.Either
12import Data.Either
12import Data.List (nub)
13import Data.List (nub)
13import Data.Maybe (mapMaybe)
14import Data.Maybe (mapMaybe)
15+import Data.Monoid ((<>))
16+import Data.Text (Text)
17+import qualified Data.Text as T
14
18
15import Language.PureScript.Docs.Types
19import Language.PureScript.Docs.Types
16import qualified Language.PureScript as P
20import qualified Language.PureScript as P
17
21
22+-- TODO (Christoph): Get rid of the T.unpack s
23+
18-- |
24-- |
19-- Convert a single Module, but ignore re-exports; any re-exported types or
25-- Convert a single Module, but ignore re-exports; any re-exported types or
20-- values will not appear in the result.
26-- values will not appear in the result.
@@ -75,7 +81,7 @@ augmentDeclarations (partitionEithers -> (augments, toplevels)) =
75 augmentWith (AugmentChild child) d =
81 augmentWith (AugmentChild child) d =
76 d { declChildren = declChildren d ++ [child] }
82 d { declChildren = declChildren d ++ [child] }
77
83
78−getDeclarationTitle :: P.Declaration -> Maybe String
84+getDeclarationTitle :: P.Declaration -> Maybe Text
79getDeclarationTitle (P.ValueDeclaration name _ _ _) = Just (P.showIdent name)
85getDeclarationTitle (P.ValueDeclaration name _ _ _) = Just (P.showIdent name)
80getDeclarationTitle (P.ExternDeclaration name _) = Just (P.showIdent name)
86getDeclarationTitle (P.ExternDeclaration name _) = Just (P.showIdent name)
81getDeclarationTitle (P.DataDeclaration _ name _ _) = Just (P.runProperName name)
87getDeclarationTitle (P.DataDeclaration _ name _ _) = Just (P.runProperName name)
@@ -83,25 +89,25 @@ getDeclarationTitle (P.ExternDataDeclaration name _) = Just (P.runProperName nam
83getDeclarationTitle (P.TypeSynonymDeclaration name _ _) = Just (P.runProperName name)
89getDeclarationTitle (P.TypeSynonymDeclaration name _ _) = Just (P.runProperName name)
84getDeclarationTitle (P.TypeClassDeclaration name _ _ _ _) = Just (P.runProperName name)
90getDeclarationTitle (P.TypeClassDeclaration name _ _ _ _) = Just (P.runProperName name)
85getDeclarationTitle (P.TypeInstanceDeclaration name _ _ _ _) = Just (P.showIdent name)
91getDeclarationTitle (P.TypeInstanceDeclaration name _ _ _ _) = Just (P.showIdent name)
86−getDeclarationTitle (P.TypeFixityDeclaration _ _ op) = Just ("type " ++ P.showOp op)
92+getDeclarationTitle (P.TypeFixityDeclaration _ _ op) = Just ("type " <> P.showOp op)
87getDeclarationTitle (P.ValueFixityDeclaration _ _ op) = Just (P.showOp op)
93getDeclarationTitle (P.ValueFixityDeclaration _ _ op) = Just (P.showOp op)
88getDeclarationTitle (P.PositionedDeclaration _ _ d) = getDeclarationTitle d
94getDeclarationTitle (P.PositionedDeclaration _ _ d) = getDeclarationTitle d
89getDeclarationTitle _ = Nothing
95getDeclarationTitle _ = Nothing
90
96
91-- | Create a basic Declaration value.
97-- | Create a basic Declaration value.
92−mkDeclaration :: String -> DeclarationInfo -> Declaration
98+mkDeclaration :: Text -> DeclarationInfo -> Declaration
93mkDeclaration title info =
99mkDeclaration title info =
94− Declaration { declTitle = title
100+ Declaration { declTitle = T.unpack title
95 , declComments = Nothing
101 , declComments = Nothing
96 , declSourceSpan = Nothing
102 , declSourceSpan = Nothing
97 , declChildren = []
103 , declChildren = []
98 , declInfo = info
104 , declInfo = info
99 }
105 }
100
106
101−basicDeclaration :: String -> DeclarationInfo -> Maybe IntermediateDeclaration
107+basicDeclaration :: Text -> DeclarationInfo -> Maybe IntermediateDeclaration
102basicDeclaration title info = Just $ Right $ mkDeclaration title info
108basicDeclaration title info = Just $ Right $ mkDeclaration title info
103
109
104−convertDeclaration :: P.Declaration -> String -> Maybe IntermediateDeclaration
110+convertDeclaration :: P.Declaration -> Text -> Maybe IntermediateDeclaration
105convertDeclaration (P.ValueDeclaration _ _ _ (Right (P.TypedValue _ _ ty))) title =
111convertDeclaration (P.ValueDeclaration _ _ _ (Right (P.TypedValue _ _ ty))) title =
106 basicDeclaration title (ValueDeclaration ty)
112 basicDeclaration title (ValueDeclaration ty)
107convertDeclaration P.ValueDeclaration{} title =
113convertDeclaration P.ValueDeclaration{} title =
@@ -113,27 +119,27 @@ convertDeclaration (P.ExternDeclaration _ ty) title =
113convertDeclaration (P.DataDeclaration dtype _ args ctors) title =
119convertDeclaration (P.DataDeclaration dtype _ args ctors) title =
114 Just (Right (mkDeclaration title info) { declChildren = children })
120 Just (Right (mkDeclaration title info) { declChildren = children })
115 where
121 where
116− info = DataDeclaration dtype args
122+ info = DataDeclaration dtype (map (first T.unpack) args)
117 children = map convertCtor ctors
123 children = map convertCtor ctors
118 convertCtor (ctor', tys) =
124 convertCtor (ctor', tys) =
119− ChildDeclaration (P.runProperName ctor') Nothing Nothing (ChildDataConstructor tys)
125+ ChildDeclaration (T.unpack (P.runProperName ctor')) Nothing Nothing (ChildDataConstructor tys)
120convertDeclaration (P.ExternDataDeclaration _ kind') title =
126convertDeclaration (P.ExternDataDeclaration _ kind') title =
121 basicDeclaration title (ExternDataDeclaration kind')
127 basicDeclaration title (ExternDataDeclaration kind')
122convertDeclaration (P.TypeSynonymDeclaration _ args ty) title =
128convertDeclaration (P.TypeSynonymDeclaration _ args ty) title =
123− basicDeclaration title (TypeSynonymDeclaration args ty)
129+ basicDeclaration title (TypeSynonymDeclaration (map (first T.unpack) args) ty)
124convertDeclaration (P.TypeClassDeclaration _ args implies _ ds) title = -- TODO: include fundep info
130convertDeclaration (P.TypeClassDeclaration _ args implies _ ds) title = -- TODO: include fundep info
125 Just (Right (mkDeclaration title info) { declChildren = children })
131 Just (Right (mkDeclaration title info) { declChildren = children })
126 where
132 where
127− info = TypeClassDeclaration args implies
133+ info = TypeClassDeclaration (map (first T.unpack) args) implies
128 children = map convertClassMember ds
134 children = map convertClassMember ds
129 convertClassMember (P.PositionedDeclaration _ _ d) =
135 convertClassMember (P.PositionedDeclaration _ _ d) =
130 convertClassMember d
136 convertClassMember d
131 convertClassMember (P.TypeDeclaration ident' ty) =
137 convertClassMember (P.TypeDeclaration ident' ty) =
132− ChildDeclaration (P.showIdent ident') Nothing Nothing (ChildTypeClassMember ty)
138+ ChildDeclaration (T.unpack (P.showIdent ident')) Nothing Nothing (ChildTypeClassMember ty)
133 convertClassMember _ =
139 convertClassMember _ =
134 P.internalError "convertDeclaration: Invalid argument to convertClassMember."
140 P.internalError "convertDeclaration: Invalid argument to convertClassMember."
135convertDeclaration (P.TypeInstanceDeclaration _ constraints className tys _) title =
141convertDeclaration (P.TypeInstanceDeclaration _ constraints className tys _) title =
136− Just (Left (classNameString : typeNameStrings, AugmentChild childDecl))
142+ Just (Left (T.unpack classNameString : map T.unpack typeNameStrings, AugmentChild childDecl))
137 where
143 where
138 classNameString = unQual className
144 classNameString = unQual className
139 typeNameStrings = nub (concatMap (P.everythingOnTypes (++) extractProperNames) tys)
145 typeNameStrings = nub (concatMap (P.everythingOnTypes (++) extractProperNames) tys)
@@ -142,7 +148,7 @@ convertDeclaration (P.TypeInstanceDeclaration _ constraints className tys _) tit
142 extractProperNames (P.TypeConstructor n) = [unQual n]
148 extractProperNames (P.TypeConstructor n) = [unQual n]
143 extractProperNames _ = []
149 extractProperNames _ = []
144
150
145− childDecl = ChildDeclaration title Nothing Nothing (ChildInstance constraints classApp)
151+ childDecl = ChildDeclaration (T.unpack title) Nothing Nothing (ChildInstance constraints classApp)
146 classApp = foldl P.TypeApp (P.TypeConstructor (fmap P.coerceProperName className)) tys
152 classApp = foldl P.TypeApp (P.TypeConstructor (fmap P.coerceProperName className)) tys
147convertDeclaration (P.ValueFixityDeclaration fixity (P.Qualified mn alias) _) title =
153convertDeclaration (P.ValueFixityDeclaration fixity (P.Qualified mn alias) _) title =
148 Just $ Right $ mkDeclaration title (AliasDeclaration fixity (P.Qualified mn (Right alias)))
154 Just $ Right $ mkDeclaration title (AliasDeclaration fixity (P.Qualified mn (Right alias)))
@@ -174,8 +180,8 @@ convertComments cs = do
174 pure (unlines docs)
180 pure (unlines docs)
175
181
176 where
182 where
177− toLines (P.LineComment s) = [s]
183+ toLines (P.LineComment s) = [T.unpack s]
178− toLines (P.BlockComment s) = lines s
184+ toLines (P.BlockComment s) = lines (T.unpack s)
179
185
180 stripPipe s' =
186 stripPipe s' =
181 case dropWhile (== ' ') s' of
187 case dropWhile (== ' ') s' of
@@ -196,5 +202,5 @@ collectBookmarks (FromDep pkg m) = map (FromDep pkg) (collectBookmarks' m)
196collectBookmarks' :: P.Module -> [(P.ModuleName, String)]
202collectBookmarks' :: P.Module -> [(P.ModuleName, String)]
197collectBookmarks' m =
203collectBookmarks' m =
198 map (P.getModuleName m, )
204 map (P.getModuleName m, )
199− (mapMaybe getDeclarationTitle
205+ (mapMaybe (fmap T.unpack . getDeclarationTitle)
200 (P.exportedDeclarations m))
206 (P.exportedDeclarations m))
src/Language/PureScript/Docs/Render.hs+13−9
@@ -13,12 +13,16 @@ import Prelude.Compat
13
13
14import Data.Maybe (maybeToList)
14import Data.Maybe (maybeToList)
15import Data.Monoid ((<>))
15import Data.Monoid ((<>))
16+import qualified Data.Text as T
17+import Data.Text (Text)
16
18
17import Language.PureScript.Docs.RenderedCode
19import Language.PureScript.Docs.RenderedCode
18import Language.PureScript.Docs.Types
20import Language.PureScript.Docs.Types
19import Language.PureScript.Docs.Utils.MonoidExtras
21import Language.PureScript.Docs.Utils.MonoidExtras
20import qualified Language.PureScript as P
22import qualified Language.PureScript as P
21
23
24+-- TODO (Christoph): get rid of T.unpack's
25+
22renderDeclaration :: Declaration -> RenderedCode
26renderDeclaration :: Declaration -> RenderedCode
23renderDeclaration = renderDeclarationWithOptions defaultRenderTypeOptions
27renderDeclaration = renderDeclarationWithOptions defaultRenderTypeOptions
24
28
@@ -31,7 +35,7 @@ renderDeclarationWithOptions opts Declaration{..} =
31 , renderType' ty
35 , renderType' ty
32 ]
36 ]
33 DataDeclaration dtype args ->
37 DataDeclaration dtype args ->
34− [ keyword (P.showDataDeclType dtype)
38+ [ keyword (T.unpack (P.showDataDeclType dtype))
35 , renderType' (typeApp declTitle args)
39 , renderType' (typeApp declTitle args)
36 ]
40 ]
37 ExternDataDeclaration kind' ->
41 ExternDataDeclaration kind' ->
@@ -74,15 +78,15 @@ renderDeclarationWithOptions opts Declaration{..} =
74
78
75 renderQualAlias :: FixityAlias -> String
79 renderQualAlias :: FixityAlias -> String
76 renderQualAlias (P.Qualified mn alias)
80 renderQualAlias (P.Qualified mn alias)
77− | mn == currentModule opts = renderAlias id alias
81+ | mn == currentModule opts = T.unpack (renderAlias id alias)
78− | otherwise = renderAlias (\f -> P.showQualified f . P.Qualified mn) alias
82+ | otherwise = T.unpack (renderAlias (\f -> P.showQualified f . P.Qualified mn) alias)
79
83
80 renderAlias
84 renderAlias
81− :: (forall a. (a -> String) -> a -> String)
85+ :: (forall a. (a -> Text) -> a -> Text)
82 -> Either (P.ProperName 'P.TypeName) (Either P.Ident (P.ProperName 'P.ConstructorName))
86 -> Either (P.ProperName 'P.TypeName) (Either P.Ident (P.ProperName 'P.ConstructorName))
83− -> String
87+ -> Text
84 renderAlias f
88 renderAlias f
85− = either (("type " ++) . f P.runProperName)
89+ = either (("type " <>) . f P.runProperName)
86 $ either (f P.runIdent) (f P.runProperName)
90 $ either (f P.runIdent) (f P.runProperName)
87
91
88 -- adjustAliasName (P.AliasType{}) title = drop 6 (init title)
92 -- adjustAliasName (P.AliasType{}) title = drop 6 (init title)
@@ -133,7 +137,7 @@ renderConstraintsWithOptions opts constraints
133 (map (renderConstraintWithOptions opts) constraints)
137 (map (renderConstraintWithOptions opts) constraints)
134
138
135notQualified :: String -> P.Qualified (P.ProperName a)
139notQualified :: String -> P.Qualified (P.ProperName a)
136−notQualified = P.Qualified Nothing . P.ProperName
140+notQualified = P.Qualified Nothing . P.ProperName . T.pack
137
141
138typeApp :: String -> [(String, Maybe P.Kind)] -> P.Type
142typeApp :: String -> [(String, Maybe P.Kind)] -> P.Type
139typeApp title typeArgs =
143typeApp title typeArgs =
@@ -142,5 +146,5 @@ typeApp title typeArgs =
142 (map toTypeVar typeArgs)
146 (map toTypeVar typeArgs)
143
147
144toTypeVar :: (String, Maybe P.Kind) -> P.Type
148toTypeVar :: (String, Maybe P.Kind) -> P.Type
145−toTypeVar (s, Nothing) = P.TypeVar s
149+toTypeVar (s, Nothing) = P.TypeVar (T.pack s)
146−toTypeVar (s, Just k) = P.KindedType (P.TypeVar s) k
150+toTypeVar (s, Just k) = P.KindedType (P.TypeVar (T.pack s)) k
src/Language/PureScript/Docs/RenderedCode/Render.hs+11−7
@@ -14,8 +14,10 @@ import Prelude.Compat
14
14
15import Data.Maybe (fromMaybe)
15import Data.Maybe (fromMaybe)
16import Data.Monoid ((<>))
16import Data.Monoid ((<>))
17+import qualified Data.Text as T
18+import Data.Text (Text)
17
19
18−import Control.Arrow ((<+>))
20+import Control.Arrow ((<+>), first)
19import Control.PatternArrows as PA
21import Control.PatternArrows as PA
20
22
21import Language.PureScript.Crash
23import Language.PureScript.Crash
@@ -33,7 +35,7 @@ typeLiterals = mkPattern match
33 match TypeWildcard{} =
35 match TypeWildcard{} =
34 Just (syntax "_")
36 Just (syntax "_")
35 match (TypeVar var) =
37 match (TypeVar var) =
36− Just (ident var)
38+ Just (ident (T.unpack var))
37 match (PrettyPrintObject row) =
39 match (PrettyPrintObject row) =
38 Just $ mintersperse sp
40 Just $ mintersperse sp
39 [ syntax "{"
41 [ syntax "{"
@@ -41,7 +43,7 @@ typeLiterals = mkPattern match
41 , syntax "}"
43 , syntax "}"
42 ]
44 ]
43 match (TypeConstructor (Qualified mn name)) =
45 match (TypeConstructor (Qualified mn name)) =
44− Just (ctor (runProperName name) (maybeToContainingModule mn))
46+ Just (ctor (T.unpack (runProperName name)) (maybeToContainingModule mn))
45 match REmpty =
47 match REmpty =
46 Just (syntax "()")
48 Just (syntax "()")
47 match row@RCons{} =
49 match row@RCons{} =
@@ -49,7 +51,7 @@ typeLiterals = mkPattern match
49 match (BinaryNoParensType op l r) =
51 match (BinaryNoParensType op l r) =
50 Just $ renderTypeAtom l <> sp <> renderTypeAtom op <> sp <> renderTypeAtom r
52 Just $ renderTypeAtom l <> sp <> renderTypeAtom op <> sp <> renderTypeAtom r
51 match (TypeOp (Qualified mn op)) =
53 match (TypeOp (Qualified mn op)) =
52− Just (ident' (runOpName op) (maybeToContainingModule mn))
54+ Just (ident' (T.unpack (runOpName op)) (maybeToContainingModule mn))
53 match _ =
55 match _ =
54 Nothing
56 Nothing
55
57
@@ -74,8 +76,10 @@ renderConstraints deps ty =
74-- Render code representing a Row
76-- Render code representing a Row
75--
77--
76renderRow :: Type -> RenderedCode
78renderRow :: Type -> RenderedCode
77−renderRow = uncurry renderRow' . rowToList
79+renderRow = uncurry renderRow' . convertString . rowToList
78 where
80 where
81+ convertString :: ([(Text, Type)], Type) -> ([(String, Type)], Type)
82+ convertString = first (map (first T.unpack))
79 renderRow' h t = renderHead h <> renderTail t
83 renderRow' h t = renderHead h <> renderTail t
80
84
81renderHead :: [(String, Type)] -> RenderedCode
85renderHead :: [(String, Type)] -> RenderedCode
@@ -144,7 +148,7 @@ matchType = buildPrettyPrinter operators matchTypeAtom
144forall_ :: Pattern () Type ([String], Type)
148forall_ :: Pattern () Type ([String], Type)
145forall_ = mkPattern match
149forall_ = mkPattern match
146 where
150 where
147− match (PrettyPrintForAll idents ty) = Just (idents, ty)
151+ match (PrettyPrintForAll idents ty) = Just (map T.unpack idents, ty)
148 match _ = Nothing
152 match _ = Nothing
149
153
150insertPlaceholders :: RenderTypeOptions -> Type -> Type
154insertPlaceholders :: RenderTypeOptions -> Type -> Type
@@ -176,7 +180,7 @@ preprocessType opts = dePrim . insertPlaceholders opts
176-- Render code representing a Kind
180-- Render code representing a Kind
177--
181--
178renderKind :: Kind -> RenderedCode
182renderKind :: Kind -> RenderedCode
179−renderKind = kind . prettyPrintKind
183+renderKind = kind . T.unpack . prettyPrintKind
180
184
181-- |
185-- |
182-- Render code representing a Type, as it should appear inside parentheses
186-- Render code representing a Type, as it should appear inside parentheses
src/Language/PureScript/Docs/RenderedCode/Types.hs+2−2
@@ -1,5 +1,4 @@
1{-# LANGUAGE GeneralizedNewtypeDeriving #-}
1{-# LANGUAGE GeneralizedNewtypeDeriving #-}
2−{-# LANGUAGE OverloadedStrings #-}
3
2
4-- | Data types and functions for representing a simplified form of PureScript
3-- | Data types and functions for representing a simplified form of PureScript
5-- code, intended for use in e.g. HTML documentation.
4-- code, intended for use in e.g. HTML documentation.
@@ -38,6 +37,7 @@ import Control.Monad.Error.Class (MonadError(..))
38
37
39import Data.Aeson.BetterErrors
38import Data.Aeson.BetterErrors
40import qualified Data.Aeson as A
39import qualified Data.Aeson as A
40+import qualified Data.Text as T
41
41
42import qualified Language.PureScript as P
42import qualified Language.PureScript as P
43
43
@@ -103,7 +103,7 @@ instance A.ToJSON ContainingModule where
103
103
104asContainingModule :: Parse e ContainingModule
104asContainingModule :: Parse e ContainingModule
105asContainingModule =
105asContainingModule =
106− maybeToContainingModule <$> perhaps (P.moduleNameFromString <$> asString)
106+ maybeToContainingModule <$> perhaps (P.moduleNameFromString . T.pack <$> asString)
107
107
108-- |
108-- |
109-- Convert a 'Maybe' 'P.ModuleName' to a 'ContainingModule', using the obvious
109-- Convert a 'Maybe' 'P.ModuleName' to a 'ContainingModule', using the obvious
src/Language/PureScript/Docs/Types.hs+2−2
@@ -352,7 +352,7 @@ parseVersion' str =
352
352
353asModule :: Parse PackageError Module
353asModule :: Parse PackageError Module
354asModule =
354asModule =
355− Module <$> key "name" (P.moduleNameFromString <$> asString)
355+ Module <$> key "name" (P.moduleNameFromString <$> asText)
356 <*> key "comments" (perhaps asString)
356 <*> key "comments" (perhaps asString)
357 <*> key "declarations" (eachInArray asDeclaration)
357 <*> key "declarations" (eachInArray asDeclaration)
358 <*> key "reExports" (eachInArray asReExport)
358 <*> key "reExports" (eachInArray asReExport)
@@ -478,7 +478,7 @@ asBookmarks = eachInArray asBookmark
478
478
479asBookmark :: Parse BowerError Bookmark
479asBookmark :: Parse BowerError Bookmark
480asBookmark =
480asBookmark =
481− asInPackage ((,) <$> nth 0 (P.moduleNameFromString <$> asString)
481+ asInPackage ((,) <$> nth 0 (P.moduleNameFromString <$> asText)
482 <*> nth 1 asString)
482 <*> nth 1 asString)
483
483
484asResolvedDependencies :: Parse PackageError [(PackageName, Version)]
484asResolvedDependencies :: Parse PackageError [(PackageName, Version)]
src/Language/PureScript/Environment.hs+8−8
@@ -1,4 +1,3 @@
1−{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE TemplateHaskell #-}
1{-# LANGUAGE TemplateHaskell #-}
3
2
4module Language.PureScript.Environment where
3module Language.PureScript.Environment where
@@ -6,9 +5,10 @@ module Language.PureScript.Environment where
6import Prelude.Compat
5import Prelude.Compat
7
6
8import Data.Aeson.TH
7import Data.Aeson.TH
9−import Data.Maybe (fromMaybe)
10import qualified Data.Aeson as A
8import qualified Data.Aeson as A
11import qualified Data.Map as M
9import qualified Data.Map as M
10+import Data.Maybe (fromMaybe)
11+import Data.Text (Text)
12import qualified Data.Text as T
12import qualified Data.Text as T
13
13
14import Language.PureScript.Crash
14import Language.PureScript.Crash
@@ -27,7 +27,7 @@ data Environment = Environment
27 , dataConstructors :: M.Map (Qualified (ProperName 'ConstructorName)) (DataDeclType, ProperName 'TypeName, Type, [Ident])
27 , dataConstructors :: M.Map (Qualified (ProperName 'ConstructorName)) (DataDeclType, ProperName 'TypeName, Type, [Ident])
28 -- ^ Data constructors currently in scope, along with their associated type
28 -- ^ Data constructors currently in scope, along with their associated type
29 -- constructor name, argument types and return type.
29 -- constructor name, argument types and return type.
30− , typeSynonyms :: M.Map (Qualified (ProperName 'TypeName)) ([(String, Maybe Kind)], Type)
30+ , typeSynonyms :: M.Map (Qualified (ProperName 'TypeName)) ([(Text, Maybe Kind)], Type)
31 -- ^ Type synonyms currently in scope
31 -- ^ Type synonyms currently in scope
32 , typeClassDictionaries :: M.Map (Maybe ModuleName) (M.Map (Qualified (ProperName 'ClassName)) (M.Map (Qualified Ident) NamedDict))
32 , typeClassDictionaries :: M.Map (Maybe ModuleName) (M.Map (Qualified (ProperName 'ClassName)) (M.Map (Qualified Ident) NamedDict))
33 -- ^ Available type class dictionaries
33 -- ^ Available type class dictionaries
@@ -37,7 +37,7 @@ data Environment = Environment
37
37
38-- | Information about a type class
38-- | Information about a type class
39data TypeClassData = TypeClassData
39data TypeClassData = TypeClassData
40− { typeClassArguments :: [(String, Maybe Kind)]
40+ { typeClassArguments :: [(Text, Maybe Kind)]
41 -- ^ A list of type argument names, and their kinds, where kind annotations
41 -- ^ A list of type argument names, and their kinds, where kind annotations
42 -- were provided.
42 -- were provided.
43 , typeClassMembers :: [(Ident, Type)]
43 , typeClassMembers :: [(Ident, Type)]
@@ -105,7 +105,7 @@ data TypeKind
105 -- |
105 -- |
106 -- Data type
106 -- Data type
107 --
107 --
108− = DataType [(String, Maybe Kind)] [(ProperName 'ConstructorName, [Type])]
108+ = DataType [(Text, Maybe Kind)] [(ProperName 'ConstructorName, [Type])]
109 -- |
109 -- |
110 -- Type synonym
110 -- Type synonym
111 --
111 --
@@ -138,7 +138,7 @@ data DataDeclType
138 | Newtype
138 | Newtype
139 deriving (Show, Eq, Ord)
139 deriving (Show, Eq, Ord)
140
140
141−showDataDeclType :: DataDeclType -> String
141+showDataDeclType :: DataDeclType -> Text
142showDataDeclType Data = "data"
142showDataDeclType Data = "data"
143showDataDeclType Newtype = "newtype"
143showDataDeclType Newtype = "newtype"
144
144
@@ -155,13 +155,13 @@ instance A.FromJSON DataDeclType where
155-- |
155-- |
156-- Construct a ProperName in the Prim module
156-- Construct a ProperName in the Prim module
157--
157--
158−primName :: String -> Qualified (ProperName a)
158+primName :: Text -> Qualified (ProperName a)
159primName = Qualified (Just $ ModuleName [ProperName C.prim]) . ProperName
159primName = Qualified (Just $ ModuleName [ProperName C.prim]) . ProperName
160
160
161-- |
161-- |
162-- Construct a type in the Prim module
162-- Construct a type in the Prim module
163--
163--
164−primTy :: String -> Type
164+primTy :: Text -> Type
165primTy = TypeConstructor . primName
165primTy = TypeConstructor . primName
166
166
167-- |
167-- |
src/Language/PureScript/Errors.hs+144−139
@@ -18,10 +18,12 @@ import Data.Char (isSpace)
18import Data.Either (lefts, rights)
18import Data.Either (lefts, rights)
19import Data.Foldable (fold)
19import Data.Foldable (fold)
20import Data.Functor.Identity (Identity(..))
20import Data.Functor.Identity (Identity(..))
21−import Data.List (intercalate, transpose, nub, nubBy, sortBy, partition)
21+import Data.List (transpose, nub, nubBy, sortBy, partition)
22import Data.Maybe (maybeToList, fromMaybe, mapMaybe)
22import Data.Maybe (maybeToList, fromMaybe, mapMaybe)
23import Data.Ord (comparing)
23import Data.Ord (comparing)
24import qualified Data.Map as M
24import qualified Data.Map as M
25+import qualified Data.Text as T
26+import Data.Text (Text)
25
27
26import Language.PureScript.AST
28import Language.PureScript.AST
27import Language.PureScript.Crash
29import Language.PureScript.Crash
@@ -43,7 +45,7 @@ import qualified Text.PrettyPrint.Boxes as Box
43import qualified Language.PureScript.Publish.BoxesHelpers as BoxHelpers
45import qualified Language.PureScript.Publish.BoxesHelpers as BoxHelpers
44import Text.Parsec.Error (Message(..))
46import Text.Parsec.Error (Message(..))
45
47
46−newtype ErrorSuggestion = ErrorSuggestion String
48+newtype ErrorSuggestion = ErrorSuggestion Text
47
49
48-- | Get the source span for an error
50-- | Get the source span for an error
49errorSpan :: ErrorMessage -> Maybe SourceSpan
51errorSpan :: ErrorMessage -> Maybe SourceSpan
@@ -73,7 +75,7 @@ stripModuleAndSpan (ErrorMessage hints e) = ErrorMessage (filter (not . shouldSt
73-- |
75-- |
74-- Get the error code for a particular error type
76-- Get the error code for a particular error type
75--
77--
76−errorCode :: ErrorMessage -> String
78+errorCode :: ErrorMessage -> Text
77errorCode em = case unwrapErrorMessage em of
79errorCode em = case unwrapErrorMessage em of
78 ErrorParsingFFIModule{} -> "ErrorParsingFFIModule"
80 ErrorParsingFFIModule{} -> "ErrorParsingFFIModule"
79 ErrorParsingModule{} -> "ErrorParsingModule"
81 ErrorParsingModule{} -> "ErrorParsingModule"
@@ -245,7 +247,7 @@ replaceUnknowns = everywhereOnTypesM replaceTypes
245 case M.lookup s (umSkolemMap m) of
247 case M.lookup s (umSkolemMap m) of
246 Nothing -> do
248 Nothing -> do
247 let s' = umNextIndex m
249 let s' = umNextIndex m
248− put $ m { umSkolemMap = M.insert s (name, s', ss) (umSkolemMap m), umNextIndex = s' + 1 }
250+ put $ m { umSkolemMap = M.insert s (T.unpack name, s', ss) (umSkolemMap m), umNextIndex = s' + 1 }
249 return (Skolem name s' sko ss)
251 return (Skolem name s' sko ss)
250 Just (_, s', _) -> return (Skolem name s' sko ss)
252 Just (_, s', _) -> return (Skolem name s' sko ss)
251 replaceTypes other = return other
253 replaceTypes other = return other
@@ -287,8 +289,8 @@ onTypesInErrorMessageM f (ErrorMessage hints simple) = ErrorMessage <$> traverse
287 gTypeSearch (TSBefore env) = pure (TSBefore env)
289 gTypeSearch (TSBefore env) = pure (TSBefore env)
288 gTypeSearch (TSAfter result) = TSAfter <$> traverse (traverse f) result
290 gTypeSearch (TSAfter result) = TSAfter <$> traverse (traverse f) result
289
291
290−wikiUri :: ErrorMessage -> String
292+wikiUri :: ErrorMessage -> Text
291−wikiUri e = "https://github.com/purescript/purescript/wiki/Error-Code-" ++ errorCode e
293+wikiUri e = "https://github.com/purescript/purescript/wiki/Error-Code-" <> errorCode e
292
294
293-- TODO Other possible suggestions:
295-- TODO Other possible suggestions:
294-- WildcardInferredType - source span not small enough
296-- WildcardInferredType - source span not small enough
@@ -304,19 +306,19 @@ errorSuggestion err =
304 ImplicitImport mn refs -> suggest $ importSuggestion mn refs Nothing
306 ImplicitImport mn refs -> suggest $ importSuggestion mn refs Nothing
305 ImplicitQualifiedImport mn asModule refs -> suggest $ importSuggestion mn refs (Just asModule)
307 ImplicitQualifiedImport mn asModule refs -> suggest $ importSuggestion mn refs (Just asModule)
306 HidingImport mn refs -> suggest $ importSuggestion mn refs Nothing
308 HidingImport mn refs -> suggest $ importSuggestion mn refs Nothing
307− MissingTypeDeclaration ident ty -> suggest $ showIdent ident ++ " :: " ++ prettyPrintSuggestedType ty
309+ MissingTypeDeclaration ident ty -> suggest $ showIdent ident <> " :: " <> T.pack (prettyPrintSuggestedType ty)
308− WildcardInferredType ty _ -> suggest $ prettyPrintSuggestedType ty
310+ WildcardInferredType ty _ -> suggest $ T.pack (prettyPrintSuggestedType ty)
309 _ -> Nothing
311 _ -> Nothing
310 where
312 where
311 emptySuggestion = Just $ ErrorSuggestion ""
313 emptySuggestion = Just $ ErrorSuggestion ""
312 suggest = Just . ErrorSuggestion
314 suggest = Just . ErrorSuggestion
313
315
314− importSuggestion :: ModuleName -> [ DeclarationRef ] -> Maybe ModuleName -> String
316+ importSuggestion :: ModuleName -> [ DeclarationRef ] -> Maybe ModuleName -> Text
315 importSuggestion mn refs qual =
317 importSuggestion mn refs qual =
316− "import " ++ runModuleName mn ++ " (" ++ intercalate ", " (mapMaybe prettyPrintRef refs) ++ ")" ++ qstr qual
318+ "import " <> runModuleName mn <> " (" <> T.intercalate ", " (mapMaybe prettyPrintRef refs) <> ")" <> qstr qual
317
319
318− qstr :: Maybe ModuleName -> String
320+ qstr :: Maybe ModuleName -> Text
319− qstr (Just mn) = " as " ++ runModuleName mn
321+ qstr (Just mn) = " as " <> runModuleName mn
320 qstr Nothing = ""
322 qstr Nothing = ""
321
323
322suggestionSpan :: ErrorMessage -> Maybe SourceSpan
324suggestionSpan :: ErrorMessage -> Maybe SourceSpan
@@ -330,7 +332,7 @@ suggestionSpan e =
330 MissingTypeDeclaration{} -> startOnly ss
332 MissingTypeDeclaration{} -> startOnly ss
331 _ -> ss
333 _ -> ss
332
334
333−showSuggestion :: SimpleErrorMessage -> String
335+showSuggestion :: SimpleErrorMessage -> Text
334showSuggestion suggestion = case errorSuggestion suggestion of
336showSuggestion suggestion = case errorSuggestion suggestion of
335 Just (ErrorSuggestion x) -> x
337 Just (ErrorSuggestion x) -> x
336 _ -> ""
338 _ -> ""
@@ -343,10 +345,10 @@ ansiColorReset :: String
343ansiColorReset =
345ansiColorReset =
344 ANSI.setSGRCode [ANSI.Reset]
346 ANSI.setSGRCode [ANSI.Reset]
345
347
346−colorCode :: Maybe (ANSI.ColorIntensity, ANSI.Color) -> String -> String
348+colorCode :: Maybe (ANSI.ColorIntensity, ANSI.Color) -> Text -> Text
347colorCode codeColor code = case codeColor of
349colorCode codeColor code = case codeColor of
348 Nothing -> code
350 Nothing -> code
349− Just cc -> concat [ansiColor cc, code, ansiColorReset]
351+ Just cc -> T.pack (ansiColor cc) <> code <> T.pack ansiColorReset
350
352
351colorCodeBox :: Maybe (ANSI.ColorIntensity, ANSI.Color) -> Box.Box -> Box.Box
353colorCodeBox :: Maybe (ANSI.ColorIntensity, ANSI.Color) -> Box.Box -> Box.Box
352colorCodeBox codeColor b = case codeColor of
354colorCodeBox codeColor b = case codeColor of
@@ -403,8 +405,8 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
403 ] ++
405 ] ++
404 maybe [] (return . Box.moveDown 1) typeInformation ++
406 maybe [] (return . Box.moveDown 1) typeInformation ++
405 [ Box.moveDown 1 $ paras
407 [ Box.moveDown 1 $ paras
406− [ line $ "See " ++ wikiUri e ++ " for more information, "
408+ [ line $ "See " <> wikiUri e <> " for more information, "
407− , line $ "or to contribute content related to this " ++ levelText ++ "."
409+ , line $ "or to contribute content related to this " <> levelText <> "."
408 ]
410 ]
409 | showWiki
411 | showWiki
410 ]
412 ]
@@ -420,59 +422,59 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
420 skolemInfo :: (String, Int, Maybe SourceSpan) -> Box.Box
422 skolemInfo :: (String, Int, Maybe SourceSpan) -> Box.Box
421 skolemInfo (name, s, ss) =
423 skolemInfo (name, s, ss) =
422 paras $
424 paras $
423− line (markCode (name ++ show s) ++ " is a rigid type variable")
425+ line (markCode (T.pack (name <> show s)) <> " is a rigid type variable")
424− : foldMap (return . line . (" bound at " ++) . displayStartEndPos) ss
426+ : foldMap (return . line . (" bound at " <>) . displayStartEndPos) ss
425
427
426 unknownInfo :: Int -> Box.Box
428 unknownInfo :: Int -> Box.Box
427− unknownInfo u = line $ markCode ("t" ++ show u) ++ " is an unknown type"
429+ unknownInfo u = line $ markCode ("t" <> T.pack (show u)) <> " is an unknown type"
428
430
429 renderSimpleErrorMessage :: SimpleErrorMessage -> Box.Box
431 renderSimpleErrorMessage :: SimpleErrorMessage -> Box.Box
430 renderSimpleErrorMessage (CannotGetFileInfo path) =
432 renderSimpleErrorMessage (CannotGetFileInfo path) =
431 paras [ line "Unable to read file info: "
433 paras [ line "Unable to read file info: "
432− , indent . line $ path
434+ , indent . lineS $ path
433 ]
435 ]
434 renderSimpleErrorMessage (CannotReadFile path) =
436 renderSimpleErrorMessage (CannotReadFile path) =
435 paras [ line "Unable to read file: "
437 paras [ line "Unable to read file: "
436− , indent . line $ path
438+ , indent . lineS $ path
437 ]
439 ]
438 renderSimpleErrorMessage (CannotWriteFile path) =
440 renderSimpleErrorMessage (CannotWriteFile path) =
439 paras [ line "Unable to write file: "
441 paras [ line "Unable to write file: "
440− , indent . line $ path
442+ , indent . lineS $ path
441 ]
443 ]
442 renderSimpleErrorMessage (ErrorParsingFFIModule path extra) =
444 renderSimpleErrorMessage (ErrorParsingFFIModule path extra) =
443 paras $ [ line "Unable to parse foreign module:"
445 paras $ [ line "Unable to parse foreign module:"
444− , indent . line $ path
446+ , indent . lineS $ path
445 ] ++
447 ] ++
446− map (indent . line) (concatMap Bundle.printErrorMessage (maybeToList extra))
448+ map (indent . lineS) (concatMap Bundle.printErrorMessage (maybeToList extra))
447 renderSimpleErrorMessage (ErrorParsingModule err) =
449 renderSimpleErrorMessage (ErrorParsingModule err) =
448 paras [ line "Unable to parse module: "
450 paras [ line "Unable to parse module: "
449 , prettyPrintParseError err
451 , prettyPrintParseError err
450 ]
452 ]
451 renderSimpleErrorMessage (MissingFFIModule mn) =
453 renderSimpleErrorMessage (MissingFFIModule mn) =
452− line $ "The foreign module implementation for module " ++ markCode (runModuleName mn) ++ " is missing."
454+ line $ "The foreign module implementation for module " <> markCode (runModuleName mn) <> " is missing."
453 renderSimpleErrorMessage (UnnecessaryFFIModule mn path) =
455 renderSimpleErrorMessage (UnnecessaryFFIModule mn path) =
454− paras [ line $ "An unnecessary foreign module implementation was provided for module " ++ markCode (runModuleName mn) ++ ": "
456+ paras [ line $ "An unnecessary foreign module implementation was provided for module " <> markCode (runModuleName mn) <> ": "
455− , indent . line $ path
457+ , indent . lineS $ path
456− , line $ "Module " ++ markCode (runModuleName mn) ++ " does not contain any foreign import declarations, so a foreign module is not necessary."
458+ , line $ "Module " <> markCode (runModuleName mn) <> " does not contain any foreign import declarations, so a foreign module is not necessary."
457 ]
459 ]
458 renderSimpleErrorMessage (MissingFFIImplementations mn idents) =
460 renderSimpleErrorMessage (MissingFFIImplementations mn idents) =
459− paras [ line $ "The following values are not defined in the foreign module for module " ++ markCode (runModuleName mn) ++ ": "
461+ paras [ line $ "The following values are not defined in the foreign module for module " <> markCode (runModuleName mn) <> ": "
460 , indent . paras $ map (line . runIdent) idents
462 , indent . paras $ map (line . runIdent) idents
461 ]
463 ]
462 renderSimpleErrorMessage (UnusedFFIImplementations mn idents) =
464 renderSimpleErrorMessage (UnusedFFIImplementations mn idents) =
463− paras [ line $ "The following definitions in the foreign module for module " ++ markCode (runModuleName mn) ++ " are unused: "
465+ paras [ line $ "The following definitions in the foreign module for module " <> markCode (runModuleName mn) <> " are unused: "
464 , indent . paras $ map (line . runIdent) idents
466 , indent . paras $ map (line . runIdent) idents
465 ]
467 ]
466 renderSimpleErrorMessage (InvalidFFIIdentifier mn ident) =
468 renderSimpleErrorMessage (InvalidFFIIdentifier mn ident) =
467− paras [ line $ "In the FFI module for " ++ markCode (runModuleName mn) ++ ":"
469+ paras [ line $ "In the FFI module for " <> markCode (runModuleName mn) <> ":"
468 , indent . paras $
470 , indent . paras $
469− [ line $ "The identifier " ++ markCode ident ++ " is not valid in PureScript."
471+ [ line $ "The identifier " <> markCode ident <> " is not valid in PureScript."
470 , line "Note that exported identifiers in FFI modules must be valid PureScript identifiers."
472 , line "Note that exported identifiers in FFI modules must be valid PureScript identifiers."
471 ]
473 ]
472 ]
474 ]
473 renderSimpleErrorMessage (MultipleFFIModules mn paths) =
475 renderSimpleErrorMessage (MultipleFFIModules mn paths) =
474− paras [ line $ "Multiple foreign module implementations have been provided for module " ++ markCode (runModuleName mn) ++ ": "
476+ paras [ line $ "Multiple foreign module implementations have been provided for module " <> markCode (runModuleName mn) <> ": "
475− , indent . paras $ map line paths
477+ , indent . paras $ map lineS paths
476 ]
478 ]
477 renderSimpleErrorMessage InvalidDoBind =
479 renderSimpleErrorMessage InvalidDoBind =
478 line "The last statement in a 'do' block must be an expression, but this block ends with a binder."
480 line "The last statement in a 'do' block must be an expression, but this block ends with a binder."
@@ -489,63 +491,63 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
489 , indent $ line $ markCode $ prettyPrintKind ki
491 , indent $ line $ markCode $ prettyPrintKind ki
490 ]
492 ]
491 renderSimpleErrorMessage (MultipleValueOpFixities op) =
493 renderSimpleErrorMessage (MultipleValueOpFixities op) =
492− line $ "There are multiple fixity/precedence declarations for operator " ++ markCode (showOp op)
494+ line $ "There are multiple fixity/precedence declarations for operator " <> markCode (showOp op)
493 renderSimpleErrorMessage (MultipleTypeOpFixities op) =
495 renderSimpleErrorMessage (MultipleTypeOpFixities op) =
494− line $ "There are multiple fixity/precedence declarations for type operator " ++ markCode (showOp op)
496+ line $ "There are multiple fixity/precedence declarations for type operator " <> markCode (showOp op)
495 renderSimpleErrorMessage (OrphanTypeDeclaration nm) =
497 renderSimpleErrorMessage (OrphanTypeDeclaration nm) =
496− line $ "The type declaration for " ++ markCode (showIdent nm) ++ " should be followed by its definition."
498+ line $ "The type declaration for " <> markCode (showIdent nm) <> " should be followed by its definition."
497 renderSimpleErrorMessage (RedefinedIdent name) =
499 renderSimpleErrorMessage (RedefinedIdent name) =
498− line $ "The value " ++ markCode (showIdent name) ++ " has been defined multiple times"
500+ line $ "The value " <> markCode (showIdent name) <> " has been defined multiple times"
499 renderSimpleErrorMessage (UnknownName name) =
501 renderSimpleErrorMessage (UnknownName name) =
500− line $ "Unknown " ++ printName name
502+ line $ "Unknown " <> printName name
501 renderSimpleErrorMessage (UnknownImport mn name) =
503 renderSimpleErrorMessage (UnknownImport mn name) =
502− paras [ line $ "Cannot import " ++ printName (Qualified Nothing name) ++ " from module " ++ markCode (runModuleName mn)
504+ paras [ line $ "Cannot import " <> printName (Qualified Nothing name) <> " from module " <> markCode (runModuleName mn)
503 , line "It either does not exist or the module does not export it."
505 , line "It either does not exist or the module does not export it."
504 ]
506 ]
505 renderSimpleErrorMessage (UnknownImportDataConstructor mn tcon dcon) =
507 renderSimpleErrorMessage (UnknownImportDataConstructor mn tcon dcon) =
506− line $ "Module " ++ runModuleName mn ++ " does not export data constructor " ++ markCode (runProperName dcon) ++ " for type " ++ markCode (runProperName tcon)
508+ line $ "Module " <> runModuleName mn <> " does not export data constructor " <> markCode (runProperName dcon) <> " for type " <> markCode (runProperName tcon)
507 renderSimpleErrorMessage (UnknownExport name) =
509 renderSimpleErrorMessage (UnknownExport name) =
508− line $ "Cannot export unknown " ++ printName (Qualified Nothing name)
510+ line $ "Cannot export unknown " <> printName (Qualified Nothing name)
509 renderSimpleErrorMessage (UnknownExportDataConstructor tcon dcon) =
511 renderSimpleErrorMessage (UnknownExportDataConstructor tcon dcon) =
510− line $ "Cannot export data constructor " ++ markCode (runProperName dcon) ++ " for type " ++ markCode (runProperName tcon) ++ ", as it has not been declared."
512+ line $ "Cannot export data constructor " <> markCode (runProperName dcon) <> " for type " <> markCode (runProperName tcon) <> ", as it has not been declared."
511 renderSimpleErrorMessage (ScopeConflict nm ms) =
513 renderSimpleErrorMessage (ScopeConflict nm ms) =
512− paras [ line $ "Conflicting definitions are in scope for " ++ printName (Qualified Nothing nm) ++ " from the following modules:"
514+ paras [ line $ "Conflicting definitions are in scope for " <> printName (Qualified Nothing nm) <> " from the following modules:"
513 , indent $ paras $ map (line . markCode . runModuleName) ms
515 , indent $ paras $ map (line . markCode . runModuleName) ms
514 ]
516 ]
515 renderSimpleErrorMessage (ScopeShadowing nm exmn ms) =
517 renderSimpleErrorMessage (ScopeShadowing nm exmn ms) =
516− paras [ line $ "Shadowed definitions are in scope for " ++ printName (Qualified Nothing nm) ++ " from the following open imports:"
518+ paras [ line $ "Shadowed definitions are in scope for " <> printName (Qualified Nothing nm) <> " from the following open imports:"
517− , indent $ paras $ map (line . markCode . ("import " ++) . runModuleName) ms
519+ , indent $ paras $ map (line . markCode . ("import " <>) . runModuleName) ms
518− , line $ "These will be ignored and the " ++ case exmn of
520+ , line $ "These will be ignored and the " <> case exmn of
519− Just exmn' -> "declaration from " ++ markCode (runModuleName exmn') ++ " will be used."
521+ Just exmn' -> "declaration from " <> markCode (runModuleName exmn') <> " will be used."
520 Nothing -> "local declaration will be used."
522 Nothing -> "local declaration will be used."
521 ]
523 ]
522 renderSimpleErrorMessage (DeclConflict new existing) =
524 renderSimpleErrorMessage (DeclConflict new existing) =
523− line $ "Declaration for " ++ printName (Qualified Nothing new) ++ " conflicts with an existing " ++ nameType existing ++ " of the same name."
525+ line $ "Declaration for " <> printName (Qualified Nothing new) <> " conflicts with an existing " <> nameType existing <> " of the same name."
524 renderSimpleErrorMessage (ExportConflict new existing) =
526 renderSimpleErrorMessage (ExportConflict new existing) =
525− line $ "Export for " ++ printName new ++ " conflicts with " ++ runName existing
527+ line $ "Export for " <> printName new <> " conflicts with " <> runName existing
526 renderSimpleErrorMessage (DuplicateModule mn ss) =
528 renderSimpleErrorMessage (DuplicateModule mn ss) =
527− paras [ line ("Module " ++ markCode (runModuleName mn) ++ " has been defined multiple times:")
529+ paras [ line ("Module " <> markCode (runModuleName mn) <> " has been defined multiple times:")
528 , indent . paras $ map (line . displaySourceSpan) ss
530 , indent . paras $ map (line . displaySourceSpan) ss
529 ]
531 ]
530 renderSimpleErrorMessage (CycleInDeclaration nm) =
532 renderSimpleErrorMessage (CycleInDeclaration nm) =
531− line $ "The value of " ++ markCode (showIdent nm) ++ " is undefined here, so this reference is not allowed."
533+ line $ "The value of " <> markCode (showIdent nm) <> " is undefined here, so this reference is not allowed."
532 renderSimpleErrorMessage (CycleInModules mns) =
534 renderSimpleErrorMessage (CycleInModules mns) =
533 paras [ line "There is a cycle in module dependencies in these modules: "
535 paras [ line "There is a cycle in module dependencies in these modules: "
534 , indent $ paras (map (line . markCode . runModuleName) mns)
536 , indent $ paras (map (line . markCode . runModuleName) mns)
535 ]
537 ]
536 renderSimpleErrorMessage (CycleInTypeSynonym name) =
538 renderSimpleErrorMessage (CycleInTypeSynonym name) =
537 paras [ line $ case name of
539 paras [ line $ case name of
538− Just pn -> "A cycle appears in the definition of type synonym " ++ markCode (runProperName pn)
540+ Just pn -> "A cycle appears in the definition of type synonym " <> markCode (runProperName pn)
539 Nothing -> "A cycle appears in a set of type synonym definitions."
541 Nothing -> "A cycle appears in a set of type synonym definitions."
540 , line "Cycles are disallowed because they can lead to loops in the type checker."
542 , line "Cycles are disallowed because they can lead to loops in the type checker."
541 , line "Consider using a 'newtype' instead."
543 , line "Consider using a 'newtype' instead."
542 ]
544 ]
543 renderSimpleErrorMessage (NameIsUndefined ident) =
545 renderSimpleErrorMessage (NameIsUndefined ident) =
544− line $ "Value " ++ markCode (showIdent ident) ++ " is undefined."
546+ line $ "Value " <> markCode (showIdent ident) <> " is undefined."
545 renderSimpleErrorMessage (UndefinedTypeVariable name) =
547 renderSimpleErrorMessage (UndefinedTypeVariable name) =
546− line $ "Type variable " ++ markCode (runProperName name) ++ " is undefined."
548+ line $ "Type variable " <> markCode (runProperName name) <> " is undefined."
547 renderSimpleErrorMessage (PartiallyAppliedSynonym name) =
549 renderSimpleErrorMessage (PartiallyAppliedSynonym name) =
548− paras [ line $ "Type synonym " ++ markCode (showQualified runProperName name) ++ " is partially applied."
550+ paras [ line $ "Type synonym " <> markCode (showQualified runProperName name) <> " is partially applied."
549 , line "Type synonyms must be applied to all of their type arguments."
551 , line "Type synonyms must be applied to all of their type arguments."
550 ]
552 ]
551 renderSimpleErrorMessage (EscapedSkolem binding) =
553 renderSimpleErrorMessage (EscapedSkolem binding) =
@@ -561,12 +563,12 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
561 sortRows t1 t2 = (t1, t2)
563 sortRows t1 t2 = (t1, t2)
562
564
563 -- Put the common labels last
565 -- Put the common labels last
564− sortRows' :: ([(String, Type)], Type) -> ([(String, Type)], Type) -> (Type, Type)
566+ sortRows' :: ([(Text, Type)], Type) -> ([(Text, Type)], Type) -> (Type, Type)
565 sortRows' (s1, r1) (s2, r2) =
567 sortRows' (s1, r1) (s2, r2) =
566− let common :: [(String, (Type, Type))]
568+ let common :: [(Text, (Type, Type))]
567 common = sortBy (comparing fst) [ (name, (t1, t2)) | (name, t1) <- s1, (name', t2) <- s2, name == name' ]
569 common = sortBy (comparing fst) [ (name, (t1, t2)) | (name, t1) <- s1, (name', t2) <- s2, name == name' ]
568
570
569− sd1, sd2 :: [(String, Type)]
571+ sd1, sd2 :: [(Text, Type)]
570 sd1 = [ (name, t1) | (name, t1) <- s1, name `notElem` map fst s2 ]
572 sd1 = [ (name, t1) | (name, t1) <- s1, name `notElem` map fst s2 ]
571 sd2 = [ (name, t2) | (name, t2) <- s2, name `notElem` map fst s1 ]
573 sd2 = [ (name, t2) | (name, t2) <- s2, name `notElem` map fst s1 ]
572 in ( rowFromList (sortBy (comparing fst) sd1 ++ map (fst &&& fst . snd) common, r1)
574 in ( rowFromList (sortBy (comparing fst) sd1 ++ map (fst &&& fst . snd) common, r1)
@@ -597,7 +599,7 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
597 , Box.vcat Box.left (map typeAtomAsBox ts)
599 , Box.vcat Box.left (map typeAtomAsBox ts)
598 ]
600 ]
599 , line "The following instances were found:"
601 , line "The following instances were found:"
600− , indent $ paras (line (showQualified showIdent d ++ " (chosen)") : map (line . showQualified showIdent) ds)
602+ , indent $ paras (line (showQualified showIdent d <> " (chosen)") : map (line . showQualified showIdent) ds)
601 , line "Overlapping type class instances can lead to different behavior based on the order of module imports, and for that reason are not recommended."
603 , line "Overlapping type class instances can lead to different behavior based on the order of module imports, and for that reason are not recommended."
602 , line "They may be disallowed completely in a future version of the compiler."
604 , line "They may be disallowed completely in a future version of the compiler."
603 ]
605 ]
@@ -667,26 +669,26 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
667 , line "Make sure this is a newtype."
669 , line "Make sure this is a newtype."
668 ]
670 ]
669 renderSimpleErrorMessage (CannotFindDerivingType nm) =
671 renderSimpleErrorMessage (CannotFindDerivingType nm) =
670− line $ "Cannot derive a type class instance, because the type declaration for " ++ markCode (runProperName nm) ++ " could not be found."
672+ line $ "Cannot derive a type class instance, because the type declaration for " <> markCode (runProperName nm) <> " could not be found."
671 renderSimpleErrorMessage (DuplicateLabel l expr) =
673 renderSimpleErrorMessage (DuplicateLabel l expr) =
672− paras $ [ line $ "Label " ++ markCode l ++ " appears more than once in a row type." ]
674+ paras $ [ line $ "Label " <> markCode l <> " appears more than once in a row type." ]
673 <> foldMap (\expr' -> [ line "Relevant expression: "
675 <> foldMap (\expr' -> [ line "Relevant expression: "
674 , markCodeBox $ indent $ prettyPrintValue valueDepth expr'
676 , markCodeBox $ indent $ prettyPrintValue valueDepth expr'
675 ]) expr
677 ]) expr
676 renderSimpleErrorMessage (DuplicateTypeArgument name) =
678 renderSimpleErrorMessage (DuplicateTypeArgument name) =
677− line $ "Type argument " ++ markCode name ++ " appears more than once."
679+ line $ "Type argument " <> markCode name <> " appears more than once."
678 renderSimpleErrorMessage (DuplicateValueDeclaration nm) =
680 renderSimpleErrorMessage (DuplicateValueDeclaration nm) =
679− line $ "Multiple value declarations exist for " ++ markCode (showIdent nm) ++ "."
681+ line $ "Multiple value declarations exist for " <> markCode (showIdent nm) <> "."
680 renderSimpleErrorMessage (ArgListLengthsDiffer ident) =
682 renderSimpleErrorMessage (ArgListLengthsDiffer ident) =
681− line $ "Argument list lengths differ in declaration " ++ markCode (showIdent ident)
683+ line $ "Argument list lengths differ in declaration " <> markCode (showIdent ident)
682 renderSimpleErrorMessage (OverlappingArgNames ident) =
684 renderSimpleErrorMessage (OverlappingArgNames ident) =
683− line $ "Overlapping names in function/binder" ++ foldMap ((" in declaration " ++) . showIdent) ident
685+ line $ "Overlapping names in function/binder" <> foldMap ((" in declaration " <>) . showIdent) ident
684 renderSimpleErrorMessage (MissingClassMember ident) =
686 renderSimpleErrorMessage (MissingClassMember ident) =
685− line $ "Type class member " ++ markCode (showIdent ident) ++ " has not been implemented."
687+ line $ "Type class member " <> markCode (showIdent ident) <> " has not been implemented."
686 renderSimpleErrorMessage (ExtraneousClassMember ident className) =
688 renderSimpleErrorMessage (ExtraneousClassMember ident className) =
687− line $ "" ++ markCode (showIdent ident) ++ " is not a member of type class " ++ markCode (showQualified runProperName className)
689+ line $ "" <> markCode (showIdent ident) <> " is not a member of type class " <> markCode (showQualified runProperName className)
688 renderSimpleErrorMessage (ExpectedType ty kind) =
690 renderSimpleErrorMessage (ExpectedType ty kind) =
689− paras [ line $ "In a type-annotated expression " ++ markCode "x :: t" ++ ", the type " ++ markCode "t" ++ " must have kind " ++ markCode "*" ++ "."
691+ paras [ line $ "In a type-annotated expression " <> markCode "x :: t" <> ", the type " <> markCode "t" <> " must have kind " <> markCode "*" <> "."
690 , line "The error arises from the type"
692 , line "The error arises from the type"
691 , markCodeBox $ indent $ typeAsBox ty
693 , markCodeBox $ indent $ typeAsBox ty
692 , line "having the kind"
694 , line "having the kind"
@@ -694,7 +696,7 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
694 , line "instead."
696 , line "instead."
695 ]
697 ]
696 renderSimpleErrorMessage (IncorrectConstructorArity nm) =
698 renderSimpleErrorMessage (IncorrectConstructorArity nm) =
697− line $ "Data constructor " ++ markCode (showQualified runProperName nm) ++ " was given the wrong number of arguments in a case expression."
699+ line $ "Data constructor " <> markCode (showQualified runProperName nm) <> " was given the wrong number of arguments in a case expression."
698 renderSimpleErrorMessage (ExprDoesNotHaveType expr ty) =
700 renderSimpleErrorMessage (ExprDoesNotHaveType expr ty) =
699 paras [ line "Expression"
701 paras [ line "Expression"
700 , markCodeBox $ indent $ prettyPrintValue valueDepth expr
702 , markCodeBox $ indent $ prettyPrintValue valueDepth expr
@@ -702,13 +704,13 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
702 , markCodeBox $ indent $ typeAsBox ty
704 , markCodeBox $ indent $ typeAsBox ty
703 ]
705 ]
704 renderSimpleErrorMessage (PropertyIsMissing prop) =
706 renderSimpleErrorMessage (PropertyIsMissing prop) =
705− line $ "Type of expression lacks required label " ++ markCode prop ++ "."
707+ line $ "Type of expression lacks required label " <> markCode prop <> "."
706 renderSimpleErrorMessage (AdditionalProperty prop) =
708 renderSimpleErrorMessage (AdditionalProperty prop) =
707− line $ "Type of expression contains additional label " ++ markCode prop ++ "."
709+ line $ "Type of expression contains additional label " <> markCode prop <> "."
708 renderSimpleErrorMessage TypeSynonymInstance =
710 renderSimpleErrorMessage TypeSynonymInstance =
709 line "Type class instances for type synonyms are disallowed."
711 line "Type class instances for type synonyms are disallowed."
710 renderSimpleErrorMessage (OrphanInstance nm cnm ts) =
712 renderSimpleErrorMessage (OrphanInstance nm cnm ts) =
711− paras [ line $ "Type class instance " ++ markCode (showIdent nm) ++ " for "
713+ paras [ line $ "Type class instance " <> markCode (showIdent nm) <> " for "
712 , markCodeBox $ indent $ Box.hsep 1 Box.left
714 , markCodeBox $ indent $ Box.hsep 1 Box.left
713 [ line (showQualified runProperName cnm)
715 [ line (showQualified runProperName cnm)
714 , Box.vcat Box.left (map typeAtomAsBox ts)
716 , Box.vcat Box.left (map typeAtomAsBox ts)
@@ -718,7 +720,7 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
718 , line "Consider moving the instance, if possible, or using a newtype wrapper."
720 , line "Consider moving the instance, if possible, or using a newtype wrapper."
719 ]
721 ]
720 renderSimpleErrorMessage (InvalidNewtype name) =
722 renderSimpleErrorMessage (InvalidNewtype name) =
721− paras [ line $ "Newtype " ++ markCode (runProperName name) ++ " is invalid."
723+ paras [ line $ "Newtype " <> markCode (runProperName name) <> " is invalid."
722 , line "Newtypes must define a single constructor with a single argument."
724 , line "Newtypes must define a single constructor with a single argument."
723 ]
725 ]
724 renderSimpleErrorMessage (InvalidInstanceHead ty) =
726 renderSimpleErrorMessage (InvalidInstanceHead ty) =
@@ -727,29 +729,29 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
727 , line "All types appearing in instance declarations must be of the form T a_1 .. a_n, where each type a_i is of the same form."
729 , line "All types appearing in instance declarations must be of the form T a_1 .. a_n, where each type a_i is of the same form."
728 ]
730 ]
729 renderSimpleErrorMessage (TransitiveExportError x ys) =
731 renderSimpleErrorMessage (TransitiveExportError x ys) =
730− paras [ line $ "An export for " ++ markCode (prettyPrintExport x) ++ " requires the following to also be exported: "
732+ paras [ line $ "An export for " <> markCode (prettyPrintExport x) <> " requires the following to also be exported: "
731 , indent $ paras $ map (line . markCode . prettyPrintExport) ys
733 , indent $ paras $ map (line . markCode . prettyPrintExport) ys
732 ]
734 ]
733 renderSimpleErrorMessage (TransitiveDctorExportError x ctor) =
735 renderSimpleErrorMessage (TransitiveDctorExportError x ctor) =
734− paras [ line $ "An export for " ++ markCode (prettyPrintExport x) ++ " requires the following data constructor to also be exported: "
736+ paras [ line $ "An export for " <> markCode (prettyPrintExport x) <> " requires the following data constructor to also be exported: "
735 , indent $ line $ markCode $ runProperName ctor
737 , indent $ line $ markCode $ runProperName ctor
736 ]
738 ]
737 renderSimpleErrorMessage (ShadowedName nm) =
739 renderSimpleErrorMessage (ShadowedName nm) =
738− line $ "Name " ++ markCode (showIdent nm) ++ " was shadowed."
740+ line $ "Name " <> markCode (showIdent nm) <> " was shadowed."
739 renderSimpleErrorMessage (ShadowedTypeVar tv) =
741 renderSimpleErrorMessage (ShadowedTypeVar tv) =
740− line $ "Type variable " ++ markCode tv ++ " was shadowed."
742+ line $ "Type variable " <> markCode tv <> " was shadowed."
741 renderSimpleErrorMessage (UnusedTypeVar tv) =
743 renderSimpleErrorMessage (UnusedTypeVar tv) =
742− line $ "Type variable " ++ markCode tv ++ " was declared but not used."
744+ line $ "Type variable " <> markCode tv <> " was declared but not used."
743 renderSimpleErrorMessage (MisleadingEmptyTypeImport mn name) =
745 renderSimpleErrorMessage (MisleadingEmptyTypeImport mn name) =
744− line $ "Importing type " ++ markCode (runProperName name ++ "(..)") ++ " from " ++ markCode (runModuleName mn) ++ " is misleading as it has no exported data constructors."
746+ line $ "Importing type " <> markCode (runProperName name <> "(..)") <> " from " <> markCode (runModuleName mn) <> " is misleading as it has no exported data constructors."
745 renderSimpleErrorMessage (ImportHidingModule name) =
747 renderSimpleErrorMessage (ImportHidingModule name) =
746 paras [ line "hiding imports cannot be used to hide modules."
748 paras [ line "hiding imports cannot be used to hide modules."
747− , line $ "An attempt was made to hide the import of " ++ markCode (runModuleName name)
749+ , line $ "An attempt was made to hide the import of " <> markCode (runModuleName name)
748 ]
750 ]
749 renderSimpleErrorMessage (WildcardInferredType ty ctx) =
751 renderSimpleErrorMessage (WildcardInferredType ty ctx) =
750 paras $ [ line "Wildcard type definition has the inferred type "
752 paras $ [ line "Wildcard type definition has the inferred type "
751 , markCodeBox $ indent $ typeAsBox ty
753 , markCodeBox $ indent $ typeAsBox ty
752− ] ++ renderContext ctx
754+ ] <> renderContext ctx
753 renderSimpleErrorMessage (HoleInferredType name ty ctx ts) =
755 renderSimpleErrorMessage (HoleInferredType name ty ctx ts) =
754 let
756 let
755 maxTSResults = 15
757 maxTSResults = 15
@@ -758,7 +760,7 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
758 let
760 let
759 formatTS (names, types) =
761 formatTS (names, types) =
760 let
762 let
761− idBoxes = Box.text . showQualified runIdent <$> names
763+ idBoxes = Box.text . T.unpack . showQualified runIdent <$> names
762 tyBoxes = (\t -> BoxHelpers.indented
764 tyBoxes = (\t -> BoxHelpers.indented
763 (Box.text ":: " Box.<> typeAsBox t)) <$> types
765 (Box.text ":: " Box.<> typeAsBox t)) <$> types
764 longestId = maximum (map Box.cols idBoxes)
766 longestId = maximum (map Box.cols idBoxes)
@@ -772,13 +774,13 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
772 ]
774 ]
773 _ -> []
775 _ -> []
774 in
776 in
775− paras $ [ line $ "Hole '" ++ markCode name ++ "' has the inferred type "
777+ paras $ [ line $ "Hole '" <> markCode name <> "' has the inferred type "
776 , markCodeBox (indent (typeAsBox ty))
778 , markCodeBox (indent (typeAsBox ty))
777 ] ++ tsResult ++ renderContext ctx
779 ] ++ tsResult ++ renderContext ctx
778 renderSimpleErrorMessage (MissingTypeDeclaration ident ty) =
780 renderSimpleErrorMessage (MissingTypeDeclaration ident ty) =
779− paras [ line $ "No type declaration was provided for the top-level declaration of " ++ markCode (showIdent ident) ++ "."
781+ paras [ line $ "No type declaration was provided for the top-level declaration of " <> markCode (showIdent ident) <> "."
780 , line "It is good practice to provide type declarations as a form of documentation."
782 , line "It is good practice to provide type declarations as a form of documentation."
781− , line $ "The inferred type of " ++ markCode (showIdent ident) ++ " was:"
783+ , line $ "The inferred type of " <> markCode (showIdent ident) <> " was:"
782 , markCodeBox $ indent $ typeAsBox ty
784 , markCodeBox $ indent $ typeAsBox ty
783 ]
785 ]
784 renderSimpleErrorMessage (OverlappingPattern bs b) =
786 renderSimpleErrorMessage (OverlappingPattern bs b) =
@@ -791,70 +793,70 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
791 , line "You may want to decompose your data types into smaller types."
793 , line "You may want to decompose your data types into smaller types."
792 ]
794 ]
793 renderSimpleErrorMessage (UnusedImport name) =
795 renderSimpleErrorMessage (UnusedImport name) =
794− line $ "The import of module " ++ markCode (runModuleName name) ++ " is redundant"
796+ line $ "The import of module " <> markCode (runModuleName name) <> " is redundant"
795
797
796 renderSimpleErrorMessage msg@(UnusedExplicitImport mn names _ _) =
798 renderSimpleErrorMessage msg@(UnusedExplicitImport mn names _ _) =
797− paras [ line $ "The import of module " ++ markCode (runModuleName mn) ++ " contains the following unused references:"
799+ paras [ line $ "The import of module " <> markCode (runModuleName mn) <> " contains the following unused references:"
798 , indent $ paras $ map (line . markCode . runName . Qualified Nothing) names
800 , indent $ paras $ map (line . markCode . runName . Qualified Nothing) names
799 , line "It could be replaced with:"
801 , line "It could be replaced with:"
800 , indent $ line $ markCode $ showSuggestion msg ]
802 , indent $ line $ markCode $ showSuggestion msg ]
801
803
802 renderSimpleErrorMessage msg@(UnusedDctorImport mn name _ _) =
804 renderSimpleErrorMessage msg@(UnusedDctorImport mn name _ _) =
803− paras [line $ "The import of type " ++ markCode (runProperName name)
805+ paras [line $ "The import of type " <> markCode (runProperName name)
804− ++ " from module " ++ markCode (runModuleName mn) ++ " includes data constructors but only the type is used"
806+ <> " from module " <> markCode (runModuleName mn) <> " includes data constructors but only the type is used"
805 , line "It could be replaced with:"
807 , line "It could be replaced with:"
806 , indent $ line $ markCode $ showSuggestion msg ]
808 , indent $ line $ markCode $ showSuggestion msg ]
807
809
808 renderSimpleErrorMessage msg@(UnusedDctorExplicitImport mn name names _ _) =
810 renderSimpleErrorMessage msg@(UnusedDctorExplicitImport mn name names _ _) =
809− paras [ line $ "The import of type " ++ markCode (runProperName name)
811+ paras [ line $ "The import of type " <> markCode (runProperName name)
810− ++ " from module " ++ markCode (runModuleName mn) ++ " includes the following unused data constructors:"
812+ <> " from module " <> markCode (runModuleName mn) <> " includes the following unused data constructors:"
811 , indent $ paras $ map (line . markCode . runProperName) names
813 , indent $ paras $ map (line . markCode . runProperName) names
812 , line "It could be replaced with:"
814 , line "It could be replaced with:"
813 , indent $ line $ markCode $ showSuggestion msg ]
815 , indent $ line $ markCode $ showSuggestion msg ]
814
816
815 renderSimpleErrorMessage (DuplicateSelectiveImport name) =
817 renderSimpleErrorMessage (DuplicateSelectiveImport name) =
816− line $ "There is an existing import of " ++ markCode (runModuleName name) ++ ", consider merging the import lists"
818+ line $ "There is an existing import of " <> markCode (runModuleName name) <> ", consider merging the import lists"
817
819
818 renderSimpleErrorMessage (DuplicateImport name imp qual) =
820 renderSimpleErrorMessage (DuplicateImport name imp qual) =
819− line $ "Duplicate import of " ++ markCode (prettyPrintImport name imp qual)
821+ line $ "Duplicate import of " <> markCode (prettyPrintImport name imp qual)
820
822
821 renderSimpleErrorMessage (DuplicateImportRef name) =
823 renderSimpleErrorMessage (DuplicateImportRef name) =
822− line $ "Import list contains multiple references to " ++ printName (Qualified Nothing name)
824+ line $ "Import list contains multiple references to " <> printName (Qualified Nothing name)
823
825
824 renderSimpleErrorMessage (DuplicateExportRef name) =
826 renderSimpleErrorMessage (DuplicateExportRef name) =
825− line $ "Export list contains multiple references to " ++ printName (Qualified Nothing name)
827+ line $ "Export list contains multiple references to " <> printName (Qualified Nothing name)
826
828
827 renderSimpleErrorMessage (IntOutOfRange value backend lo hi) =
829 renderSimpleErrorMessage (IntOutOfRange value backend lo hi) =
828− paras [ line $ "Integer value " ++ markCode (show value) ++ " is out of range for the " ++ backend ++ " backend."
830+ paras [ line $ "Integer value " <> markCode (T.pack (show value)) <> " is out of range for the " <> backend <> " backend."
829− , line $ "Acceptable values fall within the range " ++ markCode (show lo) ++ " to " ++ markCode (show hi) ++ " (inclusive)." ]
831+ , line $ "Acceptable values fall within the range " <> markCode (T.pack (show lo)) <> " to " <> markCode (T.pack (show hi)) <> " (inclusive)." ]
830
832
831 renderSimpleErrorMessage msg@(ImplicitQualifiedImport importedModule asModule _) =
833 renderSimpleErrorMessage msg@(ImplicitQualifiedImport importedModule asModule _) =
832− paras [ line $ "Module " ++ markCode (runModuleName importedModule) ++ " was imported as " ++ markCode (runModuleName asModule) ++ " with unspecified imports."
834+ paras [ line $ "Module " <> markCode (runModuleName importedModule) <> " was imported as " <> markCode (runModuleName asModule) <> " with unspecified imports."
833− , line $ "As there are multiple modules being imported as " ++ markCode (runModuleName asModule) ++ ", consider using the explicit form:"
835+ , line $ "As there are multiple modules being imported as " <> markCode (runModuleName asModule) <> ", consider using the explicit form:"
834 , indent $ line $ markCode $ showSuggestion msg
836 , indent $ line $ markCode $ showSuggestion msg
835 ]
837 ]
836
838
837 renderSimpleErrorMessage msg@(ImplicitImport mn _) =
839 renderSimpleErrorMessage msg@(ImplicitImport mn _) =
838− paras [ line $ "Module " ++ markCode (runModuleName mn) ++ " has unspecified imports, consider using the explicit form: "
840+ paras [ line $ "Module " <> markCode (runModuleName mn) <> " has unspecified imports, consider using the explicit form: "
839 , indent $ line $ markCode $ showSuggestion msg
841 , indent $ line $ markCode $ showSuggestion msg
840 ]
842 ]
841
843
842 renderSimpleErrorMessage msg@(HidingImport mn _) =
844 renderSimpleErrorMessage msg@(HidingImport mn _) =
843− paras [ line $ "Module " ++ markCode (runModuleName mn) ++ " has unspecified imports, consider using the inclusive form: "
845+ paras [ line $ "Module " <> markCode (runModuleName mn) <> " has unspecified imports, consider using the inclusive form: "
844 , indent $ line $ markCode $ showSuggestion msg
846 , indent $ line $ markCode $ showSuggestion msg
845 ]
847 ]
846
848
847 renderSimpleErrorMessage (CaseBinderLengthDiffers l bs) =
849 renderSimpleErrorMessage (CaseBinderLengthDiffers l bs) =
848 paras [ line "Binder list length differs in case alternative:"
850 paras [ line "Binder list length differs in case alternative:"
849− , indent $ line $ intercalate ", " $ fmap prettyPrintBinderAtom bs
851+ , indent $ line $ T.intercalate ", " $ fmap prettyPrintBinderAtom bs
850− , line $ "Expecting " ++ show l ++ " binder" ++ (if l == 1 then "" else "s") ++ "."
852+ , line $ "Expecting " <> T.pack (show l) <> " binder" <> (if l == 1 then "" else "s") <> "."
851 ]
853 ]
852
854
853 renderSimpleErrorMessage IncorrectAnonymousArgument =
855 renderSimpleErrorMessage IncorrectAnonymousArgument =
854 line "An anonymous function argument appears in an invalid context."
856 line "An anonymous function argument appears in an invalid context."
855
857
856 renderSimpleErrorMessage (InvalidOperatorInBinder op fn) =
858 renderSimpleErrorMessage (InvalidOperatorInBinder op fn) =
857− paras [ line $ "Operator " ++ markCode (showQualified showOp op) ++ " cannot be used in a pattern as it is an alias for function " ++ showQualified showIdent fn ++ "."
859+ paras [ line $ "Operator " <> markCode (showQualified showOp op) <> " cannot be used in a pattern as it is an alias for function " <> showQualified showIdent fn <> "."
858 , line "Only aliases for data constructors may be used in patterns."
860 , line "Only aliases for data constructors may be used in patterns."
859 ]
861 ]
860
862
@@ -862,18 +864,18 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
862 line "The require-path option is deprecated and will be removed in PureScript 0.9."
864 line "The require-path option is deprecated and will be removed in PureScript 0.9."
863
865
864 renderSimpleErrorMessage (CannotGeneralizeRecursiveFunction ident ty) =
866 renderSimpleErrorMessage (CannotGeneralizeRecursiveFunction ident ty) =
865− paras [ line $ "Unable to generalize the type of the recursive function " ++ markCode (showIdent ident) ++ "."
867+ paras [ line $ "Unable to generalize the type of the recursive function " <> markCode (showIdent ident) <> "."
866− , line $ "The inferred type of " ++ markCode (showIdent ident) ++ " was:"
868+ , line $ "The inferred type of " <> markCode (showIdent ident) <> " was:"
867 , markCodeBox $ indent $ typeAsBox ty
869 , markCodeBox $ indent $ typeAsBox ty
868 , line "Try adding a type signature."
870 , line "Try adding a type signature."
869 ]
871 ]
870
872
871 renderSimpleErrorMessage (CannotDeriveNewtypeForData tyName) =
873 renderSimpleErrorMessage (CannotDeriveNewtypeForData tyName) =
872− paras [ line $ "Cannot derive an instance of the " ++ markCode "Newtype" ++ " class for non-newtype " ++ markCode (runProperName tyName) ++ "."
874+ paras [ line $ "Cannot derive an instance of the " <> markCode "Newtype" <> " class for non-newtype " <> markCode (runProperName tyName) <> "."
873 ]
875 ]
874
876
875 renderSimpleErrorMessage (ExpectedWildcard tyName) =
877 renderSimpleErrorMessage (ExpectedWildcard tyName) =
876− paras [ line $ "Expected a type wildcard (_) when deriving an instance for " ++ markCode (runProperName tyName) ++ "."
878+ paras [ line $ "Expected a type wildcard (_) when deriving an instance for " <> markCode (runProperName tyName) <> "."
877 ]
879 ]
878
880
879 renderHint :: ErrorMessageHint -> Box.Box -> Box.Box
881 renderHint :: ErrorMessageHint -> Box.Box -> Box.Box
@@ -893,7 +895,7 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
893 ]
895 ]
894 ]
896 ]
895 renderHint (ErrorInModule mn) detail =
897 renderHint (ErrorInModule mn) detail =
896− paras [ line $ "in module " ++ markCode (runModuleName mn)
898+ paras [ line $ "in module " <> markCode (runModuleName mn)
897 , detail
899 , detail
898 ]
900 ]
899 renderHint (ErrorInSubsumption t1 t2) detail =
901 renderHint (ErrorInSubsumption t1 t2) detail =
@@ -958,15 +960,15 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
958 ]
960 ]
959 renderHint (ErrorInDataConstructor nm) detail =
961 renderHint (ErrorInDataConstructor nm) detail =
960 paras [ detail
962 paras [ detail
961− , line $ "in data constructor " ++ markCode (runProperName nm)
963+ , line $ "in data constructor " <> markCode (runProperName nm)
962 ]
964 ]
963 renderHint (ErrorInTypeConstructor nm) detail =
965 renderHint (ErrorInTypeConstructor nm) detail =
964 paras [ detail
966 paras [ detail
965− , line $ "in type constructor " ++ markCode (runProperName nm)
967+ , line $ "in type constructor " <> markCode (runProperName nm)
966 ]
968 ]
967 renderHint (ErrorInBindingGroup nms) detail =
969 renderHint (ErrorInBindingGroup nms) detail =
968 paras [ detail
970 paras [ detail
969− , line $ "in binding group " ++ intercalate ", " (map showIdent nms)
971+ , line $ "in binding group " <> T.intercalate ", " (map showIdent nms)
970 ]
972 ]
971 renderHint (ErrorInDataBindingGroup nms) detail =
973 renderHint (ErrorInDataBindingGroup nms) detail =
972 paras [ detail
974 paras [ detail
@@ -974,15 +976,15 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
974 ]
976 ]
975 renderHint (ErrorInTypeSynonym name) detail =
977 renderHint (ErrorInTypeSynonym name) detail =
976 paras [ detail
978 paras [ detail
977− , line $ "in type synonym " ++ markCode (runProperName name)
979+ , line $ "in type synonym " <> markCode (runProperName name)
978 ]
980 ]
979 renderHint (ErrorInValueDeclaration n) detail =
981 renderHint (ErrorInValueDeclaration n) detail =
980 paras [ detail
982 paras [ detail
981− , line $ "in value declaration " ++ markCode (showIdent n)
983+ , line $ "in value declaration " <> markCode (showIdent n)
982 ]
984 ]
983 renderHint (ErrorInTypeDeclaration n) detail =
985 renderHint (ErrorInTypeDeclaration n) detail =
984 paras [ detail
986 paras [ detail
985− , line $ "in type declaration for " ++ markCode (showIdent n)
987+ , line $ "in type declaration for " <> markCode (showIdent n)
986 ]
988 ]
987 renderHint (ErrorInTypeClassDeclaration name) detail =
989 renderHint (ErrorInTypeClassDeclaration name) detail =
988 paras [ detail
990 paras [ detail
@@ -990,7 +992,7 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
990 ]
992 ]
991 renderHint (ErrorInForeignImport nm) detail =
993 renderHint (ErrorInForeignImport nm) detail =
992 paras [ detail
994 paras [ detail
993− , line $ "in foreign import " ++ markCode (showIdent nm)
995+ , line $ "in foreign import " <> markCode (showIdent nm)
994 ]
996 ]
995 renderHint (ErrorSolvingConstraint (Constraint nm ts _)) detail =
997 renderHint (ErrorSolvingConstraint (Constraint nm ts _)) detail =
996 paras [ detail
998 paras [ detail
@@ -1001,7 +1003,7 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
1001 ]
1003 ]
1002 ]
1004 ]
1003 renderHint (PositionedError srcSpan) detail =
1005 renderHint (PositionedError srcSpan) detail =
1004− paras [ line $ "at " ++ displaySourceSpan srcSpan
1006+ paras [ line $ "at " <> displaySourceSpan srcSpan
1005 , detail
1007 , detail
1006 ]
1008 ]
1007
1009
@@ -1010,17 +1012,17 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
1010 renderContext ctx =
1012 renderContext ctx =
1011 [ line "in the following context:"
1013 [ line "in the following context:"
1012 , indent $ paras
1014 , indent $ paras
1013− [ Box.hcat Box.left [ Box.text (showIdent ident <> " :: ")
1015+ [ Box.hcat Box.left [ Box.text (T.unpack (showIdent ident) ++ " :: ")
1014 , markCodeBox $ typeAsBox ty'
1016 , markCodeBox $ typeAsBox ty'
1015 ]
1017 ]
1016 | (ident, ty') <- take 5 ctx
1018 | (ident, ty') <- take 5 ctx
1017 ]
1019 ]
1018 ]
1020 ]
1019
1021
1020− printName :: Qualified Name -> String
1022+ printName :: Qualified Name -> Text
1021− printName qn = nameType (disqualify qn) ++ " " ++ markCode (runName qn)
1023+ printName qn = nameType (disqualify qn) <> " " <> markCode (runName qn)
1022
1024
1023− nameType :: Name -> String
1025+ nameType :: Name -> Text
1024 nameType (IdentName _) = "value"
1026 nameType (IdentName _) = "value"
1025 nameType (ValOpName _) = "operator"
1027 nameType (ValOpName _) = "operator"
1026 nameType (TyName _) = "type"
1028 nameType (TyName _) = "type"
@@ -1029,7 +1031,7 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
1029 nameType (TyClassName _) = "type class"
1031 nameType (TyClassName _) = "type class"
1030 nameType (ModName _) = "module"
1032 nameType (ModName _) = "module"
1031
1033
1032− runName :: Qualified Name -> String
1034+ runName :: Qualified Name -> Text
1033 runName (Qualified mn (IdentName name)) =
1035 runName (Qualified mn (IdentName name)) =
1034 showQualified showIdent (Qualified mn name)
1036 showQualified showIdent (Qualified mn name)
1035 runName (Qualified mn (ValOpName op)) =
1037 runName (Qualified mn (ValOpName op)) =
@@ -1051,7 +1053,7 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
1051 valueDepth | full = 1000
1053 valueDepth | full = 1000
1052 | otherwise = 3
1054 | otherwise = 3
1053
1055
1054− levelText :: String
1056+ levelText :: Text
1055 levelText = case level of
1057 levelText = case level of
1056 Error -> "error"
1058 Error -> "error"
1057 Warning -> "warning"
1059 Warning -> "warning"
@@ -1112,40 +1114,40 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
1112 hintCategory _ = OtherHint
1114 hintCategory _ = OtherHint
1113
1115
1114-- Pretty print and export declaration
1116-- Pretty print and export declaration
1115−prettyPrintExport :: DeclarationRef -> String
1117+prettyPrintExport :: DeclarationRef -> Text
1116prettyPrintExport (TypeRef pn _) = runProperName pn
1118prettyPrintExport (TypeRef pn _) = runProperName pn
1117prettyPrintExport ref =
1119prettyPrintExport ref =
1118 fromMaybe
1120 fromMaybe
1119 (internalError "prettyPrintRef returned Nothing in prettyPrintExport")
1121 (internalError "prettyPrintRef returned Nothing in prettyPrintExport")
1120 (prettyPrintRef ref)
1122 (prettyPrintRef ref)
1121
1123
1122−prettyPrintImport :: ModuleName -> ImportDeclarationType -> Maybe ModuleName -> String
1124+prettyPrintImport :: ModuleName -> ImportDeclarationType -> Maybe ModuleName -> Text
1123prettyPrintImport mn idt qual =
1125prettyPrintImport mn idt qual =
1124 let i = case idt of
1126 let i = case idt of
1125 Implicit -> runModuleName mn
1127 Implicit -> runModuleName mn
1126− Explicit refs -> runModuleName mn ++ " (" ++ intercalate ", " (mapMaybe prettyPrintRef refs) ++ ")"
1128+ Explicit refs -> runModuleName mn <> " (" <> T.intercalate ", " (mapMaybe prettyPrintRef refs) <> ")"
1127− Hiding refs -> runModuleName mn ++ " hiding (" ++ intercalate "," (mapMaybe prettyPrintRef refs) ++ ")"
1129+ Hiding refs -> runModuleName mn <> " hiding (" <> T.intercalate "," (mapMaybe prettyPrintRef refs) <> ")"
1128− in i ++ maybe "" (\q -> " as " ++ runModuleName q) qual
1130+ in i <> maybe "" (\q -> " as " <> runModuleName q) qual
1129
1131
1130−prettyPrintRef :: DeclarationRef -> Maybe String
1132+prettyPrintRef :: DeclarationRef -> Maybe Text
1131prettyPrintRef (TypeRef pn Nothing) =
1133prettyPrintRef (TypeRef pn Nothing) =
1132− Just $ runProperName pn ++ "(..)"
1134+ Just $ runProperName pn <> "(..)"
1133prettyPrintRef (TypeRef pn (Just [])) =
1135prettyPrintRef (TypeRef pn (Just [])) =
1134 Just $ runProperName pn
1136 Just $ runProperName pn
1135prettyPrintRef (TypeRef pn (Just dctors)) =
1137prettyPrintRef (TypeRef pn (Just dctors)) =
1136− Just $ runProperName pn ++ "(" ++ intercalate ", " (map runProperName dctors) ++ ")"
1138+ Just $ runProperName pn <> "(" <> T.intercalate ", " (map runProperName dctors) <> ")"
1137prettyPrintRef (TypeOpRef op) =
1139prettyPrintRef (TypeOpRef op) =
1138− Just $ "type " ++ showOp op
1140+ Just $ "type " <> showOp op
1139prettyPrintRef (ValueRef ident) =
1141prettyPrintRef (ValueRef ident) =
1140 Just $ showIdent ident
1142 Just $ showIdent ident
1141prettyPrintRef (ValueOpRef op) =
1143prettyPrintRef (ValueOpRef op) =
1142 Just $ showOp op
1144 Just $ showOp op
1143prettyPrintRef (TypeClassRef pn) =
1145prettyPrintRef (TypeClassRef pn) =
1144− Just $ "class " ++ runProperName pn
1146+ Just $ "class " <> runProperName pn
1145prettyPrintRef (TypeInstanceRef ident) =
1147prettyPrintRef (TypeInstanceRef ident) =
1146 Just $ showIdent ident
1148 Just $ showIdent ident
1147prettyPrintRef (ModuleRef name) =
1149prettyPrintRef (ModuleRef name) =
1148− Just $ "module " ++ runModuleName name
1150+ Just $ "module " <> runModuleName name
1149prettyPrintRef (ReExportRef _ _) =
1151prettyPrintRef (ReExportRef _ _) =
1150 Nothing
1152 Nothing
1151prettyPrintRef (PositionedDeclarationRef _ _ ref) =
1153prettyPrintRef (PositionedDeclarationRef _ _ ref) =
@@ -1238,8 +1240,11 @@ prettyPrintParseErrorMessages msgOr msgUnknown msgExpecting msgUnExpected msgEnd
1238indent :: Box.Box -> Box.Box
1240indent :: Box.Box -> Box.Box
1239indent = Box.moveUp 1 . Box.moveDown 1 . Box.moveRight 2
1241indent = Box.moveUp 1 . Box.moveDown 1 . Box.moveRight 2
1240
1242
1243+line :: Text -> Box.Box
1244+line = Box.text . T.unpack
1245+
1241−line :: String -> Box.Box
1246+lineS :: String -> Box.Box
1242−line = Box.text
1247+lineS = Box.text
1243
1248
1244renderBox :: Box.Box -> String
1249renderBox :: Box.Box -> String
1245renderBox = unlines
1250renderBox = unlines
@@ -1253,7 +1258,7 @@ renderBox = unlines
1253 whiteSpace = all isSpace
1258 whiteSpace = all isSpace
1254
1259
1255toTypelevelString :: Type -> Maybe Box.Box
1260toTypelevelString :: Type -> Maybe Box.Box
1256−toTypelevelString (TypeLevelString s) = Just $ Box.text s
1261+toTypelevelString (TypeLevelString s) = Just $ Box.text (T.unpack s)
1257toTypelevelString (TypeApp (TypeConstructor f) x)
1262toTypelevelString (TypeApp (TypeConstructor f) x)
1258 | f == primName "TypeString" = Just $ typeAsBox x
1263 | f == primName "TypeString" = Just $ typeAsBox x
1259toTypelevelString (TypeApp (TypeApp (TypeConstructor f) x) ret)
1264toTypelevelString (TypeApp (TypeApp (TypeConstructor f) x) ret)
src/Language/PureScript/Errors/JSON.hs+8−5
@@ -5,6 +5,9 @@ module Language.PureScript.Errors.JSON where
5import Prelude.Compat
5import Prelude.Compat
6
6
7import qualified Data.Aeson.TH as A
7import qualified Data.Aeson.TH as A
8+import Data.Monoid ((<>))
9+import qualified Data.Text as T
10+import Data.Text (Text)
8
11
9import qualified Language.PureScript as P
12import qualified Language.PureScript as P
10
13
@@ -16,17 +19,17 @@ data ErrorPosition = ErrorPosition
16 } deriving (Show, Eq, Ord)
19 } deriving (Show, Eq, Ord)
17
20
18data ErrorSuggestion = ErrorSuggestion
21data ErrorSuggestion = ErrorSuggestion
19− { replacement :: String
22+ { replacement :: Text
20 , replaceRange :: Maybe ErrorPosition
23 , replaceRange :: Maybe ErrorPosition
21 } deriving (Show, Eq)
24 } deriving (Show, Eq)
22
25
23data JSONError = JSONError
26data JSONError = JSONError
24 { position :: Maybe ErrorPosition
27 { position :: Maybe ErrorPosition
25 , message :: String
28 , message :: String
26− , errorCode :: String
29+ , errorCode :: Text
27− , errorLink :: String
30+ , errorLink :: Text
28 , filename :: Maybe String
31 , filename :: Maybe String
29− , moduleName :: Maybe String
32+ , moduleName :: Maybe Text
30 , suggestion :: Maybe ErrorSuggestion
33 , suggestion :: Maybe ErrorSuggestion
31 } deriving (Show, Eq)
34 } deriving (Show, Eq)
32
35
@@ -70,4 +73,4 @@ toJSONError verbose level e =
70 Just s -> Just $ ErrorSuggestion (suggestionText s) (toErrorPosition <$> P.suggestionSpan em)
73 Just s -> Just $ ErrorSuggestion (suggestionText s) (toErrorPosition <$> P.suggestionSpan em)
71
74
72 -- TODO: Adding a newline because source spans chomp everything up to the next character
75 -- TODO: Adding a newline because source spans chomp everything up to the next character
73− suggestionText (P.ErrorSuggestion s) = if null s then s else s ++ "\n"
76+ suggestionText (P.ErrorSuggestion s) = if T.null s then s else s <> "\n"
src/Language/PureScript/Externs.hs+9−7
@@ -17,9 +17,11 @@ module Language.PureScript.Externs
17import Prelude.Compat
17import Prelude.Compat
18
18
19import Data.Aeson.TH
19import Data.Aeson.TH
20+import Data.Maybe (fromMaybe, mapMaybe, maybeToList)
21+import Data.List (foldl', find)
20import Data.Foldable (fold)
22import Data.Foldable (fold)
21−import Data.List (find, foldl')
23+import Data.Text (Text)
22−import Data.Maybe (mapMaybe, maybeToList, fromMaybe)
24+import qualified Data.Text as T
23import Data.Version (showVersion)
25import Data.Version (showVersion)
24import qualified Data.Map as M
26import qualified Data.Map as M
25
27
@@ -37,7 +39,7 @@ import Paths_purescript as Paths
37data ExternsFile = ExternsFile
39data ExternsFile = ExternsFile
38 {
40 {
39 -- | The externs version
41 -- | The externs version
40− efVersion :: String
42+ efVersion :: Text
41 -- | Module name
43 -- | Module name
42 , efModuleName :: ModuleName
44 , efModuleName :: ModuleName
43 -- | List of module exports
45 -- | List of module exports
@@ -100,7 +102,7 @@ data ExternsDeclaration =
100 -- | A type synonym
102 -- | A type synonym
101 | EDTypeSynonym
103 | EDTypeSynonym
102 { edTypeSynonymName :: ProperName 'TypeName
104 { edTypeSynonymName :: ProperName 'TypeName
103− , edTypeSynonymArguments :: [(String, Maybe Kind)]
105+ , edTypeSynonymArguments :: [(Text, Maybe Kind)]
104 , edTypeSynonymType :: Type
106 , edTypeSynonymType :: Type
105 }
107 }
106 -- | A data construtor
108 -- | A data construtor
@@ -119,7 +121,7 @@ data ExternsDeclaration =
119 -- | A type class declaration
121 -- | A type class declaration
120 | EDClass
122 | EDClass
121 { edClassName :: ProperName 'ClassName
123 { edClassName :: ProperName 'ClassName
122− , edClassTypeArguments :: [(String, Maybe Kind)]
124+ , edClassTypeArguments :: [(Text, Maybe Kind)]
123 , edClassMembers :: [(Ident, Type)]
125 , edClassMembers :: [(Ident, Type)]
124 , edClassConstraints :: [Constraint]
126 , edClassConstraints :: [Constraint]
125 , edFunctionalDependencies :: [FunctionalDependency]
127 , edFunctionalDependencies :: [FunctionalDependency]
@@ -159,7 +161,7 @@ moduleToExternsFile :: Module -> Environment -> ExternsFile
159moduleToExternsFile (Module _ _ _ _ Nothing) _ = internalError "moduleToExternsFile: module exports were not elaborated"
161moduleToExternsFile (Module _ _ _ _ Nothing) _ = internalError "moduleToExternsFile: module exports were not elaborated"
160moduleToExternsFile (Module _ _ mn ds (Just exps)) env = ExternsFile{..}
162moduleToExternsFile (Module _ _ mn ds (Just exps)) env = ExternsFile{..}
161 where
163 where
162− efVersion = showVersion Paths.version
164+ efVersion = T.pack (showVersion Paths.version)
163 efModuleName = mn
165 efModuleName = mn
164 efExports = exps
166 efExports = exps
165 efImports = mapMaybe importDecl ds
167 efImports = mapMaybe importDecl ds
@@ -180,7 +182,7 @@ moduleToExternsFile (Module _ _ mn ds (Just exps)) env = ExternsFile{..}
180 typeFixityDecl _ = Nothing
182 typeFixityDecl _ = Nothing
181
183
182 findOp :: (DeclarationRef -> Maybe (OpName a)) -> OpName a -> DeclarationRef -> Bool
184 findOp :: (DeclarationRef -> Maybe (OpName a)) -> OpName a -> DeclarationRef -> Bool
183− findOp get op = maybe False (== op) . get
185+ findOp g op = maybe False (== op) . g
184
186
185 importDecl :: Declaration -> Maybe ExternsImport
187 importDecl :: Declaration -> Maybe ExternsImport
186 importDecl (ImportDeclaration m mt qmn) = Just (ExternsImport m mt qmn)
188 importDecl (ImportDeclaration m mt qmn) = Just (ExternsImport m mt qmn)
src/Language/PureScript/Ide.hs+2−2
@@ -142,7 +142,7 @@ findAvailableExterns = do
142 liftIO $ do
142 liftIO $ do
143 directories <- getDirectoryContents oDir
143 directories <- getDirectoryContents oDir
144 moduleNames <- filterM (containsExterns oDir) directories
144 moduleNames <- filterM (containsExterns oDir) directories
145− pure (P.moduleNameFromString <$> moduleNames)
145+ pure (P.moduleNameFromString . toS <$> moduleNames)
146 where
146 where
147 -- Takes the output directory and a filepath like "Monad.Control.Eff" and
147 -- Takes the output directory and a filepath like "Monad.Control.Eff" and
148 -- looks up, whether that folder contains an externs.json
148 -- looks up, whether that folder contains an externs.json
@@ -171,7 +171,7 @@ loadModules moduleNames = do
171 -- We resolve all the modulenames to externs files and load these into memory.
171 -- We resolve all the modulenames to externs files and load these into memory.
172 oDir <- outputDirectory
172 oDir <- outputDirectory
173 let efPaths =
173 let efPaths =
174− map (\mn -> oDir </> P.runModuleName mn </> "externs.json") moduleNames
174+ map (\mn -> oDir </> toS (P.runModuleName mn) </> "externs.json") moduleNames
175 efiles <- traverse readExternFile efPaths
175 efiles <- traverse readExternFile efPaths
176 traverse_ insertExterns efiles
176 traverse_ insertExterns efiles
177
177
src/Language/PureScript/Ide/Imports.hs+5−5
@@ -145,7 +145,7 @@ step (Res start end) _ = Res start end
145
145
146moduleParse :: [Text] -> Either Text P.Module
146moduleParse :: [Text] -> Either Text P.Module
147moduleParse t = first show $ do
147moduleParse t = first show $ do
148− tokens <- (P.lex "" . T.unpack . T.unlines) t
148+ tokens <- P.lex "" (T.unlines t)
149 P.runTokenParser "<psc-ide>" P.parseModule tokens
149 P.runTokenParser "<psc-ide>" P.parseModule tokens
150
150
151-- | Adds an implicit import like @import Prelude@ to a Sourcefile.
151-- | Adds an implicit import like @import Prelude@ to a Sourcefile.
@@ -210,7 +210,7 @@ addExplicitImport' decl moduleName imports =
210 refFromDeclaration (IdeDeclTypeOperator op) =
210 refFromDeclaration (IdeDeclTypeOperator op) =
211 P.TypeOpRef (op ^. ideTypeOpName)
211 P.TypeOpRef (op ^. ideTypeOpName)
212 refFromDeclaration d =
212 refFromDeclaration d =
213− P.ValueRef $ P.Ident $ T.unpack (identifierFromIdeDeclaration d)
213+ P.ValueRef (P.Ident (identifierFromIdeDeclaration d))
214
214
215 -- | Adds a declaration to an import:
215 -- | Adds a declaration to an import:
216 -- TypeDeclaration "Maybe" + Data.Maybe (maybe) -> Data.Maybe(Maybe, maybe)
216 -- TypeDeclaration "Maybe" + Data.Maybe (maybe) -> Data.Maybe(Maybe, maybe)
@@ -304,9 +304,9 @@ addImportForIdentifier fp ident filters = do
304prettyPrintImport' :: Import -> Text
304prettyPrintImport' :: Import -> Text
305-- TODO: remove this clause once P.prettyPrintImport can properly handle PositionedRefs
305-- TODO: remove this clause once P.prettyPrintImport can properly handle PositionedRefs
306prettyPrintImport' (Import mn (P.Explicit refs) qual) =
306prettyPrintImport' (Import mn (P.Explicit refs) qual) =
307− T.pack $ "import " ++ P.prettyPrintImport mn (P.Explicit (unwrapPositionedRef <$> refs)) qual
307+ "import " <> P.prettyPrintImport mn (P.Explicit (unwrapPositionedRef <$> refs)) qual
308prettyPrintImport' (Import mn idt qual) =
308prettyPrintImport' (Import mn idt qual) =
309− T.pack $ "import " ++ P.prettyPrintImport mn idt qual
309+ "import " <> P.prettyPrintImport mn idt qual
310
310
311prettyPrintImportSection :: [Import] -> [Text]
311prettyPrintImportSection :: [Import] -> [Text]
312prettyPrintImportSection imports = map prettyPrintImport' (sort imports)
312prettyPrintImportSection imports = map prettyPrintImport' (sort imports)
@@ -325,7 +325,7 @@ answerRequest outfp rs =
325-- | Test and ghci helper
325-- | Test and ghci helper
326parseImport :: Text -> Maybe Import
326parseImport :: Text -> Maybe Import
327parseImport t =
327parseImport t =
328− case P.lex "<psc-ide>" (T.unpack t)
328+ case P.lex "<psc-ide>" t
329 >>= P.runTokenParser "<psc-ide>" P.parseImportDeclaration' of
329 >>= P.runTokenParser "<psc-ide>" P.parseImportDeclaration' of
330 Right (mn, P.Explicit refs, mmn) ->
330 Right (mn, P.Explicit refs, mmn) ->
331 Just (Import mn (P.Explicit (unwrapPositionedRef <$> refs)) mmn)
331 Just (Import mn (P.Explicit (unwrapPositionedRef <$> refs)) mmn)
src/Language/PureScript/Interactive.hs+19−16
@@ -16,9 +16,12 @@ module Language.PureScript.Interactive
16import Prelude ()
16import Prelude ()
17import Prelude.Compat
17import Prelude.Compat
18
18
19−import Data.List (intercalate, nub, sort, find, foldl')
19+import Data.List (nub, sort, find, foldl')
20import Data.Maybe (mapMaybe)
20import Data.Maybe (mapMaybe)
21import qualified Data.Map as M
21import qualified Data.Map as M
22+import Data.Monoid ((<>))
23+import Data.Text (Text)
24+import qualified Data.Text as T
22
25
23import Control.Monad.IO.Class (MonadIO, liftIO)
26import Control.Monad.IO.Class (MonadIO, liftIO)
24import Control.Monad.State.Class
27import Control.Monad.State.Class
@@ -165,7 +168,7 @@ handleShowLoadedModules = do
165 loadedModules <- gets psciLoadedExterns
168 loadedModules <- gets psciLoadedExterns
166 liftIO $ putStrLn (readModules loadedModules)
169 liftIO $ putStrLn (readModules loadedModules)
167 where
170 where
168− readModules = unlines . sort . nub . map (P.runModuleName . P.getModuleName . fst)
171+ readModules = unlines . sort . nub . map (T.unpack . P.runModuleName . P.getModuleName . fst)
169
172
170-- | Show the imported modules in psci.
173-- | Show the imported modules in psci.
171handleShowImportedModules
174handleShowImportedModules
@@ -176,38 +179,38 @@ handleShowImportedModules = do
176 liftIO $ showModules importedModules >>= putStrLn
179 liftIO $ showModules importedModules >>= putStrLn
177 return ()
180 return ()
178 where
181 where
179− showModules = return . unlines . sort . map showModule
182+ showModules = return . unlines . sort . map (T.unpack . showModule)
180 showModule (mn, declType, asQ) =
183 showModule (mn, declType, asQ) =
181− "import " ++ N.runModuleName mn ++ showDeclType declType ++
184+ "import " <> N.runModuleName mn <> showDeclType declType <>
182− foldMap (\mn' -> " as " ++ N.runModuleName mn') asQ
185+ foldMap (\mn' -> " as " <> N.runModuleName mn') asQ
183
186
184 showDeclType P.Implicit = ""
187 showDeclType P.Implicit = ""
185 showDeclType (P.Explicit refs) = refsList refs
188 showDeclType (P.Explicit refs) = refsList refs
186− showDeclType (P.Hiding refs) = " hiding " ++ refsList refs
189+ showDeclType (P.Hiding refs) = " hiding " <> refsList refs
187− refsList refs = " (" ++ commaList (mapMaybe showRef refs) ++ ")"
190+ refsList refs = " (" <> commaList (mapMaybe showRef refs) <> ")"
188
191
189− showRef :: P.DeclarationRef -> Maybe String
192+ showRef :: P.DeclarationRef -> Maybe Text
190 showRef (P.TypeRef pn dctors) =
193 showRef (P.TypeRef pn dctors) =
191− Just $ N.runProperName pn ++ "(" ++ maybe ".." (commaList . map N.runProperName) dctors ++ ")"
194+ Just $ N.runProperName pn <> "(" <> maybe ".." (commaList . map N.runProperName) dctors <> ")"
192 showRef (P.TypeOpRef op) =
195 showRef (P.TypeOpRef op) =
193− Just $ "type " ++ N.showOp op
196+ Just $ "type " <> N.showOp op
194 showRef (P.ValueRef ident) =
197 showRef (P.ValueRef ident) =
195 Just $ N.runIdent ident
198 Just $ N.runIdent ident
196 showRef (P.ValueOpRef op) =
199 showRef (P.ValueOpRef op) =
197 Just $ N.showOp op
200 Just $ N.showOp op
198 showRef (P.TypeClassRef pn) =
201 showRef (P.TypeClassRef pn) =
199− Just $ "class " ++ N.runProperName pn
202+ Just $ "class " <> N.runProperName pn
200 showRef (P.TypeInstanceRef ident) =
203 showRef (P.TypeInstanceRef ident) =
201 Just $ N.runIdent ident
204 Just $ N.runIdent ident
202 showRef (P.ModuleRef name) =
205 showRef (P.ModuleRef name) =
203− Just $ "module " ++ N.runModuleName name
206+ Just $ "module " <> N.runModuleName name
204 showRef (P.ReExportRef _ _) =
207 showRef (P.ReExportRef _ _) =
205 Nothing
208 Nothing
206 showRef (P.PositionedDeclarationRef _ _ ref) =
209 showRef (P.PositionedDeclarationRef _ _ ref) =
207 showRef ref
210 showRef ref
208
211
209− commaList :: [String] -> String
212+ commaList :: [Text] -> Text
210− commaList = intercalate ", "
213+ commaList = T.intercalate ", "
211
214
212-- | Imports a module, preserving the initial state on failure.
215-- | Imports a module, preserving the initial state on failure.
213handleImport
216handleImport
@@ -260,7 +263,7 @@ handleKindOf typ = do
260 check sew = fst . runWriter . runExceptT . runStateT sew
263 check sew = fst . runWriter . runExceptT . runStateT sew
261 case k of
264 case k of
262 Left err -> printErrors err
265 Left err -> printErrors err
263− Right (kind, _) -> liftIO . putStrLn . P.prettyPrintKind $ kind
266+ Right (kind, _) -> liftIO . putStrLn . T.unpack . P.prettyPrintKind $ kind
264 Nothing -> liftIO $ putStrLn "Could not find kind"
267 Nothing -> liftIO $ putStrLn "Could not find kind"
265
268
266-- | Browse a module and displays its signature
269-- | Browse a module and displays its signature
@@ -284,6 +287,6 @@ handleBrowse moduleName = do
284 isModInEnv modName =
287 isModInEnv modName =
285 any ((== modName) . P.getModuleName . fst) . psciLoadedExterns
288 any ((== modName) . P.getModuleName . fst) . psciLoadedExterns
286 failNotInEnv modName =
289 failNotInEnv modName =
287− liftIO $ putStrLn $ "Module '" ++ N.runModuleName modName ++ "' is not valid."
290+ liftIO $ putStrLn $ T.unpack $ "Module '" <> N.runModuleName modName <> "' is not valid."
288 lookupUnQualifiedModName quaModName st =
291 lookupUnQualifiedModName quaModName st =
289 (\(modName,_,_) -> modName) <$> find ( \(_, _, mayQuaName) -> mayQuaName == Just quaModName) (psciImportedModules st)
292 (\(modName,_,_) -> modName) <$> find ( \(_, _, mayQuaName) -> mayQuaName == Just quaModName) (psciImportedModules st)
src/Language/PureScript/Interactive/Completion.hs+6−4
@@ -16,6 +16,8 @@ import Control.Monad.Trans.Reader (asks, runReaderT, ReaderT)
16import Data.Function (on)
16import Data.Function (on)
17import Data.List (nub, nubBy, isPrefixOf, sortBy, stripPrefix)
17import Data.List (nub, nubBy, isPrefixOf, sortBy, stripPrefix)
18import Data.Maybe (mapMaybe)
18import Data.Maybe (mapMaybe)
19+import Data.Text (Text)
20+import qualified Data.Text as T
19import qualified Language.PureScript as P
21import qualified Language.PureScript as P
20import qualified Language.PureScript.Interactive.Directive as D
22import qualified Language.PureScript.Interactive.Directive as D
21import Language.PureScript.Interactive.Types
23import Language.PureScript.Interactive.Types
@@ -145,7 +147,7 @@ getLoadedModules = asks (map fst . psciLoadedExterns)
145getModuleNames :: CompletionM [String]
147getModuleNames :: CompletionM [String]
146getModuleNames = moduleNames <$> getLoadedModules
148getModuleNames = moduleNames <$> getLoadedModules
147
149
148−mapLoadedModulesAndQualify :: (a -> String) -> (P.Module -> [(a, P.Declaration)]) -> CompletionM [String]
150+mapLoadedModulesAndQualify :: (a -> Text) -> (P.Module -> [(a, P.Declaration)]) -> CompletionM [String]
149mapLoadedModulesAndQualify sho f = do
151mapLoadedModulesAndQualify sho f = do
150 ms <- getLoadedModules
152 ms <- getLoadedModules
151 let argPairs = do m <- ms
153 let argPairs = do m <- ms
@@ -165,14 +167,14 @@ getTypeNames = mapLoadedModulesAndQualify P.runProperName typeDecls
165-- | Given a module and a declaration in that module, return all possible ways
167-- | Given a module and a declaration in that module, return all possible ways
166-- it could have been referenced given the current PSCiState - including fully
168-- it could have been referenced given the current PSCiState - including fully
167-- qualified, qualified using an alias, and unqualified.
169-- qualified, qualified using an alias, and unqualified.
168−getAllQualifications :: (a -> String) -> P.Module -> (a, P.Declaration) -> CompletionM [String]
170+getAllQualifications :: (a -> Text) -> P.Module -> (a, P.Declaration) -> CompletionM [String]
169getAllQualifications sho m (declName, decl) = do
171getAllQualifications sho m (declName, decl) = do
170 imports <- getAllImportsOf m
172 imports <- getAllImportsOf m
171 let fullyQualified = qualifyWith (Just (P.getModuleName m))
173 let fullyQualified = qualifyWith (Just (P.getModuleName m))
172 let otherQuals = nub (concatMap qualificationsUsing imports)
174 let otherQuals = nub (concatMap qualificationsUsing imports)
173 return $ fullyQualified : otherQuals
175 return $ fullyQualified : otherQuals
174 where
176 where
175− qualifyWith mMod = P.showQualified sho (P.Qualified mMod declName)
177+ qualifyWith mMod = T.unpack (P.showQualified sho (P.Qualified mMod declName))
176 referencedBy refs = P.isExported (Just refs) decl
178 referencedBy refs = P.isExported (Just refs) decl
177
179
178 qualificationsUsing (_, importType, asQ') =
180 qualificationsUsing (_, importType, asQ') =
@@ -220,4 +222,4 @@ dctorNames = nubOnFst . concatMap go . P.exportedDeclarations
220 go _ = []
222 go _ = []
221
223
222moduleNames :: [P.Module] -> [String]
224moduleNames :: [P.Module] -> [String]
223−moduleNames = nub . map (P.runModuleName . P.getModuleName)
225+moduleNames = nub . map (T.unpack . P.runModuleName . P.getModuleName)
src/Language/PureScript/Interactive/Parser.hs+2−1
@@ -9,6 +9,7 @@ import Prelude.Compat hiding (lex)
9
9
10import Data.Char (isSpace)
10import Data.Char (isSpace)
11import Data.List (intercalate)
11import Data.List (intercalate)
12+import qualified Data.Text as T
12import Text.Parsec hiding ((<|>))
13import Text.Parsec hiding ((<|>))
13import qualified Language.PureScript as P
14import qualified Language.PureScript as P
14import qualified Language.PureScript.Interactive.Directive as D
15import qualified Language.PureScript.Interactive.Directive as D
@@ -26,7 +27,7 @@ parseCommand cmdString =
26
27
27parseRest :: P.TokenParser a -> String -> Either String a
28parseRest :: P.TokenParser a -> String -> Either String a
28parseRest p s = either (Left . show) Right $ do
29parseRest p s = either (Left . show) Right $ do
29− ts <- P.lex "" s
30+ ts <- P.lex "" (T.pack s)
30 P.runTokenParser "" (p <* eof) ts
31 P.runTokenParser "" (p <* eof) ts
31
32
32psciCommand :: P.TokenParser Command
33psciCommand :: P.TokenParser Command
src/Language/PureScript/Interactive/Printer.hs+16−9
@@ -8,9 +8,16 @@ import Prelude.Compat
8import Data.List (intersperse)
8import Data.List (intersperse)
9import qualified Data.Map as M
9import qualified Data.Map as M
10import Data.Maybe (mapMaybe)
10import Data.Maybe (mapMaybe)
11+import Data.Monoid ((<>))
12+import qualified Data.Text as T
13+import Data.Text (Text)
11import qualified Language.PureScript as P
14import qualified Language.PureScript as P
12import qualified Text.PrettyPrint.Boxes as Box
15import qualified Text.PrettyPrint.Boxes as Box
13
16
17+-- TODO (Christoph): Text version of boxes
18+textT :: Text -> Box.Box
19+textT = Box.text . T.unpack
20+
14-- Printers
21-- Printers
15
22
16-- |
23-- |
@@ -40,7 +47,7 @@ printModuleSignatures moduleName P.Environment{..} =
40 findNameType envNames m = (P.disqualify m, M.lookup m envNames)
47 findNameType envNames m = (P.disqualify m, M.lookup m envNames)
41
48
42 showNameType :: (P.Ident, Maybe (P.Type, P.NameKind, P.NameVisibility)) -> Box.Box
49 showNameType :: (P.Ident, Maybe (P.Type, P.NameKind, P.NameVisibility)) -> Box.Box
43− showNameType (mIdent, Just (mType, _, _)) = Box.text (P.showIdent mIdent ++ " :: ") Box.<> P.typeAsBox mType
50+ showNameType (mIdent, Just (mType, _, _)) = textT (P.showIdent mIdent <> " :: ") Box.<> P.typeAsBox mType
44 showNameType _ = P.internalError "The impossible happened in printModuleSignatures."
51 showNameType _ = P.internalError "The impossible happened in printModuleSignatures."
45
52
46 findTypeClass
53 findTypeClass
@@ -58,13 +65,13 @@ printModuleSignatures moduleName P.Environment{..} =
58 if null typeClassSuperclasses
65 if null typeClassSuperclasses
59 then Box.text ""
66 then Box.text ""
60 else Box.text "("
67 else Box.text "("
61− Box.<> Box.hcat Box.left (intersperse (Box.text ", ") $ map (\(P.Constraint (P.Qualified _ pn) lt _) -> Box.text (P.runProperName pn) Box.<+> Box.hcat Box.left (map P.typeAtomAsBox lt)) typeClassSuperclasses)
68+ Box.<> Box.hcat Box.left (intersperse (Box.text ", ") $ map (\(P.Constraint (P.Qualified _ pn) lt _) -> textT (P.runProperName pn) Box.<+> Box.hcat Box.left (map P.typeAtomAsBox lt)) typeClassSuperclasses)
62 Box.<> Box.text ") <= "
69 Box.<> Box.text ") <= "
63 className =
70 className =
64− Box.text (P.runProperName name)
71+ textT (P.runProperName name)
65− Box.<> Box.text (concatMap ((' ':) . fst) typeClassArguments)
72+ Box.<> textT (foldMap ((" " <>) . fst) typeClassArguments)
66 classBody =
73 classBody =
67− Box.vcat Box.top (map (\(i, t) -> Box.text (P.showIdent i ++ " ::") Box.<+> P.typeAsBox t) typeClassMembers)
74+ Box.vcat Box.top (map (\(i, t) -> textT (P.showIdent i <> " ::") Box.<+> P.typeAsBox t) typeClassMembers)
68
75
69 in
76 in
70 Just $
77 Just $
@@ -84,7 +91,7 @@ printModuleSignatures moduleName P.Environment{..} =
84 showType
91 showType
85 :: M.Map (P.Qualified (P.ProperName 'P.ClassName)) P.TypeClassData
92 :: M.Map (P.Qualified (P.ProperName 'P.ClassName)) P.TypeClassData
86 -> M.Map (P.Qualified (P.ProperName 'P.ConstructorName)) (P.DataDeclType, P.ProperName 'P.TypeName, P.Type, [P.Ident])
93 -> M.Map (P.Qualified (P.ProperName 'P.ConstructorName)) (P.DataDeclType, P.ProperName 'P.TypeName, P.Type, [P.Ident])
87− -> M.Map (P.Qualified (P.ProperName 'P.TypeName)) ([(String, Maybe P.Kind)], P.Type)
94+ -> M.Map (P.Qualified (P.ProperName 'P.TypeName)) ([(Text, Maybe P.Kind)], P.Type)
88 -> (P.Qualified (P.ProperName 'P.TypeName), Maybe (P.Kind, P.TypeKind))
95 -> (P.Qualified (P.ProperName 'P.TypeName), Maybe (P.Kind, P.TypeKind))
89 -> Maybe Box.Box
96 -> Maybe Box.Box
90 showType typeClassesEnv dataConstructorsEnv typeSynonymsEnv (n@(P.Qualified modul name), typ) =
97 showType typeClassesEnv dataConstructorsEnv typeSynonymsEnv (n@(P.Qualified modul name), typ) =
@@ -95,7 +102,7 @@ printModuleSignatures moduleName P.Environment{..} =
95 Nothing
102 Nothing
96 else
103 else
97 Just $
104 Just $
98− Box.text ("type " ++ P.runProperName name ++ concatMap ((' ':) . fst) typevars)
105+ textT ("type " <> P.runProperName name <> foldMap ((" " <>) . fst) typevars)
99 Box.// Box.moveRight 2 (Box.text "=" Box.<+> P.typeAsBox dtType)
106 Box.// Box.moveRight 2 (Box.text "=" Box.<+> P.typeAsBox dtType)
100
107
101 (Just (_, P.DataType typevars pt), _) ->
108 (Just (_, P.DataType typevars pt), _) ->
@@ -108,7 +115,7 @@ printModuleSignatures moduleName P.Environment{..} =
108 _ -> "data"
115 _ -> "data"
109
116
110 in
117 in
111− Just $ Box.text (prefix ++ " " ++ P.runProperName name ++ concatMap ((' ':) . fst) typevars) Box.// printCons pt
118+ Just $ textT (prefix <> " " <> P.runProperName name <> foldMap ((" " <>) . fst) typevars) Box.// printCons pt
112
119
113 _ ->
120 _ ->
114 Nothing
121 Nothing
@@ -117,7 +124,7 @@ printModuleSignatures moduleName P.Environment{..} =
117 Box.moveRight 2 $
124 Box.moveRight 2 $
118 Box.vcat Box.left $
125 Box.vcat Box.left $
119 mapFirstRest (Box.text "=" Box.<+>) (Box.text "|" Box.<+>) $
126 mapFirstRest (Box.text "=" Box.<+>) (Box.text "|" Box.<+>) $
120− map (\(cons,idents) -> (Box.text (P.runProperName cons) Box.<> Box.hcat Box.left (map prettyPrintType idents))) pt
127+ map (\(cons,idents) -> (textT (P.runProperName cons) Box.<> Box.hcat Box.left (map prettyPrintType idents))) pt
121
128
122 prettyPrintType t = Box.text " " Box.<> P.typeAtomAsBox t
129 prettyPrintType t = Box.text " " Box.<> P.typeAtomAsBox t
123
130
src/Language/PureScript/Linter.hs+4−3
@@ -11,6 +11,7 @@ import Data.List (nub, (\\))
11import Data.Maybe (mapMaybe)
11import Data.Maybe (mapMaybe)
12import Data.Monoid
12import Data.Monoid
13import qualified Data.Set as S
13import qualified Data.Set as S
14+import Data.Text (Text)
14
15
15import Language.PureScript.AST
16import Language.PureScript.AST
16import Language.PureScript.Crash
17import Language.PureScript.Crash
@@ -81,10 +82,10 @@ lint (Module _ _ mn ds _) = censor (addHint (ErrorInModule mn)) $ mapM_ lintDecl
81 checkTypeVars :: S.Set String -> Type -> MultipleErrors
82 checkTypeVars :: S.Set String -> Type -> MultipleErrors
82 checkTypeVars set ty = everythingWithContextOnTypes set mempty mappend step ty <> findUnused ty
83 checkTypeVars set ty = everythingWithContextOnTypes set mempty mappend step ty <> findUnused ty
83 where
84 where
84− step :: S.Set String -> Type -> (S.Set String, MultipleErrors)
85+ step :: S.Set Text -> Type -> (S.Set Text, MultipleErrors)
85 step s (ForAll tv _ _) = bindVar s tv
86 step s (ForAll tv _ _) = bindVar s tv
86 step s _ = (s, mempty)
87 step s _ = (s, mempty)
87− bindVar :: S.Set String -> String -> (S.Set String, MultipleErrors)
88+ bindVar :: S.Set Text -> Text -> (S.Set Text, MultipleErrors)
88 bindVar = bind ShadowedTypeVar
89 bindVar = bind ShadowedTypeVar
89 findUnused :: Type -> MultipleErrors
90 findUnused :: Type -> MultipleErrors
90 findUnused ty' =
91 findUnused ty' =
@@ -93,7 +94,7 @@ lint (Module _ _ mn ds _) = censor (addHint (ErrorInModule mn)) $ mapM_ lintDecl
93 unused = nub declared \\ nub used
94 unused = nub declared \\ nub used
94 in foldl (<>) mempty $ map (errorMessage . UnusedTypeVar) unused
95 in foldl (<>) mempty $ map (errorMessage . UnusedTypeVar) unused
95 where
96 where
96− go :: Type -> [String]
97+ go :: Type -> [Text]
97 go (ForAll tv _ _) = [tv]
98 go (ForAll tv _ _) = [tv]
98 go _ = []
99 go _ = []
99
100
src/Language/PureScript/Linter/Exhaustive.hs+7−4
@@ -19,7 +19,10 @@ import Control.Monad.Supply.Class (MonadSupply, fresh, freshName)
19import Data.Function (on)
19import Data.Function (on)
20import Data.List (foldl', sortBy, nub)
20import Data.List (foldl', sortBy, nub)
21import Data.Maybe (fromMaybe)
21import Data.Maybe (fromMaybe)
22+import Data.Monoid ((<>))
22import qualified Data.Map as M
23import qualified Data.Map as M
24+import Data.Text (Text)
25+import qualified Data.Text as T
23
26
24import Language.PureScript.AST.Binders
27import Language.PureScript.AST.Binders
25import Language.PureScript.AST.Declarations
28import Language.PureScript.AST.Declarations
@@ -77,7 +80,7 @@ getConstructors env defmn n = extractConstructors lnte
77 getConsDataName :: Qualified (ProperName 'ConstructorName) -> Qualified (ProperName 'TypeName)
80 getConsDataName :: Qualified (ProperName 'ConstructorName) -> Qualified (ProperName 'TypeName)
78 getConsDataName con =
81 getConsDataName con =
79 case getConsInfo con of
82 case getConsInfo con of
80− Nothing -> internalError $ "Constructor " ++ showQualified runProperName con ++ " not in the scope of the current environment in getConsDataName."
83+ Nothing -> internalError $ "Constructor " ++ T.unpack (showQualified runProperName con) ++ " not in the scope of the current environment in getConsDataName."
81 Just (_, pm, _, _) -> qualifyName pm defmn con
84 Just (_, pm, _, _) -> qualifyName pm defmn con
82
85
83 getConsInfo :: Qualified (ProperName 'ConstructorName) -> Maybe (DataDeclType, ProperName 'TypeName, Type, [Ident])
86 getConsInfo :: Qualified (ProperName 'ConstructorName) -> Maybe (DataDeclType, ProperName 'TypeName, Type, [Ident])
@@ -276,14 +279,14 @@ checkExhaustive env mn numArgs cas expr = makeResult . first nub $ foldl' step (
276 -- and then included in the error message.
279 -- and then included in the error message.
277 addPartialConstraint :: ([[Binder]], Bool) -> Expr -> m Expr
280 addPartialConstraint :: ([[Binder]], Bool) -> Expr -> m Expr
278 addPartialConstraint (bss, complete) e = do
281 addPartialConstraint (bss, complete) e = do
279− tyVar <- ("p" ++) . show <$> fresh
282+ tyVar <- ("p" <>) . T.pack . show <$> fresh
280 var <- freshName
283 var <- freshName
281 return $
284 return $
282 Let
285 Let
283 [ partial var tyVar ]
286 [ partial var tyVar ]
284 $ App (Var (Qualified Nothing (Ident C.__unused))) e
287 $ App (Var (Qualified Nothing (Ident C.__unused))) e
285 where
288 where
286− partial :: String -> String -> Declaration
289+ partial :: Text -> Text -> Declaration
287 partial var tyVar =
290 partial var tyVar =
288 ValueDeclaration (Ident C.__unused) Private [] $ Right $
291 ValueDeclaration (Ident C.__unused) Private [] $ Right $
289 TypedValue
292 TypedValue
@@ -291,7 +294,7 @@ checkExhaustive env mn numArgs cas expr = makeResult . first nub $ foldl' step (
291 (Abs (Left (Ident var)) (Var (Qualified Nothing (Ident var))))
294 (Abs (Left (Ident var)) (Var (Qualified Nothing (Ident var))))
292 (ty tyVar)
295 (ty tyVar)
293
296
294− ty :: String -> Type
297+ ty :: Text -> Type
295 ty tyVar =
298 ty tyVar =
296 ForAll tyVar
299 ForAll tyVar
297 ( ConstrainedType
300 ( ConstrainedType
src/Language/PureScript/Linter/Imports.hs+3−2
@@ -15,6 +15,7 @@ import Data.List (find, intersect, nub, groupBy, sortBy, (\\))
15import Data.Maybe (mapMaybe, fromMaybe)
15import Data.Maybe (mapMaybe, fromMaybe)
16import Data.Monoid (Sum(..))
16import Data.Monoid (Sum(..))
17import Data.Traversable (forM)
17import Data.Traversable (forM)
18+import qualified Data.Text as T
18import qualified Data.Map as M
19import qualified Data.Map as M
19
20
20import Language.PureScript.AST.Declarations
21import Language.PureScript.AST.Declarations
@@ -329,8 +330,8 @@ findUsedRefs env mni qn names =
329 Just (_, _, exps) ->
330 Just (_, _, exps) ->
330 case find (elem dctor . fst . snd) (M.toList (exportedTypes exps)) of
331 case find (elem dctor . fst . snd) (M.toList (exportedTypes exps)) of
331 Just (ty, _) -> ty
332 Just (ty, _) -> ty
332− Nothing -> internalError $ "missing type for data constructor " ++ runProperName dctor ++ " in findTypeForDctor"
333+ Nothing -> internalError $ "missing type for data constructor " ++ T.unpack (runProperName dctor) ++ " in findTypeForDctor"
333− Nothing -> internalError $ "missing module " ++ runModuleName mn ++ " in findTypeForDctor"
334+ Nothing -> internalError $ "missing module " ++ T.unpack (runModuleName mn) ++ " in findTypeForDctor"
334
335
335matchName
336matchName
336 :: (ProperName 'ConstructorName -> Maybe (ProperName 'TypeName))
337 :: (ProperName 'ConstructorName -> Maybe (ProperName 'TypeName))
src/Language/PureScript/Make.hs+26−26
@@ -38,13 +38,12 @@ import Control.Monad.Writer.Class (MonadWriter(..))
38
38
39import Data.Aeson (encode, decode)
39import Data.Aeson (encode, decode)
40import qualified Data.Aeson as Aeson
40import qualified Data.Aeson as Aeson
41−import Data.ByteString.Builder (toLazyByteString, stringUtf8)
42import Data.Either (partitionEithers)
41import Data.Either (partitionEithers)
43import Data.Function (on)
42import Data.Function (on)
44import Data.Foldable (for_)
43import Data.Foldable (for_)
45import Data.List (foldl', sortBy, groupBy)
44import Data.List (foldl', sortBy, groupBy)
46import Data.Maybe (fromMaybe, catMaybes)
45import Data.Maybe (fromMaybe, catMaybes)
47−import Data.String (fromString)
46+import Data.Monoid ((<>))
48import Data.Time.Clock
47import Data.Time.Clock
49import Data.Traversable (for)
48import Data.Traversable (for)
50import Data.Version (showVersion)
49import Data.Version (showVersion)
@@ -52,6 +51,8 @@ import qualified Data.ByteString.Lazy as B
52import qualified Data.ByteString.UTF8 as BU8
51import qualified Data.ByteString.UTF8 as BU8
53import qualified Data.Map as M
52import qualified Data.Map as M
54import qualified Data.Set as S
53import qualified Data.Set as S
54+import qualified Data.Text as T
55+import qualified Data.Text.Encoding as TE
55
56
56import Language.PureScript.AST
57import Language.PureScript.AST
57import Language.PureScript.Crash
58import Language.PureScript.Crash
@@ -83,7 +84,6 @@ import SourceMap.Types
83import System.Directory (doesFileExist, getModificationTime, createDirectoryIfMissing, getCurrentDirectory)
84import System.Directory (doesFileExist, getModificationTime, createDirectoryIfMissing, getCurrentDirectory)
84import System.FilePath ((</>), takeDirectory, makeRelative, splitPath, normalise, replaceExtension)
85import System.FilePath ((</>), takeDirectory, makeRelative, splitPath, normalise, replaceExtension)
85import System.IO.Error (tryIOError)
86import System.IO.Error (tryIOError)
86−import System.IO.UTF8 (readUTF8File, writeUTF8File)
87
87
88import qualified Text.Parsec as Parsec
88import qualified Text.Parsec as Parsec
89
89
@@ -94,7 +94,7 @@ data ProgressMessage
94
94
95-- | Render a progress message
95-- | Render a progress message
96renderProgressMessage :: ProgressMessage -> String
96renderProgressMessage :: ProgressMessage -> String
97−renderProgressMessage (CompilingModule mn) = "Compiling " ++ runModuleName mn
97+renderProgressMessage (CompilingModule mn) = "Compiling " ++ T.unpack (runModuleName mn)
98
98
99-- | Actions that require implementations when running in "make" mode.
99-- | Actions that require implementations when running in "make" mode.
100--
100--
@@ -125,7 +125,7 @@ data MakeActions m = MakeActions
125-- |
125-- |
126-- Generated code for an externs file.
126-- Generated code for an externs file.
127--
127--
128−type Externs = String
128+type Externs = B.ByteString
129
129
130-- |
130-- |
131-- Determines when to rebuild a module
131-- Determines when to rebuild a module
@@ -155,7 +155,7 @@ rebuildModule MakeActions{..} externs m@(Module _ _ moduleName _ _) = do
155 corefn = CF.moduleToCoreFn env' mod'
155 corefn = CF.moduleToCoreFn env' mod'
156 [renamed] = renameInModules [corefn]
156 [renamed] = renameInModules [corefn]
157 exts = moduleToExternsFile mod' env'
157 exts = moduleToExternsFile mod' env'
158− evalSupplyT nextVar . codegen renamed env' . BU8.toString . B.toStrict . encode $ exts
158+ evalSupplyT nextVar . codegen renamed env' . encode $ exts
159 return exts
159 return exts
160
160
161-- |
161-- |
@@ -256,8 +256,8 @@ make ma@MakeActions{..} ms = do
256
256
257 decodeExterns :: Externs -> Maybe ExternsFile
257 decodeExterns :: Externs -> Maybe ExternsFile
258 decodeExterns bs = do
258 decodeExterns bs = do
259− externs <- decode (toLazyByteString (stringUtf8 bs))
259+ externs <- decode bs
260− guard $ efVersion externs == showVersion Paths.version
260+ guard $ T.unpack (efVersion externs) == showVersion Paths.version
261 return externs
261 return externs
262
262
263importPrim :: Module -> Module
263importPrim :: Module -> Module
@@ -290,8 +290,8 @@ makeIO f io = do
290
290
291-- | Read a text file in the 'Make' monad, capturing any errors using the
291-- | Read a text file in the 'Make' monad, capturing any errors using the
292-- 'MonadError' instance.
292-- 'MonadError' instance.
293−readTextFile :: FilePath -> Make String
293+readTextFile :: FilePath -> Make B.ByteString
294−readTextFile path = makeIO (const (ErrorMessage [] $ CannotReadFile path)) $ readUTF8File path
294+readTextFile path = makeIO (const (ErrorMessage [] $ CannotReadFile path)) $ B.readFile path
295
295
296-- | Infer the module name for a module by looking for the same filename with
296-- | Infer the module name for a module by looking for the same filename with
297-- a .js extension.
297-- a .js extension.
@@ -332,14 +332,14 @@ buildMakeActions outputDir filePathMap foreigns usePrefix =
332
332
333 getOutputTimestamp :: ModuleName -> Make (Maybe UTCTime)
333 getOutputTimestamp :: ModuleName -> Make (Maybe UTCTime)
334 getOutputTimestamp mn = do
334 getOutputTimestamp mn = do
335− let filePath = runModuleName mn
335+ let filePath = T.unpack (runModuleName mn)
336 jsFile = outputDir </> filePath </> "index.js"
336 jsFile = outputDir </> filePath </> "index.js"
337 externsFile = outputDir </> filePath </> "externs.json"
337 externsFile = outputDir </> filePath </> "externs.json"
338 min <$> getTimestamp jsFile <*> getTimestamp externsFile
338 min <$> getTimestamp jsFile <*> getTimestamp externsFile
339
339
340 readExterns :: ModuleName -> Make (FilePath, Externs)
340 readExterns :: ModuleName -> Make (FilePath, Externs)
341 readExterns mn = do
341 readExterns mn = do
342− let path = outputDir </> runModuleName mn </> "externs.json"
342+ let path = outputDir </> T.unpack (runModuleName mn) </> "externs.json"
343 (path, ) <$> readTextFile path
343 (path, ) <$> readTextFile path
344
344
345 codegen :: CF.Module CF.Ann -> Environment -> Externs -> SupplyT Make ()
345 codegen :: CF.Module CF.Ann -> Environment -> Externs -> SupplyT Make ()
@@ -359,16 +359,16 @@ buildMakeActions outputDir filePathMap foreigns usePrefix =
359 dir <- lift $ makeIO (const (ErrorMessage [] $ CannotGetFileInfo ".")) getCurrentDirectory
359 dir <- lift $ makeIO (const (ErrorMessage [] $ CannotGetFileInfo ".")) getCurrentDirectory
360 sourceMaps <- lift $ asks optionsSourceMaps
360 sourceMaps <- lift $ asks optionsSourceMaps
361 let (pjs, mappings) = if sourceMaps then prettyPrintJSWithSourceMaps rawJs else (prettyPrintJS rawJs, [])
361 let (pjs, mappings) = if sourceMaps then prettyPrintJSWithSourceMaps rawJs else (prettyPrintJS rawJs, [])
362− let filePath = runModuleName mn
362+ let filePath = T.unpack (runModuleName mn)
363 jsFile = outputDir </> filePath </> "index.js"
363 jsFile = outputDir </> filePath </> "index.js"
364 mapFile = outputDir </> filePath </> "index.js.map"
364 mapFile = outputDir </> filePath </> "index.js.map"
365 externsFile = outputDir </> filePath </> "externs.json"
365 externsFile = outputDir </> filePath </> "externs.json"
366 foreignFile = outputDir </> filePath </> "foreign.js"
366 foreignFile = outputDir </> filePath </> "foreign.js"
367− prefix = ["Generated by psc version " ++ showVersion Paths.version | usePrefix]
367+ prefix = ["Generated by psc version " <> T.pack (showVersion Paths.version) | usePrefix]
368− js = unlines $ map ("// " ++) prefix ++ [pjs]
368+ js = T.unlines $ map ("// " <>) prefix ++ [pjs]
369 mapRef = if sourceMaps then "//# sourceMappingURL=index.js.map\n" else ""
369 mapRef = if sourceMaps then "//# sourceMappingURL=index.js.map\n" else ""
370 lift $ do
370 lift $ do
371− writeTextFile jsFile (fromString $ js ++ mapRef)
371+ writeTextFile jsFile (B.fromStrict $ TE.encodeUtf8 $ js <> mapRef)
372 for_ (mn `M.lookup` foreigns) (readTextFile >=> writeTextFile foreignFile)
372 for_ (mn `M.lookup` foreigns) (readTextFile >=> writeTextFile foreignFile)
373 writeTextFile externsFile exts
373 writeTextFile externsFile exts
374 lift $ when sourceMaps $ genSourceMap dir mapFile (length prefix) mappings
374 lift $ when sourceMaps $ genSourceMap dir mapFile (length prefix) mappings
@@ -376,14 +376,14 @@ buildMakeActions outputDir filePathMap foreigns usePrefix =
376 when dumpCoreFn $ do
376 when dumpCoreFn $ do
377 let coreFnFile = outputDir </> filePath </> "corefn.json"
377 let coreFnFile = outputDir </> filePath </> "corefn.json"
378 let jsonPayload = CFJ.moduleToJSON Paths.version m
378 let jsonPayload = CFJ.moduleToJSON Paths.version m
379− let json = Aeson.object [ (fromString (runModuleName mn), jsonPayload) ]
379+ let json = Aeson.object [ (runModuleName mn, jsonPayload) ]
380− lift $ writeTextFile coreFnFile (BU8.toString . B.toStrict . encode $ json)
380+ lift $ writeTextFile coreFnFile (encode json)
381
381
382 genSourceMap :: String -> String -> Int -> [SMap] -> Make ()
382 genSourceMap :: String -> String -> Int -> [SMap] -> Make ()
383 genSourceMap dir mapFile extraLines mappings = do
383 genSourceMap dir mapFile extraLines mappings = do
384 let pathToDir = iterate (".." </>) ".." !! length (splitPath $ normalise outputDir)
384 let pathToDir = iterate (".." </>) ".." !! length (splitPath $ normalise outputDir)
385 sourceFile = case mappings of
385 sourceFile = case mappings of
386− (SMap file _ _ : _) -> Just $ pathToDir </> makeRelative dir file
386+ (SMap file _ _ : _) -> Just $ pathToDir </> makeRelative dir (T.unpack file)
387 _ -> Nothing
387 _ -> Nothing
388 let rawMapping = SourceMapping { smFile = "index.js", smSourceRoot = Nothing, smMappings =
388 let rawMapping = SourceMapping { smFile = "index.js", smSourceRoot = Nothing, smMappings =
389 map (\(SMap _ orig gen) -> Mapping {
389 map (\(SMap _ orig gen) -> Mapping {
@@ -394,7 +394,7 @@ buildMakeActions outputDir filePathMap foreigns usePrefix =
394 }) mappings
394 }) mappings
395 }
395 }
396 let mapping = generate rawMapping
396 let mapping = generate rawMapping
397− writeTextFile mapFile $ BU8.toString . B.toStrict . encode $ mapping
397+ writeTextFile mapFile (encode mapping)
398 where
398 where
399 add :: Int -> Int -> SourcePos -> SourcePos
399 add :: Int -> Int -> SourcePos -> SourcePos
400 add n m (SourcePos n' m') = SourcePos (n+n') (m+m')
400 add n m (SourcePos n' m') = SourcePos (n+n') (m+m')
@@ -411,10 +411,10 @@ buildMakeActions outputDir filePathMap foreigns usePrefix =
411 exists <- doesFileExist path
411 exists <- doesFileExist path
412 traverse (const $ getModificationTime path) $ guard exists
412 traverse (const $ getModificationTime path) $ guard exists
413
413
414− writeTextFile :: FilePath -> String -> Make ()
414+ writeTextFile :: FilePath -> B.ByteString -> Make ()
415 writeTextFile path text = makeIO (const (ErrorMessage [] $ CannotWriteFile path)) $ do
415 writeTextFile path text = makeIO (const (ErrorMessage [] $ CannotWriteFile path)) $ do
416 mkdirp path
416 mkdirp path
417− writeUTF8File path text
417+ B.writeFile path text
418 where
418 where
419 mkdirp :: FilePath -> IO ()
419 mkdirp :: FilePath -> IO ()
420 mkdirp = createDirectoryIfMissing True . takeDirectory
420 mkdirp = createDirectoryIfMissing True . takeDirectory
@@ -429,7 +429,7 @@ buildMakeActions outputDir filePathMap foreigns usePrefix =
429checkForeignDecls :: CF.Module ann -> FilePath -> SupplyT Make ()
429checkForeignDecls :: CF.Module ann -> FilePath -> SupplyT Make ()
430checkForeignDecls m path = do
430checkForeignDecls m path = do
431 jsStr <- lift $ readTextFile path
431 jsStr <- lift $ readTextFile path
432− js <- either (errorParsingModule . Bundle.UnableToParseModule) pure $ JS.parse jsStr path
432+ js <- either (errorParsingModule . Bundle.UnableToParseModule) pure $ JS.parse (BU8.toString (B.toStrict jsStr)) path
433
433
434 foreignIdentsStrs <- either errorParsingModule pure $ getExps js
434 foreignIdentsStrs <- either errorParsingModule pure $ getExps js
435 foreignIdents <- either
435 foreignIdents <- either
@@ -455,11 +455,11 @@ checkForeignDecls m path = do
455 errorParsingModule = throwError . errorMessage . ErrorParsingFFIModule path . Just
455 errorParsingModule = throwError . errorMessage . ErrorParsingFFIModule path . Just
456
456
457 getExps :: JS.JSAST -> Either Bundle.ErrorMessage [String]
457 getExps :: JS.JSAST -> Either Bundle.ErrorMessage [String]
458− getExps = Bundle.getExportedIdentifiers (runModuleName mname)
458+ getExps = Bundle.getExportedIdentifiers (T.unpack (runModuleName mname))
459
459
460 errorInvalidForeignIdentifiers :: [String] -> SupplyT Make a
460 errorInvalidForeignIdentifiers :: [String] -> SupplyT Make a
461 errorInvalidForeignIdentifiers =
461 errorInvalidForeignIdentifiers =
462− throwError . mconcat . map (errorMessage . InvalidFFIIdentifier mname)
462+ throwError . mconcat . map (errorMessage . InvalidFFIIdentifier mname . T.pack)
463
463
464 parseIdents :: [String] -> Either [String] [Ident]
464 parseIdents :: [String] -> Either [String] [Ident]
465 parseIdents strs =
465 parseIdents strs =
@@ -472,7 +472,7 @@ checkForeignDecls m path = do
472 -- We ignore the error message here, just being told it's an invalid
472 -- We ignore the error message here, just being told it's an invalid
473 -- identifier should be enough.
473 -- identifier should be enough.
474 parseIdent :: String -> Either String Ident
474 parseIdent :: String -> Either String Ident
475− parseIdent str = try str
475+ parseIdent str = try (T.pack str)
476 where
476 where
477 try s = either (const (Left str)) Right $ do
477 try s = either (const (Left str)) Right $ do
478 ts <- PSParser.lex "" s
478 ts <- PSParser.lex "" s
src/Language/PureScript/Names.hs+21−19
@@ -11,7 +11,9 @@ import Control.Monad.Supply.Class
11
11
12import Data.Aeson
12import Data.Aeson
13import Data.Aeson.TH
13import Data.Aeson.TH
14−import Data.List
14+import Data.Monoid ((<>))
15+import Data.Text (Text)
16+import qualified Data.Text as T
15
17
16-- | A sum of the possible name types, useful for error and lint messages.
18-- | A sum of the possible name types, useful for error and lint messages.
17data Name
19data Name
@@ -59,22 +61,22 @@ data Ident
59 -- |
61 -- |
60 -- An alphanumeric identifier
62 -- An alphanumeric identifier
61 --
63 --
62− = Ident String
64+ = Ident Text
63 -- |
65 -- |
64 -- A generated name for an identifier
66 -- A generated name for an identifier
65 --
67 --
66− | GenIdent (Maybe String) Integer
68+ | GenIdent (Maybe Text) Integer
67 deriving (Show, Eq, Ord)
69 deriving (Show, Eq, Ord)
68
70
69−runIdent :: Ident -> String
71+runIdent :: Ident -> Text
70runIdent (Ident i) = i
72runIdent (Ident i) = i
71−runIdent (GenIdent Nothing n) = "$" ++ show n
73+runIdent (GenIdent Nothing n) = "$" <> T.pack (show n)
72−runIdent (GenIdent (Just name) n) = "$" ++ name ++ show n
74+runIdent (GenIdent (Just name) n) = "$" <> name <> T.pack (show n)
73
75
74−showIdent :: Ident -> String
76+showIdent :: Ident -> Text
75showIdent = runIdent
77showIdent = runIdent
76
78
77−freshIdent :: MonadSupply m => String -> m Ident
79+freshIdent :: MonadSupply m => Text -> m Ident
78freshIdent name = GenIdent (Just name) <$> fresh
80freshIdent name = GenIdent (Just name) <$> fresh
79
81
80freshIdent' :: MonadSupply m => m Ident
82freshIdent' :: MonadSupply m => m Ident
@@ -83,7 +85,7 @@ freshIdent' = GenIdent Nothing <$> fresh
83-- |
85-- |
84-- Operator alias names.
86-- Operator alias names.
85--
87--
86−newtype OpName (a :: OpNameType) = OpName { runOpName :: String }
88+newtype OpName (a :: OpNameType) = OpName { runOpName :: Text }
87 deriving (Show, Eq, Ord)
89 deriving (Show, Eq, Ord)
88
90
89instance ToJSON (OpName a) where
91instance ToJSON (OpName a) where
@@ -92,8 +94,8 @@ instance ToJSON (OpName a) where
92instance FromJSON (OpName a) where
94instance FromJSON (OpName a) where
93 parseJSON = fmap OpName . parseJSON
95 parseJSON = fmap OpName . parseJSON
94
96
95−showOp :: OpName a -> String
97+showOp :: OpName a -> Text
96−showOp op = '(' : runOpName op ++ ")"
98+showOp op = "(" <> runOpName op <> ")"
97
99
98-- |
100-- |
99-- The closed set of operator alias types.
101-- The closed set of operator alias types.
@@ -103,7 +105,7 @@ data OpNameType = ValueOpName | TypeOpName
103-- |
105-- |
104-- Proper names, i.e. capitalized names for e.g. module names, type//data constructors.
106-- Proper names, i.e. capitalized names for e.g. module names, type//data constructors.
105--
107--
106−newtype ProperName (a :: ProperNameType) = ProperName { runProperName :: String }
108+newtype ProperName (a :: ProperNameType) = ProperName { runProperName :: Text }
107 deriving (Show, Eq, Ord)
109 deriving (Show, Eq, Ord)
108
110
109instance ToJSON (ProperName a) where
111instance ToJSON (ProperName a) where
@@ -131,16 +133,16 @@ coerceProperName = ProperName . runProperName
131newtype ModuleName = ModuleName [ProperName 'Namespace]
133newtype ModuleName = ModuleName [ProperName 'Namespace]
132 deriving (Show, Eq, Ord)
134 deriving (Show, Eq, Ord)
133
135
134−runModuleName :: ModuleName -> String
136+runModuleName :: ModuleName -> Text
135−runModuleName (ModuleName pns) = intercalate "." (runProperName `map` pns)
137+runModuleName (ModuleName pns) = T.intercalate "." (runProperName <$> pns)
136
138
137−moduleNameFromString :: String -> ModuleName
139+moduleNameFromString :: Text -> ModuleName
138moduleNameFromString = ModuleName . splitProperNames
140moduleNameFromString = ModuleName . splitProperNames
139 where
141 where
140− splitProperNames s = case dropWhile (== '.') s of
142+ splitProperNames s = case T.dropWhile (== '.') s of
141 "" -> []
143 "" -> []
142 s' -> ProperName w : splitProperNames s''
144 s' -> ProperName w : splitProperNames s''
143− where (w, s'') = break (== '.') s'
145+ where (w, s'') = T.break (== '.') s'
144
146
145-- |
147-- |
146-- A qualified name, i.e. a name with an optional module name
148-- A qualified name, i.e. a name with an optional module name
@@ -148,9 +150,9 @@ moduleNameFromString = ModuleName . splitProperNames
148data Qualified a = Qualified (Maybe ModuleName) a
150data Qualified a = Qualified (Maybe ModuleName) a
149 deriving (Show, Eq, Ord, Functor)
151 deriving (Show, Eq, Ord, Functor)
150
152
151−showQualified :: (a -> String) -> Qualified a -> String
153+showQualified :: (a -> Text) -> Qualified a -> Text
152showQualified f (Qualified Nothing a) = f a
154showQualified f (Qualified Nothing a) = f a
153−showQualified f (Qualified (Just name) a) = runModuleName name ++ "." ++ f a
155+showQualified f (Qualified (Just name) a) = runModuleName name <> "." <> f a
154
156
155getQual :: Qualified a -> Maybe ModuleName
157getQual :: Qualified a -> Maybe ModuleName
156getQual (Qualified mn _) = mn
158getQual (Qualified mn _) = mn
src/Language/PureScript/Parser/Common.hs+12−9
@@ -5,8 +5,11 @@ module Language.PureScript.Parser.Common where
5
5
6import Prelude.Compat
6import Prelude.Compat
7
7
8−import Control.Applicative
8+import Control.Applicative ((<|>))
9import Control.Monad (guard)
9import Control.Monad (guard)
10+import Data.Monoid ((<>))
11+import Data.Text (Text)
12+import qualified Data.Text as T
10
13
11import Language.PureScript.AST.SourcePos
14import Language.PureScript.AST.SourcePos
12import Language.PureScript.Comments
15import Language.PureScript.Comments
@@ -79,8 +82,8 @@ augment p q f = flip (maybe id $ flip f) <$> p <*> P.optionMaybe q
79-- Run the first parser, then match the second zero or more times, applying the specified function for each match
82-- Run the first parser, then match the second zero or more times, applying the specified function for each match
80--
83--
81fold :: P.ParsecT s u m a -> P.ParsecT s u m b -> (a -> b -> a) -> P.ParsecT s u m a
84fold :: P.ParsecT s u m a -> P.ParsecT s u m b -> (a -> b -> a) -> P.ParsecT s u m a
82−fold first more combine = do
85+fold first' more combine = do
83− a <- first
86+ a <- first'
84 bs <- P.many more
87 bs <- P.many more
85 return $ foldl combine a bs
88 return $ foldl combine a bs
86
89
@@ -88,8 +91,8 @@ fold first more combine = do
88-- Build a parser from a smaller parser and a list of parsers for postfix operators
91-- Build a parser from a smaller parser and a list of parsers for postfix operators
89--
92--
90buildPostfixParser :: P.Stream s m t => [a -> P.ParsecT s u m a] -> P.ParsecT s u m a -> P.ParsecT s u m a
93buildPostfixParser :: P.Stream s m t => [a -> P.ParsecT s u m a] -> P.ParsecT s u m a -> P.ParsecT s u m a
91−buildPostfixParser fs first = do
94+buildPostfixParser fs first' = do
92− a <- first
95+ a <- first'
93 go a
96 go a
94 where
97 where
95 go a = do
98 go a = do
@@ -114,25 +117,25 @@ mark p = do
114-- Check that the current identation level matches a predicate
117-- Check that the current identation level matches a predicate
115--
118--
116checkIndentation
119checkIndentation
117− :: (P.Column -> String)
120+ :: (P.Column -> Text)
118 -> (P.Column -> P.Column -> Bool)
121 -> (P.Column -> P.Column -> Bool)
119 -> P.Parsec s ParseState ()
122 -> P.Parsec s ParseState ()
120checkIndentation mkMsg rel = do
123checkIndentation mkMsg rel = do
121 col <- P.sourceColumn <$> P.getPosition
124 col <- P.sourceColumn <$> P.getPosition
122 current <- indentationLevel <$> P.getState
125 current <- indentationLevel <$> P.getState
123− guard (col `rel` current) P.<?> mkMsg current
126+ guard (col `rel` current) P.<?> T.unpack (mkMsg current)
124
127
125-- |
128-- |
126-- Check that the current indentation level is past the current mark
129-- Check that the current indentation level is past the current mark
127--
130--
128indented :: P.Parsec s ParseState ()
131indented :: P.Parsec s ParseState ()
129−indented = checkIndentation (("indentation past column " ++) . show) (>)
132+indented = checkIndentation (("indentation past column " <>) . (T.pack . show)) (>)
130
133
131-- |
134-- |
132-- Check that the current indentation level is at the same indentation as the current mark
135-- Check that the current indentation level is at the same indentation as the current mark
133--
136--
134same :: P.Parsec s ParseState ()
137same :: P.Parsec s ParseState ()
135−same = checkIndentation (("indentation at column " ++) . show) (==)
138+same = checkIndentation (("indentation at column " <>) . (T.pack . show)) (==)
136
139
137-- |
140-- |
138-- Read the comments from the the next token, without consuming it
141-- Read the comments from the the next token, without consuming it
src/Language/PureScript/Parser/Declarations.hs+6−6
@@ -61,7 +61,7 @@ withSourceSpan f p = do
61 let sp = SourceSpan (P.sourceName start) (C.toSourcePos start) (C.toSourcePos $ fromMaybe end end')
61 let sp = SourceSpan (P.sourceName start) (C.toSourcePos start) (C.toSourcePos $ fromMaybe end end')
62 return $ f sp comments x
62 return $ f sp comments x
63
63
64−kindedIdent :: TokenParser (String, Maybe Kind)
64+kindedIdent :: TokenParser (Text, Maybe Kind)
65kindedIdent = (, Nothing) <$> identifier
65kindedIdent = (, Nothing) <$> identifier
66 <|> parens ((,) <$> identifier <*> (Just <$> (indented *> doubleColon *> indented *> parseKind)))
66 <|> parens ((,) <$> identifier <*> (Just <$> (indented *> doubleColon *> indented *> parseKind)))
67
67
@@ -303,7 +303,7 @@ parseModuleFromFile
303 -> Either P.ParseError (k, Module)
303 -> Either P.ParseError (k, Module)
304parseModuleFromFile toFilePath (k, content) = do
304parseModuleFromFile toFilePath (k, content) = do
305 let filename = toFilePath k
305 let filename = toFilePath k
306− ts <- lex' filename content
306+ ts <- lex filename content
307 m <- runTokenParser filename parseModule ts
307 m <- runTokenParser filename parseModule ts
308 pure (k, m)
308 pure (k, m)
309
309
@@ -333,10 +333,10 @@ parseBooleanLiteral = BooleanLiteral <$> booleanLiteral
333parseArrayLiteral :: TokenParser a -> TokenParser (Literal a)
333parseArrayLiteral :: TokenParser a -> TokenParser (Literal a)
334parseArrayLiteral p = ArrayLiteral <$> squares (commaSep p)
334parseArrayLiteral p = ArrayLiteral <$> squares (commaSep p)
335
335
336−parseObjectLiteral :: TokenParser (String, a) -> TokenParser (Literal a)
336+parseObjectLiteral :: TokenParser (Text, a) -> TokenParser (Literal a)
337parseObjectLiteral p = ObjectLiteral <$> braces (commaSep p)
337parseObjectLiteral p = ObjectLiteral <$> braces (commaSep p)
338
338
339−parseIdentifierAndValue :: TokenParser (String, Expr)
339+parseIdentifierAndValue :: TokenParser (Text, Expr)
340parseIdentifierAndValue =
340parseIdentifierAndValue =
341 do
341 do
342 name <- C.indented *> lname
342 name <- C.indented *> lname
@@ -423,7 +423,7 @@ parseInfixExpr
423parseHole :: TokenParser Expr
423parseHole :: TokenParser Expr
424parseHole = Hole <$> holeLit
424parseHole = Hole <$> holeLit
425
425
426−parsePropertyUpdate :: TokenParser (String, Expr)
426+parsePropertyUpdate :: TokenParser (Text, Expr)
427parsePropertyUpdate = do
427parsePropertyUpdate = do
428 name <- lname <|> stringLiteral
428 name <- lname <|> stringLiteral
429 _ <- C.indented *> equals
429 _ <- C.indented *> equals
@@ -515,7 +515,7 @@ parseVarOrNamedBinder = do
515parseNullBinder :: TokenParser Binder
515parseNullBinder :: TokenParser Binder
516parseNullBinder = underscore *> return NullBinder
516parseNullBinder = underscore *> return NullBinder
517
517
518−parseIdentifierAndBinder :: TokenParser (String, Binder)
518+parseIdentifierAndBinder :: TokenParser (Text, Binder)
519parseIdentifierAndBinder =
519parseIdentifierAndBinder =
520 do name <- lname
520 do name <- lname
521 b <- P.option (VarBinder (Ident name)) rest
521 b <- P.option (VarBinder (Ident name)) rest
src/Language/PureScript/Parser/Lexer.hs+76−76
@@ -6,7 +6,6 @@ module Language.PureScript.Parser.Lexer
6 , Token()
6 , Token()
7 , TokenParser()
7 , TokenParser()
8 , lex
8 , lex
9− , lex'
10 , anyToken
9 , anyToken
11 , token
10 , token
12 , match
11 , match
@@ -63,13 +62,13 @@ module Language.PureScript.Parser.Lexer
63 )
62 )
64 where
63 where
65
64
66−import Prelude hiding (lex)
65+import Prelude.Compat hiding (lex)
67
66
68−import Control.Applicative
67+import Control.Applicative ((<|>))
69import Control.Monad (void, guard)
68import Control.Monad (void, guard)
70−
69+import Control.Monad.Identity (Identity)
71import Data.Char (isSpace, isAscii, isSymbol, isAlphaNum)
70import Data.Char (isSpace, isAscii, isSymbol, isAlphaNum)
72−import Data.Functor.Identity
71+import Data.Monoid ((<>))
73import Data.Text (Text)
72import Data.Text (Text)
74import qualified Data.Text as T
73import qualified Data.Text as T
75
74
@@ -101,17 +100,17 @@ data Token
101 | Semi
100 | Semi
102 | At
101 | At
103 | Underscore
102 | Underscore
104− | LName String
103+ | LName Text
105− | UName String
104+ | UName Text
106− | Qualifier String
105+ | Qualifier Text
107− | Symbol String
106+ | Symbol Text
108 | CharLiteral Char
107 | CharLiteral Char
109− | StringLiteral String
108+ | StringLiteral Text
110 | Number (Either Integer Double)
109 | Number (Either Integer Double)
111− | HoleLit String
110+ | HoleLit Text
112 deriving (Show, Eq, Ord)
111 deriving (Show, Eq, Ord)
113
112
114−prettyPrintToken :: Token -> String
113+prettyPrintToken :: Token -> Text
115prettyPrintToken LParen = "("
114prettyPrintToken LParen = "("
116prettyPrintToken RParen = ")"
115prettyPrintToken RParen = ")"
117prettyPrintToken LBrace = "{"
116prettyPrintToken LBrace = "{"
@@ -132,15 +131,15 @@ prettyPrintToken Comma = ","
132prettyPrintToken Semi = ";"
131prettyPrintToken Semi = ";"
133prettyPrintToken At = "@"
132prettyPrintToken At = "@"
134prettyPrintToken Underscore = "_"
133prettyPrintToken Underscore = "_"
135−prettyPrintToken (Indent n) = "indentation at level " ++ show n
134+prettyPrintToken (Indent n) = "indentation at level " <> T.pack (show n)
136−prettyPrintToken (LName s) = show s
135+prettyPrintToken (LName s) = T.pack (show s)
137−prettyPrintToken (UName s) = show s
136+prettyPrintToken (UName s) = T.pack (show s)
138prettyPrintToken (Qualifier _) = "qualifier"
137prettyPrintToken (Qualifier _) = "qualifier"
139prettyPrintToken (Symbol s) = s
138prettyPrintToken (Symbol s) = s
140−prettyPrintToken (CharLiteral c) = show c
139+prettyPrintToken (CharLiteral c) = T.pack (show c)
141−prettyPrintToken (StringLiteral s) = show s
140+prettyPrintToken (StringLiteral s) = T.pack (show s)
142−prettyPrintToken (Number n) = either show show n
141+prettyPrintToken (Number n) = T.pack (either show show n)
143−prettyPrintToken (HoleLit name) = "?" ++ name
142+prettyPrintToken (HoleLit name) = "?" <> name
144
143
145data PositionedToken = PositionedToken
144data PositionedToken = PositionedToken
146 { -- | Start position of this token
145 { -- | Start position of this token
@@ -155,15 +154,12 @@ data PositionedToken = PositionedToken
155
154
156-- Parsec requires this instance for various token-level combinators
155-- Parsec requires this instance for various token-level combinators
157instance Show PositionedToken where
156instance Show PositionedToken where
158− show = prettyPrintToken . ptToken
157+ show = T.unpack . prettyPrintToken . ptToken
159
158
160type Lexer u a = P.Parsec Text u a
159type Lexer u a = P.Parsec Text u a
161
160
162−lex :: FilePath -> String -> Either P.ParseError [PositionedToken]
163−lex fp = lex' fp . T.pack
164−
165−lex' :: FilePath -> Text -> Either P.ParseError [PositionedToken]
161+lex :: FilePath -> Text -> Either P.ParseError [PositionedToken]
166−lex' f s = updatePositions <$> P.parse parseTokens f s
162+lex f s = updatePositions <$> P.parse parseTokens f s
167
163
168updatePositions :: [PositionedToken] -> [PositionedToken]
164updatePositions :: [PositionedToken] -> [PositionedToken]
169updatePositions [] = []
165updatePositions [] = []
@@ -180,11 +176,11 @@ whitespace = P.skipMany (P.satisfy isSpace)
180parseComment :: Lexer u Comment
176parseComment :: Lexer u Comment
181parseComment = (BlockComment <$> blockComment <|> LineComment <$> lineComment) <* whitespace
177parseComment = (BlockComment <$> blockComment <|> LineComment <$> lineComment) <* whitespace
182 where
178 where
183− blockComment :: Lexer u String
179+ blockComment :: Lexer u Text
184− blockComment = P.try $ P.string "{-" *> P.manyTill P.anyChar (P.try (P.string "-}"))
180+ blockComment = P.try $ P.string "{-" *> (T.pack <$> P.manyTill P.anyChar (P.try (P.string "-}")))
185
181
186− lineComment :: Lexer u String
182+ lineComment :: Lexer u Text
187− lineComment = P.try $ P.string "--" *> P.manyTill P.anyChar (P.try (void (P.char '\n') <|> P.eof))
183+ lineComment = P.try $ P.string "--" *> (T.pack <$> P.manyTill P.anyChar (P.try (void (P.char '\n') <|> P.eof)))
188
184
189parsePositionedToken :: Lexer u PositionedToken
185parsePositionedToken :: Lexer u PositionedToken
190parsePositionedToken = P.try $ do
186parsePositionedToken = P.try $ do
@@ -222,11 +218,11 @@ parseToken = P.choice
222 , P.try $ P.char ';' *> P.notFollowedBy symbolChar *> pure Semi
218 , P.try $ P.char ';' *> P.notFollowedBy symbolChar *> pure Semi
223 , P.try $ P.char '@' *> P.notFollowedBy symbolChar *> pure At
219 , P.try $ P.char '@' *> P.notFollowedBy symbolChar *> pure At
224 , P.try $ P.char '_' *> P.notFollowedBy identLetter *> pure Underscore
220 , P.try $ P.char '_' *> P.notFollowedBy identLetter *> pure Underscore
225− , HoleLit <$> P.try (P.char '?' *> P.many1 identLetter)
221+ , HoleLit <$> P.try (P.char '?' *> (T.pack <$> P.many1 identLetter))
226 , LName <$> parseLName
222 , LName <$> parseLName
227 , parseUName >>= \uName ->
223 , parseUName >>= \uName ->
228− (guard (validModuleName uName) >> Qualifier uName <$ P.char '.')
224+ guard (validModuleName uName) *> (Qualifier uName <$ P.char '.')
229− <|> pure (UName uName)
225+ <|> pure (UName uName)
230 , Symbol <$> parseSymbol
226 , Symbol <$> parseSymbol
231 , CharLiteral <$> parseCharLiteral
227 , CharLiteral <$> parseCharLiteral
232 , StringLiteral <$> parseStringLiteral
228 , StringLiteral <$> parseStringLiteral
@@ -234,14 +230,14 @@ parseToken = P.choice
234 ]
230 ]
235
231
236 where
232 where
237− parseLName :: Lexer u String
233+ parseLName :: Lexer u Text
238− parseLName = (:) <$> identStart <*> P.many identLetter
234+ parseLName = T.cons <$> identStart <*> (T.pack <$> P.many identLetter)
239
235
240− parseUName :: Lexer u String
236+ parseUName :: Lexer u Text
241− parseUName = (:) <$> P.upper <*> P.many identLetter
237+ parseUName = T.cons <$> P.upper <*> (T.pack <$> P.many identLetter)
242
238
243− parseSymbol :: Lexer u String
239+ parseSymbol :: Lexer u Text
244− parseSymbol = P.many1 symbolChar
240+ parseSymbol = T.pack <$> P.many1 symbolChar
245
241
246 identStart :: Lexer u Char
242 identStart :: Lexer u Char
247 identStart = P.lower <|> P.oneOf "_"
243 identStart = P.lower <|> P.oneOf "_"
@@ -255,21 +251,21 @@ parseToken = P.choice
255 parseCharLiteral :: Lexer u Char
251 parseCharLiteral :: Lexer u Char
256 parseCharLiteral = PT.charLiteral tokenParser
252 parseCharLiteral = PT.charLiteral tokenParser
257
253
258− parseStringLiteral :: Lexer u String
254+ parseStringLiteral :: Lexer u Text
259− parseStringLiteral = blockString <|> PT.stringLiteral tokenParser
255+ parseStringLiteral = blockString <|> T.pack <$> PT.stringLiteral tokenParser
260 where
256 where
261 delimiter = P.try (P.string "\"\"\"")
257 delimiter = P.try (P.string "\"\"\"")
262− blockString = delimiter >> P.manyTill P.anyChar delimiter
258+ blockString = delimiter *> (T.pack <$> P.manyTill P.anyChar delimiter)
263
259
264 parseNumber :: Lexer u (Either Integer Double)
260 parseNumber :: Lexer u (Either Integer Double)
265− parseNumber = (consumeLeadingZero >> P.parserZero) <|>
261+ parseNumber = (consumeLeadingZero *> P.parserZero) <|>
266 (Right <$> P.try (PT.float tokenParser) <|>
262 (Right <$> P.try (PT.float tokenParser) <|>
267 Left <$> P.try (PT.natural tokenParser))
263 Left <$> P.try (PT.natural tokenParser))
268 P.<?> "number"
264 P.<?> "number"
269 where
265 where
270 -- lookAhead doesn't consume any input if its parser succeeds
266 -- lookAhead doesn't consume any input if its parser succeeds
271 -- if notFollowedBy fails though, the consumed '0' will break the choice chain
267 -- if notFollowedBy fails though, the consumed '0' will break the choice chain
272− consumeLeadingZero = P.lookAhead (P.char '0' >>
268+ consumeLeadingZero = P.lookAhead (P.char '0' *>
273 (P.notFollowedBy P.digit P.<?> "no leading zero in number literal"))
269 (P.notFollowedBy P.digit P.<?> "no leading zero in number literal"))
274
270
275-- |
271-- |
@@ -283,10 +279,10 @@ langDef = PT.LanguageDef
283 , PT.commentEnd = ""
279 , PT.commentEnd = ""
284 , PT.commentLine = ""
280 , PT.commentLine = ""
285 , PT.nestedComments = True
281 , PT.nestedComments = True
286− , PT.identStart = fail "Identifiers not supported"
282+ , PT.identStart = P.parserFail "Identifiers not supported"
287− , PT.identLetter = fail "Identifiers not supported"
283+ , PT.identLetter = P.parserFail "Identifiers not supported"
288− , PT.opStart = fail "Operators not supported"
284+ , PT.opStart = P.parserFail "Operators not supported"
289− , PT.opLetter = fail "Operators not supported"
285+ , PT.opLetter = P.parserFail "Operators not supported"
290 , PT.caseSensitive = True
286 , PT.caseSensitive = True
291 }
287 }
292
288
@@ -299,13 +295,13 @@ tokenParser = PT.makeTokenParser langDef
299type TokenParser a = P.Parsec [PositionedToken] ParseState a
295type TokenParser a = P.Parsec [PositionedToken] ParseState a
300
296
301anyToken :: TokenParser PositionedToken
297anyToken :: TokenParser PositionedToken
302−anyToken = P.token (prettyPrintToken . ptToken) ptSourcePos Just
298+anyToken = P.token (T.unpack . prettyPrintToken . ptToken) ptSourcePos Just
303
299
304token :: (Token -> Maybe a) -> TokenParser a
300token :: (Token -> Maybe a) -> TokenParser a
305−token f = P.token (prettyPrintToken . ptToken) ptSourcePos (f . ptToken)
301+token f = P.token (T.unpack . prettyPrintToken . ptToken) ptSourcePos (f . ptToken)
306
302
307match :: Token -> TokenParser ()
303match :: Token -> TokenParser ()
308−match tok = token (\tok' -> if tok == tok' then Just () else Nothing) P.<?> prettyPrintToken tok
304+match tok = token (\tok' -> if tok == tok' then Just () else Nothing) P.<?> T.unpack (prettyPrintToken tok)
309
305
310lparen :: TokenParser ()
306lparen :: TokenParser ()
311lparen = match LParen
307lparen = match LParen
@@ -388,7 +384,7 @@ at = match At
388underscore :: TokenParser ()
384underscore :: TokenParser ()
389underscore = match Underscore
385underscore = match Underscore
390
386
391−holeLit :: TokenParser String
387+holeLit :: TokenParser Text
392holeLit = token go P.<?> "hole literal"
388holeLit = token go P.<?> "hole literal"
393 where
389 where
394 go (HoleLit n) = Just n
390 go (HoleLit n) = Just n
@@ -418,62 +414,62 @@ commaSep = flip P.sepBy comma
418commaSep1 :: TokenParser a -> TokenParser [a]
414commaSep1 :: TokenParser a -> TokenParser [a]
419commaSep1 = flip P.sepBy1 comma
415commaSep1 = flip P.sepBy1 comma
420
416
421−lname :: TokenParser String
417+lname :: TokenParser Text
422lname = token go P.<?> "identifier"
418lname = token go P.<?> "identifier"
423 where
419 where
424 go (LName s) = Just s
420 go (LName s) = Just s
425 go _ = Nothing
421 go _ = Nothing
426
422
427−lname' :: String -> TokenParser ()
423+lname' :: Text -> TokenParser ()
428lname' s = token go P.<?> show s
424lname' s = token go P.<?> show s
429 where
425 where
430 go (LName s') | s == s' = Just ()
426 go (LName s') | s == s' = Just ()
431 go _ = Nothing
427 go _ = Nothing
432
428
433−qualifier :: TokenParser String
429+qualifier :: TokenParser Text
434qualifier = token go P.<?> "qualifier"
430qualifier = token go P.<?> "qualifier"
435 where
431 where
436 go (Qualifier s) = Just s
432 go (Qualifier s) = Just s
437 go _ = Nothing
433 go _ = Nothing
438
434
439−reserved :: String -> TokenParser ()
435+reserved :: Text -> TokenParser ()
440reserved s = token go P.<?> show s
436reserved s = token go P.<?> show s
441 where
437 where
442 go (LName s') | s == s' = Just ()
438 go (LName s') | s == s' = Just ()
443 go (Symbol s') | s == s' = Just ()
439 go (Symbol s') | s == s' = Just ()
444 go _ = Nothing
440 go _ = Nothing
445
441
446−uname :: TokenParser String
442+uname :: TokenParser Text
447uname = token go P.<?> "proper name"
443uname = token go P.<?> "proper name"
448 where
444 where
449 go (UName s) | validUName s = Just s
445 go (UName s) | validUName s = Just s
450 go _ = Nothing
446 go _ = Nothing
451
447
452−uname' :: String -> TokenParser ()
448+uname' :: Text -> TokenParser ()
453uname' s = token go P.<?> "proper name"
449uname' s = token go P.<?> "proper name"
454 where
450 where
455 go (UName s') | s == s' = Just ()
451 go (UName s') | s == s' = Just ()
456 go _ = Nothing
452 go _ = Nothing
457
453
458−tyname :: TokenParser String
454+tyname :: TokenParser Text
459tyname = token go P.<?> "type name"
455tyname = token go P.<?> "type name"
460 where
456 where
461 go (UName s) = Just s
457 go (UName s) = Just s
462 go _ = Nothing
458 go _ = Nothing
463
459
464−dconsname :: TokenParser String
460+dconsname :: TokenParser Text
465dconsname = token go P.<?> "data constructor name"
461dconsname = token go P.<?> "data constructor name"
466 where
462 where
467 go (UName s) = Just s
463 go (UName s) = Just s
468 go _ = Nothing
464 go _ = Nothing
469
465
470−mname :: TokenParser String
466+mname :: TokenParser Text
471mname = token go P.<?> "module name"
467mname = token go P.<?> "module name"
472 where
468 where
473 go (UName s) | validModuleName s = Just s
469 go (UName s) | validModuleName s = Just s
474 go _ = Nothing
470 go _ = Nothing
475
471
476−symbol :: TokenParser String
472+symbol :: TokenParser Text
477symbol = token go P.<?> "symbol"
473symbol = token go P.<?> "symbol"
478 where
474 where
479 go (Symbol s) = Just s
475 go (Symbol s) = Just s
@@ -482,7 +478,7 @@ symbol = token go P.<?> "symbol"
482 go At = Just "@"
478 go At = Just "@"
483 go _ = Nothing
479 go _ = Nothing
484
480
485−symbol' :: String -> TokenParser ()
481+symbol' :: Text -> TokenParser ()
486symbol' s = token go P.<?> show s
482symbol' s = token go P.<?> show s
487 where
483 where
488 go (Symbol s') | s == s' = Just ()
484 go (Symbol s') | s == s' = Just ()
@@ -496,7 +492,7 @@ charLiteral = token go P.<?> "char literal"
496 go (CharLiteral c) = Just c
492 go (CharLiteral c) = Just c
497 go _ = Nothing
493 go _ = Nothing
498
494
499−stringLiteral :: TokenParser String
495+stringLiteral :: TokenParser Text
500stringLiteral = token go P.<?> "string literal"
496stringLiteral = token go P.<?> "string literal"
501 where
497 where
502 go (StringLiteral s) = Just s
498 go (StringLiteral s) = Just s
@@ -514,22 +510,25 @@ natural = token go P.<?> "natural"
514 go (Number (Left n)) = Just n
510 go (Number (Left n)) = Just n
515 go _ = Nothing
511 go _ = Nothing
516
512
517−identifier :: TokenParser String
513+identifier :: TokenParser Text
518identifier = token go P.<?> "identifier"
514identifier = token go P.<?> "identifier"
519 where
515 where
520 go (LName s) | s `notElem` reservedPsNames = Just s
516 go (LName s) | s `notElem` reservedPsNames = Just s
521 go _ = Nothing
517 go _ = Nothing
522
518
523−validModuleName :: String -> Bool
519+validModuleName :: Text -> Bool
524−validModuleName s = '_' `notElem` s
520+validModuleName s = '_' `notElemT` s
521+
522+validUName :: Text -> Bool
523+validUName s = '\'' `notElemT` s
525
524
526−validUName :: String -> Bool
525+notElemT :: Char -> Text -> Bool
527−validUName s = '\'' `notElem` s
526+notElemT c = not . T.any (== c)
528
527
529-- |
528-- |
530-- A list of purescript reserved identifiers
529-- A list of purescript reserved identifiers
531--
530--
532−reservedPsNames :: [String]
531+reservedPsNames :: [Text]
533reservedPsNames = [ "data"
532reservedPsNames = [ "data"
534 , "newtype"
533 , "newtype"
535 , "type"
534 , "type"
@@ -555,14 +554,14 @@ reservedPsNames = [ "data"
555 , "where"
554 , "where"
556 ]
555 ]
557
556
558−reservedTypeNames :: [String]
557+reservedTypeNames :: [Text]
559reservedTypeNames = [ "forall", "where" ]
558reservedTypeNames = [ "forall", "where" ]
560
559
561-- |
560-- |
562-- The characters allowed for use in operators
561-- The characters allowed for use in operators
563--
562--
564isSymbolChar :: Char -> Bool
563isSymbolChar :: Char -> Bool
565−isSymbolChar c = (c `elem` ":!#$%&*+./<=>?@\\^|-~") || (not (isAscii c) && isSymbol c)
564+isSymbolChar c = (c `elem` (":!#$%&*+./<=>?@\\^|-~" :: [Char])) || (not (isAscii c) && isSymbol c)
566
565
567
566
568-- |
567-- |
@@ -575,12 +574,13 @@ isUnquotedKeyHeadChar c = (c == '_') || isAlphaNum c
575-- The characters allowed in the tail of an unquoted record key
574-- The characters allowed in the tail of an unquoted record key
576--
575--
577isUnquotedKeyTailChar :: Char -> Bool
576isUnquotedKeyTailChar :: Char -> Bool
578−isUnquotedKeyTailChar c = (c `elem` "_'") || isAlphaNum c
577+isUnquotedKeyTailChar c = (c `elem` ("_'" :: [Char])) || isAlphaNum c
579
578
580-- |
579-- |
581-- Strings allowed to be left unquoted in a record key
580-- Strings allowed to be left unquoted in a record key
582--
581--
583−isUnquotedKey :: String -> Bool
582+isUnquotedKey :: Text -> Bool
584−isUnquotedKey [] = False
583+isUnquotedKey t = case T.uncons t of
584+ Nothing -> False
585−isUnquotedKey (hd : tl) = isUnquotedKeyHeadChar hd &&
585+ Just (hd, tl) -> isUnquotedKeyHeadChar hd &&
586− all isUnquotedKeyTailChar tl
586+ T.all isUnquotedKeyTailChar tl
src/Language/PureScript/Parser/Types.hs+7−5
@@ -7,8 +7,10 @@ module Language.PureScript.Parser.Types
7
7
8import Prelude.Compat
8import Prelude.Compat
9
9
10−import Control.Applicative
11import Control.Monad (when, unless)
10import Control.Monad (when, unless)
11+import Control.Applicative ((<|>))
12+import Data.Text (Text)
13+import qualified Data.Text as T
12
14
13import Language.PureScript.AST.SourcePos
15import Language.PureScript.AST.SourcePos
14import Language.PureScript.Environment
16import Language.PureScript.Environment
@@ -21,7 +23,7 @@ import qualified Text.Parsec as P
21import qualified Text.Parsec.Expr as P
23import qualified Text.Parsec.Expr as P
22
24
23parseFunction :: TokenParser Type
25parseFunction :: TokenParser Type
24−parseFunction = parens rarrow >> return tyFunction
26+parseFunction = parens rarrow *> return tyFunction
25
27
26parseObject :: TokenParser Type
28parseObject :: TokenParser Type
27parseObject = braces $ TypeApp tyRecord <$> parseRow
29parseObject = braces $ TypeApp tyRecord <$> parseRow
@@ -39,7 +41,7 @@ parseTypeWildcard = do
39parseTypeVariable :: TokenParser Type
41parseTypeVariable :: TokenParser Type
40parseTypeVariable = do
42parseTypeVariable = do
41 ident <- identifier
43 ident <- identifier
42− when (ident `elem` reservedTypeNames) $ P.unexpected ident
44+ when (ident `elem` reservedTypeNames) $ P.unexpected (T.unpack ident)
43 return $ TypeVar ident
45 return $ TypeVar ident
44
46
45parseTypeConstructor :: TokenParser Type
47parseTypeConstructor :: TokenParser Type
@@ -87,7 +89,7 @@ parseAnyType = P.buildExpressionParser operators (buildPostfixParser postfixTabl
87 , [ P.Infix (P.try (parseQualified parseOperator) >>= \ident ->
89 , [ P.Infix (P.try (parseQualified parseOperator) >>= \ident ->
88 return (BinaryNoParensType (TypeOp ident))) P.AssocRight
90 return (BinaryNoParensType (TypeOp ident))) P.AssocRight
89 ]
91 ]
90− , [ P.Infix (rarrow >> return function) P.AssocRight ]
92+ , [ P.Infix (rarrow *> return function) P.AssocRight ]
91 ]
93 ]
92 postfixTable = [ \t -> KindedType t <$> (indented *> doubleColon *> parseKind)
94 postfixTable = [ \t -> KindedType t <$> (indented *> doubleColon *> parseKind)
93 ]
95 ]
@@ -116,7 +118,7 @@ noWildcards p = do
116 when (containsWildcards ty) $ P.unexpected "type wildcard"
118 when (containsWildcards ty) $ P.unexpected "type wildcard"
117 return ty
119 return ty
118
120
119−parseNameAndType :: TokenParser t -> TokenParser (String, t)
121+parseNameAndType :: TokenParser t -> TokenParser (Text, t)
120parseNameAndType p = (,) <$> (indented *> (lname <|> stringLiteral) <* indented <* doubleColon) <*> p
122parseNameAndType p = (,) <$> (indented *> (lname <|> stringLiteral) <* indented <* doubleColon) <*> p
121
123
122parseRowEnding :: TokenParser Type
124parseRowEnding :: TokenParser Type
src/Language/PureScript/Pretty/Common.hs+28−20
@@ -10,20 +10,27 @@ import Prelude.Compat
10import Control.Monad.State (StateT, modify, get)
10import Control.Monad.State (StateT, modify, get)
11
11
12import Data.List (elemIndices, intersperse)
12import Data.List (elemIndices, intersperse)
13+import Data.Monoid ((<>))
14+import Data.Text (Text)
15+import qualified Data.Text as T
13
16
14import Language.PureScript.AST (SourcePos(..), SourceSpan(..))
17import Language.PureScript.AST (SourcePos(..), SourceSpan(..))
15import Language.PureScript.Parser.Lexer (reservedPsNames, isUnquotedKey)
18import Language.PureScript.Parser.Lexer (reservedPsNames, isUnquotedKey)
16
19
17−import Text.PrettyPrint.Boxes
20+import Text.PrettyPrint.Boxes hiding ((<>))
21+import qualified Text.PrettyPrint.Boxes as Box
18
22
19-- |
23-- |
20-- Wrap a string in parentheses
24-- Wrap a string in parentheses
21--
25--
22parens :: String -> String
26parens :: String -> String
23−parens s = '(':s ++ ")"
27+parens s = "(" <> s <> ")"
28+
29+parensT :: Text -> Text
30+parensT s = "(" <> s <> ")"
24
31
25parensPos :: (Emit gen) => gen -> gen
32parensPos :: (Emit gen) => gen -> gen
26−parensPos s = emit "(" `mappend` s `mappend` emit ")"
33+parensPos s = emit "(" <> s <> emit ")"
27
34
28-- |
35-- |
29-- Generalize intercalate slightly for monoids
36-- Generalize intercalate slightly for monoids
@@ -32,15 +39,15 @@ intercalate :: Monoid m => m -> [m] -> m
32intercalate x xs = mconcat (intersperse x xs)
39intercalate x xs = mconcat (intersperse x xs)
33
40
34class (Monoid gen) => Emit gen where
41class (Monoid gen) => Emit gen where
35− emit :: String -> gen
42+ emit :: Text -> gen
36 addMapping :: SourceSpan -> gen
43 addMapping :: SourceSpan -> gen
37
44
38−data SMap = SMap String SourcePos SourcePos
45+data SMap = SMap Text SourcePos SourcePos
39
46
40-- |
47-- |
41-- String with length and source-map entries
48-- String with length and source-map entries
42--
49--
43−newtype StrPos = StrPos (SourcePos, String, [SMap])
50+newtype StrPos = StrPos (SourcePos, Text, [SMap])
44
51
45-- |
52-- |
46-- Make a monoid where append consists of concatenating the string part, adding the lengths
53-- Make a monoid where append consists of concatenating the string part, adding the lengths
@@ -50,10 +57,10 @@ newtype StrPos = StrPos (SourcePos, String, [SMap])
50instance Monoid StrPos where
57instance Monoid StrPos where
51 mempty = StrPos (SourcePos 0 0, "", [])
58 mempty = StrPos (SourcePos 0 0, "", [])
52
59
53− StrPos (a,b,c) `mappend` StrPos (a',b',c') = StrPos (a `addPos` a', b ++ b', c ++ (bumpPos a <$> c'))
60+ StrPos (a,b,c) `mappend` StrPos (a',b',c') = StrPos (a `addPos` a', b <> b', c ++ (bumpPos a <$> c'))
54
61
55 mconcat ms =
62 mconcat ms =
56− let s' = concatMap (\(StrPos(_, s, _)) -> s) ms
63+ let s' = foldMap (\(StrPos(_, s, _)) -> s) ms
57 (p, maps) = foldl plus (SourcePos 0 0, []) ms
64 (p, maps) = foldl plus (SourcePos 0 0, []) ms
58 in
65 in
59 StrPos (p, s', concat $ reverse maps)
66 StrPos (p, s', concat $ reverse maps)
@@ -66,22 +73,23 @@ instance Emit StrPos where
66 -- Augment a string with its length (rows/column)
73 -- Augment a string with its length (rows/column)
67 --
74 --
68 emit str =
75 emit str =
76+ -- TODO(Christoph): get rid of T.unpack
69− let newlines = elemIndices '\n' str
77+ let newlines = elemIndices '\n' (T.unpack str)
70 index = if null newlines then 0 else last newlines + 1
78 index = if null newlines then 0 else last newlines + 1
71 in
79 in
72− StrPos (SourcePos { sourcePosLine = length newlines, sourcePosColumn = length str - index }, str, [])
80+ StrPos (SourcePos { sourcePosLine = length newlines, sourcePosColumn = T.length str - index }, str, [])
73
81
74 -- |
82 -- |
75 -- Add a new mapping entry for given source position with initially zero generated position
83 -- Add a new mapping entry for given source position with initially zero generated position
76 --
84 --
77 addMapping SourceSpan { spanName = file, spanStart = startPos } = StrPos (zeroPos, mempty, [mapping])
85 addMapping SourceSpan { spanName = file, spanStart = startPos } = StrPos (zeroPos, mempty, [mapping])
78 where
86 where
79− mapping = SMap file startPos zeroPos
87+ mapping = SMap (T.pack file) startPos zeroPos
80 zeroPos = SourcePos 0 0
88 zeroPos = SourcePos 0 0
81
89
82−newtype PlainString = PlainString String deriving Monoid
90+newtype PlainString = PlainString Text deriving Monoid
83
91
84−runPlainString :: PlainString -> String
92+runPlainString :: PlainString -> Text
85runPlainString (PlainString s) = s
93runPlainString (PlainString s) = s
86
94
87instance Emit PlainString where
95instance Emit PlainString where
@@ -127,7 +135,7 @@ withIndent action = do
127currentIndent :: (Emit gen) => StateT PrinterState Maybe gen
135currentIndent :: (Emit gen) => StateT PrinterState Maybe gen
128currentIndent = do
136currentIndent = do
129 current <- get
137 current <- get
130− return $ emit $ replicate (indent current) ' '
138+ return $ emit $ T.replicate (indent current) " "
131
139
132-- |
140-- |
133-- Print many lines
141-- Print many lines
@@ -141,19 +149,19 @@ prettyPrintMany f xs = do
141-- |
149-- |
142-- Prints an object key, escaping reserved names.
150-- Prints an object key, escaping reserved names.
143--
151--
144−prettyPrintObjectKey :: String -> String
152+prettyPrintObjectKey :: Text -> Text
145−prettyPrintObjectKey s | s `elem` reservedPsNames = show s
153+prettyPrintObjectKey s | s `elem` reservedPsNames = T.pack (show s)
146 | isUnquotedKey s = s
154 | isUnquotedKey s = s
147− | otherwise = show s
155+ | otherwise = T.pack (show s)
148
156
149-- | Place a box before another, vertically when the first box takes up multiple lines.
157-- | Place a box before another, vertically when the first box takes up multiple lines.
150before :: Box -> Box -> Box
158before :: Box -> Box -> Box
151before b1 b2 | rows b1 > 1 = b1 // b2
159before b1 b2 | rows b1 > 1 = b1 // b2
152− | otherwise = b1 <> b2
160+ | otherwise = b1 Box.<> b2
153
161
154beforeWithSpace :: Box -> Box -> Box
162beforeWithSpace :: Box -> Box -> Box
155−beforeWithSpace b1 = before (b1 <> text " ")
163+beforeWithSpace b1 = before (b1 Box.<> text " ")
156
164
157-- | Place a Box on the bottom right of another
165-- | Place a Box on the bottom right of another
158endWith :: Box -> Box -> Box
166endWith :: Box -> Box -> Box
159−endWith l r = l <> vcat top [emptyBox (rows l - 1) (cols r), r]
167+endWith l r = l Box.<> vcat top [emptyBox (rows l - 1) (cols r), r]
src/Language/PureScript/Pretty/JS.hs+48−39
@@ -9,12 +9,15 @@ module Language.PureScript.Pretty.JS
9import Prelude.Compat
9import Prelude.Compat
10
10
11import Control.Arrow ((<+>))
11import Control.Arrow ((<+>))
12−import Control.Monad.State hiding (sequence)
12+import Control.Monad (forM, mzero)
13+import Control.Monad.State (StateT, evalStateT)
13import Control.PatternArrows
14import Control.PatternArrows
14import qualified Control.Arrow as A
15import qualified Control.Arrow as A
15
16
16import Data.Maybe (fromMaybe)
17import Data.Maybe (fromMaybe)
17−import Data.Monoid
18+import Data.Monoid ((<>))
19+import Data.Text (Text)
20+import qualified Data.Text as T
18
21
19import Language.PureScript.AST (SourceSpan(..))
22import Language.PureScript.AST (SourceSpan(..))
20import Language.PureScript.CodeGen.JS.AST
23import Language.PureScript.CodeGen.JS.AST
@@ -25,6 +28,8 @@ import Language.PureScript.Pretty.Common
25
28
26import Numeric
29import Numeric
27
30
31+-- TODO (Christoph): Get rid of T.unpack / pack
32+
28literals :: (Emit gen) => Pattern PrinterState JS gen
33literals :: (Emit gen) => Pattern PrinterState JS gen
29literals = mkPattern' match'
34literals = mkPattern' match'
30 where
35 where
@@ -32,7 +37,7 @@ literals = mkPattern' match'
32 match' js = (addMapping' (getSourceSpan js) <>) <$> match js
37 match' js = (addMapping' (getSourceSpan js) <>) <$> match js
33
38
34 match :: (Emit gen) => JS -> StateT PrinterState Maybe gen
39 match :: (Emit gen) => JS -> StateT PrinterState Maybe gen
35− match (JSNumericLiteral _ n) = return $ emit $ either show show n
40+ match (JSNumericLiteral _ n) = return $ emit $ T.pack $ either show show n
36 match (JSStringLiteral _ s) = return $ string s
41 match (JSStringLiteral _ s) = return $ string s
37 match (JSBooleanLiteral _ True) = return $ emit "true"
42 match (JSBooleanLiteral _ True) = return $ emit "true"
38 match (JSBooleanLiteral _ False) = return $ emit "false"
43 match (JSBooleanLiteral _ False) = return $ emit "false"
@@ -53,8 +58,8 @@ literals = mkPattern' match'
53 , return $ emit "}"
58 , return $ emit "}"
54 ]
59 ]
55 where
60 where
56− objectPropertyToString :: (Emit gen) => String -> gen
61+ objectPropertyToString :: (Emit gen) => Text -> gen
57− objectPropertyToString s | identNeedsEscaping s = emit $ show s
62+ objectPropertyToString s | identNeedsEscaping s = emit $ T.pack $ show s
58 | otherwise = emit s
63 | otherwise = emit s
59 match (JSBlock _ sts) = mconcat <$> sequence
64 match (JSBlock _ sts) = mconcat <$> sequence
60 [ return $ emit "{\n"
65 [ return $ emit "{\n"
@@ -65,7 +70,7 @@ literals = mkPattern' match'
65 ]
70 ]
66 match (JSVar _ ident) = return $ emit ident
71 match (JSVar _ ident) = return $ emit ident
67 match (JSVariableIntroduction _ ident value) = mconcat <$> sequence
72 match (JSVariableIntroduction _ ident value) = mconcat <$> sequence
68− [ return $ emit $ "var " ++ ident
73+ [ return $ emit $ "var " <> ident
69 , maybe (return mempty) (fmap (emit " = " <>) . prettyPrintJS') value
74 , maybe (return mempty) (fmap (emit " = " <>) . prettyPrintJS') value
70 ]
75 ]
71 match (JSAssignment _ target value) = mconcat <$> sequence
76 match (JSAssignment _ target value) = mconcat <$> sequence
@@ -80,15 +85,15 @@ literals = mkPattern' match'
80 , prettyPrintJS' sts
85 , prettyPrintJS' sts
81 ]
86 ]
82 match (JSFor _ ident start end sts) = mconcat <$> sequence
87 match (JSFor _ ident start end sts) = mconcat <$> sequence
83− [ return $ emit $ "for (var " ++ ident ++ " = "
88+ [ return $ emit $ "for (var " <> ident <> " = "
84 , prettyPrintJS' start
89 , prettyPrintJS' start
85− , return $ emit $ "; " ++ ident ++ " < "
90+ , return $ emit $ "; " <> ident <> " < "
86 , prettyPrintJS' end
91 , prettyPrintJS' end
87− , return $ emit $ "; " ++ ident ++ "++) "
92+ , return $ emit $ "; " <> ident <> "++) "
88 , prettyPrintJS' sts
93 , prettyPrintJS' sts
89 ]
94 ]
90 match (JSForIn _ ident obj sts) = mconcat <$> sequence
95 match (JSForIn _ ident obj sts) = mconcat <$> sequence
91− [ return $ emit $ "for (var " ++ ident ++ " in "
96+ [ return $ emit $ "for (var " <> ident <> " in "
92 , prettyPrintJS' obj
97 , prettyPrintJS' obj
93 , return $ emit ") "
98 , return $ emit ") "
94 , prettyPrintJS' sts
99 , prettyPrintJS' sts
@@ -108,10 +113,10 @@ literals = mkPattern' match'
108 [ return $ emit "throw "
113 [ return $ emit "throw "
109 , prettyPrintJS' value
114 , prettyPrintJS' value
110 ]
115 ]
111− match (JSBreak _ lbl) = return $ emit $ "break " ++ lbl
116+ match (JSBreak _ lbl) = return $ emit $ "break " <> lbl
112− match (JSContinue _ lbl) = return $ emit $ "continue " ++ lbl
117+ match (JSContinue _ lbl) = return $ emit $ "continue " <> lbl
113 match (JSLabel _ lbl js) = mconcat <$> sequence
118 match (JSLabel _ lbl js) = mconcat <$> sequence
114− [ return $ emit $ lbl ++ ": "
119+ [ return $ emit $ lbl <> ": "
115 , prettyPrintJS' js
120 , prettyPrintJS' js
116 ]
121 ]
117 match (JSComment _ com js) = fmap mconcat $ sequence $
122 match (JSComment _ com js) = fmap mconcat $ sequence $
@@ -126,27 +131,29 @@ literals = mkPattern' match'
126 , prettyPrintJS' js
131 , prettyPrintJS' js
127 ]
132 ]
128 where
133 where
129− commentLines :: Comment -> [String]
134+ commentLines :: Comment -> [Text]
130 commentLines (LineComment s) = [s]
135 commentLines (LineComment s) = [s]
131− commentLines (BlockComment s) = lines s
136+ commentLines (BlockComment s) = T.lines s
132
137
133− asLine :: (Emit gen) => String -> StateT PrinterState Maybe gen
138+ asLine :: (Emit gen) => Text -> StateT PrinterState Maybe gen
134 asLine s = do
139 asLine s = do
135 i <- currentIndent
140 i <- currentIndent
136 return $ i <> emit " * " <> (emit . removeComments) s <> emit "\n"
141 return $ i <> emit " * " <> (emit . removeComments) s <> emit "\n"
137
142
138− removeComments :: String -> String
143+ removeComments :: Text -> Text
139− removeComments ('*' : '/' : s) = removeComments s
144+ removeComments t =
145+ case T.stripPrefix "*/" t of
146+ Just rest -> removeComments rest
147+ Nothing -> case T.uncons t of
140− removeComments (c : s) = c : removeComments s
148+ Just (x, xs) -> x `T.cons` removeComments xs
141−
149+ Nothing -> ""
142− removeComments [] = []
143 match (JSRaw _ js) = return $ emit js
150 match (JSRaw _ js) = return $ emit js
144 match _ = mzero
151 match _ = mzero
145
152
146−string :: (Emit gen) => String -> gen
153+string :: (Emit gen) => Text -> gen
147−string s = emit $ '"' : concatMap encodeChar s ++ "\""
154+string s = emit $ "\"" <> T.concatMap encodeChar s <> "\""
148 where
155 where
149− encodeChar :: Char -> String
156+ encodeChar :: Char -> Text
150 encodeChar '\b' = "\\b"
157 encodeChar '\b' = "\\b"
151 encodeChar '\t' = "\\t"
158 encodeChar '\t' = "\\t"
152 encodeChar '\n' = "\\n"
159 encodeChar '\n' = "\\n"
@@ -155,16 +162,18 @@ string s = emit $ '"' : concatMap encodeChar s ++ "\""
155 encodeChar '\r' = "\\r"
162 encodeChar '\r' = "\\r"
156 encodeChar '"' = "\\\""
163 encodeChar '"' = "\\\""
157 encodeChar '\\' = "\\\\"
164 encodeChar '\\' = "\\\\"
158− encodeChar c | fromEnum c > 0xFFFF = "\\u" ++ showHex highSurrogate ("\\u" ++ showHex lowSurrogate "")
165+ encodeChar c | fromEnum c > 0xFFFF = "\\u" <> showHex' highSurrogate ("\\u" ++ showHex lowSurrogate "")
159 where
166 where
160 (h, l) = divMod (fromEnum c - 0x10000) 0x400
167 (h, l) = divMod (fromEnum c - 0x10000) 0x400
161 highSurrogate = h + 0xD800
168 highSurrogate = h + 0xD800
162 lowSurrogate = l + 0xDC00
169 lowSurrogate = l + 0xDC00
163− encodeChar c | fromEnum c > 0xFFF = "\\u" ++ showHex (fromEnum c) ""
170+ encodeChar c | fromEnum c > 0xFFF = "\\u" <> showHex' (fromEnum c) ""
164− encodeChar c | fromEnum c > 0xFF = "\\u0" ++ showHex (fromEnum c) ""
171+ encodeChar c | fromEnum c > 0xFF = "\\u0" <> showHex' (fromEnum c) ""
165− encodeChar c | fromEnum c < 0x10 = "\\x0" ++ showHex (fromEnum c) ""
172+ encodeChar c | fromEnum c < 0x10 = "\\x0" <> showHex' (fromEnum c) ""
166− encodeChar c | fromEnum c > 0x7E || fromEnum c < 0x20 = "\\x" ++ showHex (fromEnum c) ""
173+ encodeChar c | fromEnum c > 0x7E || fromEnum c < 0x20 = "\\x" <> showHex' (fromEnum c) ""
167− encodeChar c = [c]
174+ encodeChar c = T.singleton c
175+
176+ showHex' a b = T.pack (showHex a b)
168
177
169conditional :: Pattern PrinterState JS ((Maybe SourceSpan, JS, JS), JS)
178conditional :: Pattern PrinterState JS ((Maybe SourceSpan, JS, JS), JS)
170conditional = mkPattern match
179conditional = mkPattern match
@@ -185,7 +194,7 @@ indexer = mkPattern' match
185
194
186 match _ = mzero
195 match _ = mzero
187
196
188−lam :: Pattern PrinterState JS ((Maybe String, [String], Maybe SourceSpan), JS)
197+lam :: Pattern PrinterState JS ((Maybe Text, [Text], Maybe SourceSpan), JS)
189lam = mkPattern match
198lam = mkPattern match
190 where
199 where
191 match (JSFunction ss name args ret) = Just ((name, args, ss), ret)
200 match (JSFunction ss name args ret) = Just ((name, args, ss), ret)
@@ -211,7 +220,7 @@ instanceOf = mkPattern match
211 match (JSInstanceOf _ val ty) = Just (val, ty)
220 match (JSInstanceOf _ val ty) = Just (val, ty)
212 match _ = Nothing
221 match _ = Nothing
213
222
214−unary' :: (Emit gen) => UnaryOperator -> (JS -> String) -> Operator PrinterState JS gen
223+unary' :: (Emit gen) => UnaryOperator -> (JS -> Text) -> Operator PrinterState JS gen
215unary' op mkStr = Wrap match (<>)
224unary' op mkStr = Wrap match (<>)
216 where
225 where
217 match :: (Emit gen) => Pattern PrinterState JS (gen, JS)
226 match :: (Emit gen) => Pattern PrinterState JS (gen, JS)
@@ -220,7 +229,7 @@ unary' op mkStr = Wrap match (<>)
220 match' (JSUnary _ op' val) | op' == op = Just (emit $ mkStr val, val)
229 match' (JSUnary _ op' val) | op' == op = Just (emit $ mkStr val, val)
221 match' _ = Nothing
230 match' _ = Nothing
222
231
223−unary :: (Emit gen) => UnaryOperator -> String -> Operator PrinterState JS gen
232+unary :: (Emit gen) => UnaryOperator -> Text -> Operator PrinterState JS gen
224unary op str = unary' op (const str)
233unary op str = unary' op (const str)
225
234
226negateOperator :: (Emit gen) => Operator PrinterState JS gen
235negateOperator :: (Emit gen) => Operator PrinterState JS gen
@@ -229,8 +238,8 @@ negateOperator = unary' Negate (\v -> if isNegate v then "- " else "-")
229 isNegate (JSUnary _ Negate _) = True
238 isNegate (JSUnary _ Negate _) = True
230 isNegate _ = False
239 isNegate _ = False
231
240
232−binary :: (Emit gen) => BinaryOperator -> String -> Operator PrinterState JS gen
241+binary :: (Emit gen) => BinaryOperator -> Text -> Operator PrinterState JS gen
233−binary op str = AssocL match (\v1 v2 -> v1 <> emit (" " ++ str ++ " ") <> v2)
242+binary op str = AssocL match (\v1 v2 -> v1 <> emit (" " <> str <> " ") <> v2)
234 where
243 where
235 match :: Pattern PrinterState JS (JS, JS)
244 match :: Pattern PrinterState JS (JS, JS)
236 match = mkPattern match'
245 match = mkPattern match'
@@ -253,12 +262,12 @@ prettyPrintJS1 = fromMaybe (internalError "Incomplete pattern") . flip evalState
253-- |
262-- |
254-- Generate a pretty-printed string representing a collection of Javascript expressions at the same indentation level
263-- Generate a pretty-printed string representing a collection of Javascript expressions at the same indentation level
255--
264--
256−prettyPrintJSWithSourceMaps :: [JS] -> (String, [SMap])
265+prettyPrintJSWithSourceMaps :: [JS] -> (Text, [SMap])
257prettyPrintJSWithSourceMaps js =
266prettyPrintJSWithSourceMaps js =
258 let StrPos (_, s, mp) = (fromMaybe (internalError "Incomplete pattern") . flip evalStateT (PrinterState 0) . prettyStatements) js
267 let StrPos (_, s, mp) = (fromMaybe (internalError "Incomplete pattern") . flip evalStateT (PrinterState 0) . prettyStatements) js
259 in (s, mp)
268 in (s, mp)
260
269
261−prettyPrintJS :: [JS] -> String
270+prettyPrintJS :: [JS] -> Text
262prettyPrintJS = maybe (internalError "Incomplete pattern") runPlainString . flip evalStateT (PrinterState 0) . prettyStatements
271prettyPrintJS = maybe (internalError "Incomplete pattern") runPlainString . flip evalStateT (PrinterState 0) . prettyStatements
263-- |
272-- |
264-- Generate an indented, pretty-printed string representing a Javascript expression
273-- Generate an indented, pretty-printed string representing a Javascript expression
@@ -276,8 +285,8 @@ prettyPrintJS' = A.runKleisli $ runPattern matchValue
276 , [ unary JSNew "new " ]
285 , [ unary JSNew "new " ]
277 , [ Wrap lam $ \(name, args, ss) ret -> addMapping' ss <>
286 , [ Wrap lam $ \(name, args, ss) ret -> addMapping' ss <>
278 emit ("function "
287 emit ("function "
279− ++ fromMaybe "" name
288+ <> fromMaybe "" name
280− ++ "(" ++ intercalate ", " args ++ ") ")
289+ <> "(" <> intercalate ", " args <> ") ")
281 <> ret ]
290 <> ret ]
282 , [ Wrap typeOf $ \_ s -> emit "typeof " <> s ]
291 , [ Wrap typeOf $ \_ s -> emit "typeof " <> s ]
283 , [ unary Not "!"
292 , [ unary Not "!"
src/Language/PureScript/Pretty/Kinds.hs+6−2
@@ -11,6 +11,8 @@ import Control.Arrow (ArrowPlus(..))
11import Control.PatternArrows as PA
11import Control.PatternArrows as PA
12
12
13import Data.Maybe (fromMaybe)
13import Data.Maybe (fromMaybe)
14+import qualified Data.Text as T
15+import Data.Text (Text)
14
16
15import Language.PureScript.Crash
17import Language.PureScript.Crash
16import Language.PureScript.Kinds
18import Language.PureScript.Kinds
@@ -38,9 +40,11 @@ funKind = mkPattern match
38 match _ = Nothing
40 match _ = Nothing
39
41
40-- | Generate a pretty-printed string representing a Kind
42-- | Generate a pretty-printed string representing a Kind
41−prettyPrintKind :: Kind -> String
43+prettyPrintKind :: Kind -> Text
42prettyPrintKind
44prettyPrintKind
45+ -- TODO(Christoph): get rid of T.pack
46+ = T.pack
43− = fromMaybe (internalError "Incomplete pattern")
47+ . fromMaybe (internalError "Incomplete pattern")
44 . PA.pattern matchKind ()
48 . PA.pattern matchKind ()
45 where
49 where
46 matchKind :: Pattern () Kind String
50 matchKind :: Pattern () Kind String
src/Language/PureScript/Pretty/Types.hs+12−9
@@ -18,6 +18,7 @@ import Control.Arrow ((<+>))
18import Control.PatternArrows as PA
18import Control.PatternArrows as PA
19
19
20import Data.Maybe (fromMaybe)
20import Data.Maybe (fromMaybe)
21+import qualified Data.Text as T
21
22
22import Language.PureScript.Crash
23import Language.PureScript.Crash
23import Language.PureScript.Environment
24import Language.PureScript.Environment
@@ -29,6 +30,8 @@ import Language.PureScript.Types
29
30
30import Text.PrettyPrint.Boxes hiding ((<+>))
31import Text.PrettyPrint.Boxes hiding ((<+>))
31
32
33+-- TODO(Christoph): get rid of T.unpack s
34+
32constraintsAsBox :: [Constraint] -> Box -> Box
35constraintsAsBox :: [Constraint] -> Box -> Box
33constraintsAsBox [con] ty = text "(" <> constraintAsBox con `before` (text ") => " <> ty)
36constraintsAsBox [con] ty = text "(" <> constraintAsBox con `before` (text ") => " <> ty)
34constraintsAsBox xs ty = vcat left (zipWith (\i con -> text (if i == 0 then "( " else ", ") <> constraintAsBox con) [0 :: Int ..] xs) `before` (text ") => " <> ty)
37constraintsAsBox xs ty = vcat left (zipWith (\i con -> text (if i == 0 then "( " else ", ") <> constraintAsBox con) [0 :: Int ..] xs) `before` (text ") => " <> ty)
@@ -43,7 +46,7 @@ prettyPrintRowWith :: Char -> Char -> Type -> Box
43prettyPrintRowWith open close = uncurry listToBox . toList []
46prettyPrintRowWith open close = uncurry listToBox . toList []
44 where
47 where
45 nameAndTypeToPs :: Char -> String -> Type -> Box
48 nameAndTypeToPs :: Char -> String -> Type -> Box
46− nameAndTypeToPs start name ty = text (start : ' ' : prettyPrintObjectKey name ++ " :: ") <> typeAsBox ty
49+ nameAndTypeToPs start name ty = text (start : ' ' : T.unpack (prettyPrintObjectKey (T.pack name)) ++ " :: ") <> typeAsBox ty
47
50
48 tailToPs :: Type -> Box
51 tailToPs :: Type -> Box
49 tailToPs REmpty = nullBox
52 tailToPs REmpty = nullBox
@@ -57,7 +60,7 @@ prettyPrintRowWith open close = uncurry listToBox . toList []
57 [ tailToPs rest, text [close] ]
60 [ tailToPs rest, text [close] ]
58
61
59 toList :: [(String, Type)] -> Type -> ([(String, Type)], Type)
62 toList :: [(String, Type)] -> Type -> ([(String, Type)], Type)
60− toList tys (RCons name ty row) = toList ((name, ty):tys) row
63+ toList tys (RCons name ty row) = toList ((T.unpack name, ty):tys) row
61 toList tys r = (reverse tys, r)
64 toList tys r = (reverse tys, r)
62
65
63prettyPrintRow :: Type -> String
66prettyPrintRow :: Type -> String
@@ -112,21 +115,21 @@ matchTypeAtom suggesting =
112 typeLiterals :: Pattern () Type Box
115 typeLiterals :: Pattern () Type Box
113 typeLiterals = mkPattern match where
116 typeLiterals = mkPattern match where
114 match TypeWildcard{} = Just $ text "_"
117 match TypeWildcard{} = Just $ text "_"
115− match (TypeVar var) = Just $ text var
118+ match (TypeVar var) = Just $ text $ T.unpack var
116 match (TypeLevelString s) = Just . text $ show s
119 match (TypeLevelString s) = Just . text $ show s
117 match (PrettyPrintObject row) = Just $ prettyPrintRowWith '{' '}' row
120 match (PrettyPrintObject row) = Just $ prettyPrintRowWith '{' '}' row
118− match (TypeConstructor ctor) = Just $ text $ runProperName $ disqualify ctor
121+ match (TypeConstructor ctor) = Just $ text $ T.unpack $ runProperName $ disqualify ctor
119 match (TUnknown u)
122 match (TUnknown u)
120 | suggesting = Just $ text "_"
123 | suggesting = Just $ text "_"
121 | otherwise = Just $ text $ 't' : show u
124 | otherwise = Just $ text $ 't' : show u
122 match (Skolem name s _ _)
125 match (Skolem name s _ _)
123− | suggesting = Just $ text name
126+ | suggesting = Just $ text $ T.unpack name
124− | otherwise = Just $ text $ name ++ show s
127+ | otherwise = Just $ text $ T.unpack name ++ show s
125 match REmpty = Just $ text "()"
128 match REmpty = Just $ text "()"
126 match row@RCons{} = Just $ prettyPrintRowWith '(' ')' row
129 match row@RCons{} = Just $ prettyPrintRowWith '(' ')' row
127 match (BinaryNoParensType op l r) =
130 match (BinaryNoParensType op l r) =
128 Just $ typeAsBox l <> text " " <> typeAsBox op <> text " " <> typeAsBox r
131 Just $ typeAsBox l <> text " " <> typeAsBox op <> text " " <> typeAsBox r
129− match (TypeOp op) = Just $ text $ showQualified runOpName op
132+ match (TypeOp op) = Just $ text $ T.unpack $ showQualified runOpName op
130 match _ = Nothing
133 match _ = Nothing
131
134
132matchType :: Bool -> Pattern () Type Box
135matchType :: Bool -> Pattern () Type Box
@@ -137,7 +140,7 @@ matchType = buildPrettyPrinter operators . matchTypeAtom where
137 , [ AssocR appliedFunction $ \arg ret -> keepSingleLinesOr id arg (text "-> " <> ret) ]
140 , [ AssocR appliedFunction $ \arg ret -> keepSingleLinesOr id arg (text "-> " <> ret) ]
138 , [ Wrap constrained $ \deps ty -> constraintsAsBox deps ty ]
141 , [ Wrap constrained $ \deps ty -> constraintsAsBox deps ty ]
139 , [ Wrap forall_ $ \idents ty -> keepSingleLinesOr (moveRight 2) (text ("forall " ++ unwords idents ++ ".")) ty ]
142 , [ Wrap forall_ $ \idents ty -> keepSingleLinesOr (moveRight 2) (text ("forall " ++ unwords idents ++ ".")) ty ]
140− , [ Wrap kinded $ \k ty -> keepSingleLinesOr (moveRight 2) ty (text (":: " ++ prettyPrintKind k)) ]
143+ , [ Wrap kinded $ \k ty -> keepSingleLinesOr (moveRight 2) ty (text (":: " ++ T.unpack (prettyPrintKind k))) ]
141 , [ Wrap explicitParens $ \_ ty -> ty ]
144 , [ Wrap explicitParens $ \_ ty -> ty ]
142 ]
145 ]
143
146
@@ -151,7 +154,7 @@ matchType = buildPrettyPrinter operators . matchTypeAtom where
151forall_ :: Pattern () Type ([String], Type)
154forall_ :: Pattern () Type ([String], Type)
152forall_ = mkPattern match
155forall_ = mkPattern match
153 where
156 where
154− match (PrettyPrintForAll idents ty) = Just (idents, ty)
157+ match (PrettyPrintForAll idents ty) = Just (map T.unpack idents, ty)
155 match _ = Nothing
158 match _ = Nothing
156
159
157typeAtomAsBox :: Type -> Box
160typeAtomAsBox :: Type -> Box
src/Language/PureScript/Pretty/Values.hs+46−36
@@ -11,6 +11,11 @@ import Prelude.Compat
11
11
12import Control.Arrow (second)
12import Control.Arrow (second)
13
13
14+import qualified Data.Monoid as Monoid ((<>))
15+
16+import qualified Data.Text as T
17+import Data.Text (Text)
18+
14import Language.PureScript.AST
19import Language.PureScript.AST
15import Language.PureScript.Crash
20import Language.PureScript.Crash
16import Language.PureScript.Names
21import Language.PureScript.Names
@@ -20,6 +25,11 @@ import Language.PureScript.Types (Constraint(..))
20
25
21import Text.PrettyPrint.Boxes
26import Text.PrettyPrint.Boxes
22
27
28+-- TODO(Christoph): remove T.unpack s
29+
30+textT :: Text -> Box
31+textT = text . T.unpack
32+
23-- | Render an aligned list of items separated with commas
33-- | Render an aligned list of items separated with commas
24list :: Char -> Char -> (a -> Box) -> [a] -> Box
34list :: Char -> Char -> (a -> Box) -> [a] -> Box
25list open close _ [] = text [open, close]
35list open close _ [] = text [open, close]
@@ -30,11 +40,11 @@ list open close f xs = vcat left (zipWith toLine [0 :: Int ..] xs ++ [ text [ cl
30ellipsis :: Box
40ellipsis :: Box
31ellipsis = text "..."
41ellipsis = text "..."
32
42
33−prettyPrintObject :: Int -> [(String, Maybe Expr)] -> Box
43+prettyPrintObject :: Int -> [(Text, Maybe Expr)] -> Box
34prettyPrintObject d = list '{' '}' prettyPrintObjectProperty
44prettyPrintObject d = list '{' '}' prettyPrintObjectProperty
35 where
45 where
36− prettyPrintObjectProperty :: (String, Maybe Expr) -> Box
46+ prettyPrintObjectProperty :: (Text, Maybe Expr) -> Box
37− prettyPrintObjectProperty (key, value) = text (prettyPrintObjectKey key ++ ": ") <> maybe (text "_") (prettyPrintValue (d - 1)) value
47+ prettyPrintObjectProperty (key, value) = textT (prettyPrintObjectKey key Monoid.<> ": ") <> maybe (text "_") (prettyPrintValue (d - 1)) value
38
48
39-- | Pretty-print an expression
49-- | Pretty-print an expression
40prettyPrintValue :: Int -> Expr -> Box
50prettyPrintValue :: Int -> Expr -> Box
@@ -44,13 +54,13 @@ prettyPrintValue d (IfThenElse cond th el) =
44 // moveRight 2 (vcat left [ text "then " <> prettyPrintValueAtom (d - 1) th
54 // moveRight 2 (vcat left [ text "then " <> prettyPrintValueAtom (d - 1) th
45 , text "else " <> prettyPrintValueAtom (d - 1) el
55 , text "else " <> prettyPrintValueAtom (d - 1) el
46 ])
56 ])
47−prettyPrintValue d (Accessor prop val) = prettyPrintValueAtom (d - 1) val <> text ("." ++ prettyPrintObjectKey prop)
57+prettyPrintValue d (Accessor prop val) = prettyPrintValueAtom (d - 1) val <> textT ("." Monoid.<> prettyPrintObjectKey prop)
48−prettyPrintValue d (ObjectUpdate o ps) = prettyPrintValueAtom (d - 1) o <> text " " <> list '{' '}' (\(key, val) -> text (key ++ " = ") <> prettyPrintValue (d - 1) val) ps
58+prettyPrintValue d (ObjectUpdate o ps) = prettyPrintValueAtom (d - 1) o <> text " " <> list '{' '}' (\(key, val) -> textT (key Monoid.<> " = ") <> prettyPrintValue (d - 1) val) ps
49prettyPrintValue d (App val arg) = prettyPrintValueAtom (d - 1) val `beforeWithSpace` prettyPrintValueAtom (d - 1) arg
59prettyPrintValue d (App val arg) = prettyPrintValueAtom (d - 1) val `beforeWithSpace` prettyPrintValueAtom (d - 1) arg
50−prettyPrintValue d (Abs (Left arg) val) = text ('\\' : showIdent arg ++ " -> ") // moveRight 2 (prettyPrintValue (d - 1) val)
60+prettyPrintValue d (Abs (Left arg) val) = text ('\\' : T.unpack (showIdent arg) ++ " -> ") // moveRight 2 (prettyPrintValue (d - 1) val)
51−prettyPrintValue d (Abs (Right arg) val) = text ('\\' : prettyPrintBinder arg ++ " -> ") // moveRight 2 (prettyPrintValue (d - 1) val)
61+prettyPrintValue d (Abs (Right arg) val) = text ('\\' : T.unpack (prettyPrintBinder arg) ++ " -> ") // moveRight 2 (prettyPrintValue (d - 1) val)
52prettyPrintValue d (TypeClassDictionaryConstructorApp className ps) =
62prettyPrintValue d (TypeClassDictionaryConstructorApp className ps) =
53− text (runProperName (disqualify className) ++ " ") <> prettyPrintValueAtom (d - 1) ps
63+ text (T.unpack (runProperName (disqualify className)) ++ " ") <> prettyPrintValueAtom (d - 1) ps
54prettyPrintValue d (Case values binders) =
64prettyPrintValue d (Case values binders) =
55 (text "case " <> foldl1 beforeWithSpace (map (prettyPrintValueAtom (d - 1)) values) <> text " of") //
65 (text "case " <> foldl1 beforeWithSpace (map (prettyPrintValueAtom (d - 1)) values) <> text " of") //
56 moveRight 2 (vcat left (map (prettyPrintCaseAlternative (d - 1)) binders))
66 moveRight 2 (vcat left (map (prettyPrintCaseAlternative (d - 1)) binders))
@@ -60,14 +70,14 @@ prettyPrintValue d (Let ds val) =
60 (text "in " <> prettyPrintValue (d - 1) val)
70 (text "in " <> prettyPrintValue (d - 1) val)
61prettyPrintValue d (Do els) =
71prettyPrintValue d (Do els) =
62 text "do " <> vcat left (map (prettyPrintDoNotationElement (d - 1)) els)
72 text "do " <> vcat left (map (prettyPrintDoNotationElement (d - 1)) els)
63−prettyPrintValue _ (TypeClassDictionary (Constraint name tys _) _ _) = foldl1 beforeWithSpace $ text ("#dict " ++ runProperName (disqualify name)) : map typeAtomAsBox tys
73+prettyPrintValue _ (TypeClassDictionary (Constraint name tys _) _ _) = foldl1 beforeWithSpace $ text ("#dict " ++ T.unpack (runProperName (disqualify name))) : map typeAtomAsBox tys
64−prettyPrintValue _ (DeferredDictionary name _) = text $ "#dict " ++ runProperName (disqualify name)
74+prettyPrintValue _ (DeferredDictionary name _) = text $ "#dict " ++ T.unpack (runProperName (disqualify name))
65prettyPrintValue _ (TypeClassDictionaryAccessor className ident) =
75prettyPrintValue _ (TypeClassDictionaryAccessor className ident) =
66− text "#dict-accessor " <> text (runProperName (disqualify className)) <> text "." <> text (showIdent ident) <> text ">"
76+ text "#dict-accessor " <> text (T.unpack (runProperName (disqualify className))) <> text "." <> text (T.unpack (showIdent ident)) <> text ">"
67prettyPrintValue d (TypedValue _ val _) = prettyPrintValue d val
77prettyPrintValue d (TypedValue _ val _) = prettyPrintValue d val
68prettyPrintValue d (PositionedValue _ _ val) = prettyPrintValue d val
78prettyPrintValue d (PositionedValue _ _ val) = prettyPrintValue d val
69prettyPrintValue d (Literal l) = prettyPrintLiteralValue d l
79prettyPrintValue d (Literal l) = prettyPrintLiteralValue d l
70−prettyPrintValue _ (Hole name) = text "?" <> text name
80+prettyPrintValue _ (Hole name) = text "?" <> textT name
71prettyPrintValue d expr@AnonymousArgument{} = prettyPrintValueAtom d expr
81prettyPrintValue d expr@AnonymousArgument{} = prettyPrintValueAtom d expr
72prettyPrintValue d expr@Constructor{} = prettyPrintValueAtom d expr
82prettyPrintValue d expr@Constructor{} = prettyPrintValueAtom d expr
73prettyPrintValue d expr@Var{} = prettyPrintValueAtom d expr
83prettyPrintValue d expr@Var{} = prettyPrintValueAtom d expr
@@ -80,12 +90,12 @@ prettyPrintValue d expr@UnaryMinus{} = prettyPrintValueAtom d expr
80prettyPrintValueAtom :: Int -> Expr -> Box
90prettyPrintValueAtom :: Int -> Expr -> Box
81prettyPrintValueAtom d (Literal l) = prettyPrintLiteralValue d l
91prettyPrintValueAtom d (Literal l) = prettyPrintLiteralValue d l
82prettyPrintValueAtom _ AnonymousArgument = text "_"
92prettyPrintValueAtom _ AnonymousArgument = text "_"
83−prettyPrintValueAtom _ (Constructor name) = text $ runProperName (disqualify name)
93+prettyPrintValueAtom _ (Constructor name) = text $ T.unpack $ runProperName (disqualify name)
84−prettyPrintValueAtom _ (Var ident) = text $ showIdent (disqualify ident)
94+prettyPrintValueAtom _ (Var ident) = text $ T.unpack $ showIdent (disqualify ident)
85prettyPrintValueAtom d (BinaryNoParens op lhs rhs) =
95prettyPrintValueAtom d (BinaryNoParens op lhs rhs) =
86 prettyPrintValue (d - 1) lhs `beforeWithSpace` printOp op `beforeWithSpace` prettyPrintValue (d - 1) rhs
96 prettyPrintValue (d - 1) lhs `beforeWithSpace` printOp op `beforeWithSpace` prettyPrintValue (d - 1) rhs
87 where
97 where
88− printOp (Op (Qualified _ name)) = text (runOpName name)
98+ printOp (Op (Qualified _ name)) = text $ T.unpack $ runOpName name
89 printOp expr = text "`" <> prettyPrintValue (d - 1) expr <> text "`"
99 printOp expr = text "`" <> prettyPrintValue (d - 1) expr <> text "`"
90prettyPrintValueAtom d (TypedValue _ val _) = prettyPrintValueAtom d val
100prettyPrintValueAtom d (TypedValue _ val _) = prettyPrintValueAtom d val
91prettyPrintValueAtom d (PositionedValue _ _ val) = prettyPrintValueAtom d val
101prettyPrintValueAtom d (PositionedValue _ _ val) = prettyPrintValueAtom d val
@@ -105,9 +115,9 @@ prettyPrintLiteralValue d (ObjectLiteral ps) = prettyPrintObject (d - 1) $ secon
105prettyPrintDeclaration :: Int -> Declaration -> Box
115prettyPrintDeclaration :: Int -> Declaration -> Box
106prettyPrintDeclaration d _ | d < 0 = ellipsis
116prettyPrintDeclaration d _ | d < 0 = ellipsis
107prettyPrintDeclaration _ (TypeDeclaration ident ty) =
117prettyPrintDeclaration _ (TypeDeclaration ident ty) =
108− text (showIdent ident ++ " :: ") <> typeAsBox ty
118+ text (T.unpack (showIdent ident) ++ " :: ") <> typeAsBox ty
109prettyPrintDeclaration d (ValueDeclaration ident _ [] (Right val)) =
119prettyPrintDeclaration d (ValueDeclaration ident _ [] (Right val)) =
110− text (showIdent ident ++ " = ") <> prettyPrintValue (d - 1) val
120+ text (T.unpack (showIdent ident) ++ " = ") <> prettyPrintValue (d - 1) val
111prettyPrintDeclaration d (BindingGroupDeclaration ds) =
121prettyPrintDeclaration d (BindingGroupDeclaration ds) =
112 vsep 1 left (map (prettyPrintDeclaration (d - 1) . toDecl) ds)
122 vsep 1 left (map (prettyPrintDeclaration (d - 1) . toDecl) ds)
113 where
123 where
@@ -118,7 +128,7 @@ prettyPrintDeclaration _ _ = internalError "Invalid argument to prettyPrintDecla
118prettyPrintCaseAlternative :: Int -> CaseAlternative -> Box
128prettyPrintCaseAlternative :: Int -> CaseAlternative -> Box
119prettyPrintCaseAlternative d _ | d < 0 = ellipsis
129prettyPrintCaseAlternative d _ | d < 0 = ellipsis
120prettyPrintCaseAlternative d (CaseAlternative binders result) =
130prettyPrintCaseAlternative d (CaseAlternative binders result) =
121− text (unwords (map prettyPrintBinderAtom binders)) <> prettyPrintResult result
131+ text (T.unpack (T.unwords (map prettyPrintBinderAtom binders))) <> prettyPrintResult result
122 where
132 where
123 prettyPrintResult :: Either [(Guard, Expr)] Expr -> Box
133 prettyPrintResult :: Either [(Guard, Expr)] Expr -> Box
124 prettyPrintResult (Left gs) =
134 prettyPrintResult (Left gs) =
@@ -138,50 +148,50 @@ prettyPrintDoNotationElement d _ | d < 0 = ellipsis
138prettyPrintDoNotationElement d (DoNotationValue val) =
148prettyPrintDoNotationElement d (DoNotationValue val) =
139 prettyPrintValue d val
149 prettyPrintValue d val
140prettyPrintDoNotationElement d (DoNotationBind binder val) =
150prettyPrintDoNotationElement d (DoNotationBind binder val) =
141− text (prettyPrintBinder binder ++ " <- ") <> prettyPrintValue d val
151+ textT (prettyPrintBinder binder Monoid.<> " <- ") <> prettyPrintValue d val
142prettyPrintDoNotationElement d (DoNotationLet ds) =
152prettyPrintDoNotationElement d (DoNotationLet ds) =
143 text "let" //
153 text "let" //
144 moveRight 2 (vcat left (map (prettyPrintDeclaration (d - 1)) ds))
154 moveRight 2 (vcat left (map (prettyPrintDeclaration (d - 1)) ds))
145prettyPrintDoNotationElement d (PositionedDoNotationElement _ _ el) = prettyPrintDoNotationElement d el
155prettyPrintDoNotationElement d (PositionedDoNotationElement _ _ el) = prettyPrintDoNotationElement d el
146
156
147−prettyPrintBinderAtom :: Binder -> String
157+prettyPrintBinderAtom :: Binder -> Text
148prettyPrintBinderAtom NullBinder = "_"
158prettyPrintBinderAtom NullBinder = "_"
149prettyPrintBinderAtom (LiteralBinder l) = prettyPrintLiteralBinder l
159prettyPrintBinderAtom (LiteralBinder l) = prettyPrintLiteralBinder l
150prettyPrintBinderAtom (VarBinder ident) = showIdent ident
160prettyPrintBinderAtom (VarBinder ident) = showIdent ident
151prettyPrintBinderAtom (ConstructorBinder ctor []) = runProperName (disqualify ctor)
161prettyPrintBinderAtom (ConstructorBinder ctor []) = runProperName (disqualify ctor)
152−prettyPrintBinderAtom b@ConstructorBinder{} = parens (prettyPrintBinder b)
162+prettyPrintBinderAtom b@ConstructorBinder{} = parensT (prettyPrintBinder b)
153−prettyPrintBinderAtom (NamedBinder ident binder) = showIdent ident ++ "@" ++ prettyPrintBinder binder
163+prettyPrintBinderAtom (NamedBinder ident binder) = showIdent ident Monoid.<> "@" Monoid.<> prettyPrintBinder binder
154prettyPrintBinderAtom (PositionedBinder _ _ binder) = prettyPrintBinderAtom binder
164prettyPrintBinderAtom (PositionedBinder _ _ binder) = prettyPrintBinderAtom binder
155prettyPrintBinderAtom (TypedBinder _ binder) = prettyPrintBinderAtom binder
165prettyPrintBinderAtom (TypedBinder _ binder) = prettyPrintBinderAtom binder
156prettyPrintBinderAtom (OpBinder op) = runOpName (disqualify op)
166prettyPrintBinderAtom (OpBinder op) = runOpName (disqualify op)
157prettyPrintBinderAtom (BinaryNoParensBinder op b1 b2) =
167prettyPrintBinderAtom (BinaryNoParensBinder op b1 b2) =
158− prettyPrintBinderAtom b1 ++ " " ++ prettyPrintBinderAtom op ++ " " ++ prettyPrintBinderAtom b2
168+ prettyPrintBinderAtom b1 Monoid.<> " " Monoid.<> prettyPrintBinderAtom op Monoid.<> " " Monoid.<> prettyPrintBinderAtom b2
159−prettyPrintBinderAtom (ParensInBinder b) = parens (prettyPrintBinder b)
169+prettyPrintBinderAtom (ParensInBinder b) = parensT (prettyPrintBinder b)
160
170
161−prettyPrintLiteralBinder :: Literal Binder -> String
171+prettyPrintLiteralBinder :: Literal Binder -> Text
162−prettyPrintLiteralBinder (StringLiteral str) = show str
172+prettyPrintLiteralBinder (StringLiteral str) = T.pack (show str)
163−prettyPrintLiteralBinder (CharLiteral c) = show c
173+prettyPrintLiteralBinder (CharLiteral c) = T.pack (show c)
164−prettyPrintLiteralBinder (NumericLiteral num) = either show show num
174+prettyPrintLiteralBinder (NumericLiteral num) = either (T.pack . show) (T.pack . show) num
165prettyPrintLiteralBinder (BooleanLiteral True) = "true"
175prettyPrintLiteralBinder (BooleanLiteral True) = "true"
166prettyPrintLiteralBinder (BooleanLiteral False) = "false"
176prettyPrintLiteralBinder (BooleanLiteral False) = "false"
167prettyPrintLiteralBinder (ObjectLiteral bs) =
177prettyPrintLiteralBinder (ObjectLiteral bs) =
168 "{ "
178 "{ "
169− ++ intercalate ", " (map prettyPrintObjectPropertyBinder bs)
179+ Monoid.<> T.intercalate ", " (map prettyPrintObjectPropertyBinder bs)
170− ++ " }"
180+ Monoid.<> " }"
171 where
181 where
172− prettyPrintObjectPropertyBinder :: (String, Binder) -> String
182+ prettyPrintObjectPropertyBinder :: (Text, Binder) -> Text
173− prettyPrintObjectPropertyBinder (key, binder) = prettyPrintObjectKey key ++ ": " ++ prettyPrintBinder binder
183+ prettyPrintObjectPropertyBinder (key, binder) = prettyPrintObjectKey key Monoid.<> ": " Monoid.<> prettyPrintBinder binder
174prettyPrintLiteralBinder (ArrayLiteral bs) =
184prettyPrintLiteralBinder (ArrayLiteral bs) =
175 "[ "
185 "[ "
176− ++ intercalate ", " (map prettyPrintBinder bs)
186+ Monoid.<> T.intercalate ", " (map prettyPrintBinder bs)
177− ++ " ]"
187+ Monoid.<> " ]"
178
188
179-- |
189-- |
180-- Generate a pretty-printed string representing a Binder
190-- Generate a pretty-printed string representing a Binder
181--
191--
182−prettyPrintBinder :: Binder -> String
192+prettyPrintBinder :: Binder -> Text
183prettyPrintBinder (ConstructorBinder ctor []) = runProperName (disqualify ctor)
193prettyPrintBinder (ConstructorBinder ctor []) = runProperName (disqualify ctor)
184−prettyPrintBinder (ConstructorBinder ctor args) = runProperName (disqualify ctor) ++ " " ++ unwords (map prettyPrintBinderAtom args)
194+prettyPrintBinder (ConstructorBinder ctor args) = (runProperName (disqualify ctor)) Monoid.<> " " Monoid.<> T.unwords (map prettyPrintBinderAtom args)
185prettyPrintBinder (PositionedBinder _ _ binder) = prettyPrintBinder binder
195prettyPrintBinder (PositionedBinder _ _ binder) = prettyPrintBinder binder
186prettyPrintBinder (TypedBinder _ binder) = prettyPrintBinder binder
196prettyPrintBinder (TypedBinder _ binder) = prettyPrintBinder binder
187prettyPrintBinder b = prettyPrintBinderAtom b
197prettyPrintBinder b = prettyPrintBinderAtom b
src/Language/PureScript/Renamer.hs+4−2
@@ -10,7 +10,9 @@ import Control.Monad.State
10import Data.List (find)
10import Data.List (find)
11import Data.Maybe (fromJust, fromMaybe)
11import Data.Maybe (fromJust, fromMaybe)
12import qualified Data.Map as M
12import qualified Data.Map as M
13+import Data.Monoid ((<>))
13import qualified Data.Set as S
14import qualified Data.Set as S
15+import qualified Data.Text as T
14
16
15import Language.PureScript.CoreFn
17import Language.PureScript.CoreFn
16import Language.PureScript.Names
18import Language.PureScript.Names
@@ -80,7 +82,7 @@ updateScope ident =
80 getNewName usedNames name =
82 getNewName usedNames name =
81 fromJust $ find
83 fromJust $ find
82 (`S.notMember` usedNames)
84 (`S.notMember` usedNames)
83− [ Ident (runIdent name ++ show (i :: Int)) | i <- [1..] ]
85+ [ Ident (runIdent name <> T.pack (show (i :: Int))) | i <- [1..] ]
84
86
85-- |
87-- |
86-- Finds the new name to use for an ident.
88-- Finds the new name to use for an ident.
@@ -91,7 +93,7 @@ lookupIdent name = do
91 name' <- gets $ M.lookup name . rsBoundNames
93 name' <- gets $ M.lookup name . rsBoundNames
92 case name' of
94 case name' of
93 Just name'' -> return name''
95 Just name'' -> return name''
94− Nothing -> error $ "Rename scope is missing ident '" ++ showIdent name ++ "'"
96+ Nothing -> error $ "Rename scope is missing ident '" ++ T.unpack (showIdent name) ++ "'"
95
97
96-- |
98-- |
97-- Finds idents introduced by declarations.
99-- Finds idents introduced by declarations.
src/Language/PureScript/Sugar/ObjectWildcards.hs+4−3
@@ -11,6 +11,7 @@ import Control.Monad.Supply.Class
11
11
12import Data.List (partition)
12import Data.List (partition)
13import Data.Maybe (catMaybes)
13import Data.Maybe (catMaybes)
14+import Data.Text (Text)
14
15
15import Language.PureScript.AST
16import Language.PureScript.AST
16import Language.PureScript.Errors
17import Language.PureScript.Errors
@@ -61,7 +62,7 @@ desugarDecl other = fn other
61 return $ foldr (Abs . Left) if_ (catMaybes [u', t', f'])
62 return $ foldr (Abs . Left) if_ (catMaybes [u', t', f'])
62 desugarExpr e = return e
63 desugarExpr e = return e
63
64
64− wrapLambda :: ([(String, Expr)] -> Expr) -> [(String, Expr)] -> m Expr
65+ wrapLambda :: ([(Text, Expr)] -> Expr) -> [(Text, Expr)] -> m Expr
65 wrapLambda mkVal ps =
66 wrapLambda mkVal ps =
66 let (args, props) = partition (isAnonymousArgument . snd) ps
67 let (args, props) = partition (isAnonymousArgument . snd) ps
67 in if null args
68 in if null args
@@ -74,7 +75,7 @@ desugarDecl other = fn other
74 stripPositionInfo (PositionedValue _ _ e) = stripPositionInfo e
75 stripPositionInfo (PositionedValue _ _ e) = stripPositionInfo e
75 stripPositionInfo e = e
76 stripPositionInfo e = e
76
77
77− peelAnonAccessorChain :: Expr -> Maybe [String]
78+ peelAnonAccessorChain :: Expr -> Maybe [Text]
78 peelAnonAccessorChain (Accessor p e) = (p :) <$> peelAnonAccessorChain e
79 peelAnonAccessorChain (Accessor p e) = (p :) <$> peelAnonAccessorChain e
79 peelAnonAccessorChain (PositionedValue _ _ e) = peelAnonAccessorChain e
80 peelAnonAccessorChain (PositionedValue _ _ e) = peelAnonAccessorChain e
80 peelAnonAccessorChain AnonymousArgument = Just []
81 peelAnonAccessorChain AnonymousArgument = Just []
@@ -85,7 +86,7 @@ desugarDecl other = fn other
85 isAnonymousArgument (PositionedValue _ _ e) = isAnonymousArgument e
86 isAnonymousArgument (PositionedValue _ _ e) = isAnonymousArgument e
86 isAnonymousArgument _ = False
87 isAnonymousArgument _ = False
87
88
88− mkProp :: (String, Expr) -> m (Maybe Ident, (String, Expr))
89+ mkProp :: (Text, Expr) -> m (Maybe Ident, (Text, Expr))
89 mkProp (name, e) = do
90 mkProp (name, e) = do
90 arg <- freshIfAnon e
91 arg <- freshIfAnon e
91 return (arg, (name, maybe e argToExpr arg))
92 return (arg, (name, maybe e argToExpr arg))
src/Language/PureScript/Sugar/TypeClasses.hs+8−6
@@ -27,8 +27,10 @@ import Control.Monad.Error.Class (MonadError(..))
27import Control.Monad.State
27import Control.Monad.State
28import Data.List ((\\), find, sortBy)
28import Data.List ((\\), find, sortBy)
29import Data.Maybe (catMaybes, mapMaybe, isJust)
29import Data.Maybe (catMaybes, mapMaybe, isJust)
30−
31import qualified Data.Map as M
30import qualified Data.Map as M
31+import Data.Monoid ((<>))
32+import Data.Text (Text)
33+import qualified Data.Text as T
32
34
33type MemberMap = M.Map (ModuleName, ProperName 'ClassName) TypeClassData
35type MemberMap = M.Map (ModuleName, ProperName 'ClassName) TypeClassData
34
36
@@ -231,7 +233,7 @@ memberToNameAndType _ = internalError "Invalid declaration in type class definit
231
233
232typeClassDictionaryDeclaration
234typeClassDictionaryDeclaration
233 :: ProperName 'ClassName
235 :: ProperName 'ClassName
234− -> [(String, Maybe Kind)]
236+ -> [(Text, Maybe Kind)]
235 -> [Constraint]
237 -> [Constraint]
236 -> [Declaration]
238 -> [Declaration]
237 -> Declaration
239 -> Declaration
@@ -247,7 +249,7 @@ typeClassDictionaryDeclaration name args implies members =
247typeClassMemberToDictionaryAccessor
249typeClassMemberToDictionaryAccessor
248 :: ModuleName
250 :: ModuleName
249 -> ProperName 'ClassName
251 -> ProperName 'ClassName
250− -> [(String, Maybe Kind)]
252+ -> [(Text, Maybe Kind)]
251 -> Declaration
253 -> Declaration
252 -> Declaration
254 -> Declaration
253typeClassMemberToDictionaryAccessor mn name args (TypeDeclaration ident ty) =
255typeClassMemberToDictionaryAccessor mn name args (TypeDeclaration ident ty) =
@@ -323,14 +325,14 @@ typeInstanceDictionaryDeclaration name mn deps className tys decls =
323 return (PositionedValue pos com val)
325 return (PositionedValue pos com val)
324 memberToValue _ _ = internalError "Invalid declaration in type instance definition"
326 memberToValue _ _ = internalError "Invalid declaration in type instance definition"
325
327
326−typeClassMemberName :: Declaration -> String
328+typeClassMemberName :: Declaration -> Text
327typeClassMemberName (TypeDeclaration ident _) = runIdent ident
329typeClassMemberName (TypeDeclaration ident _) = runIdent ident
328typeClassMemberName (ValueDeclaration ident _ _ _) = runIdent ident
330typeClassMemberName (ValueDeclaration ident _ _ _) = runIdent ident
329typeClassMemberName (PositionedDeclaration _ _ d) = typeClassMemberName d
331typeClassMemberName (PositionedDeclaration _ _ d) = typeClassMemberName d
330typeClassMemberName _ = internalError "typeClassMemberName: Invalid declaration in type class definition"
332typeClassMemberName _ = internalError "typeClassMemberName: Invalid declaration in type class definition"
331
333
332−superClassDictionaryNames :: [Constraint] -> [String]
334+superClassDictionaryNames :: [Constraint] -> [Text]
333superClassDictionaryNames supers =
335superClassDictionaryNames supers =
334− [ C.__superclass_ ++ showQualified runProperName pn ++ "_" ++ show (index :: Integer)
336+ [ C.__superclass_ <> showQualified runProperName pn <> "_" <> T.pack (show (index :: Integer))
335 | (index, Constraint pn _ _) <- zip [0..] supers
337 | (index, Constraint pn _ _) <- zip [0..] supers
336 ]
338 ]
src/Language/PureScript/Sugar/TypeClasses/Deriving.hs+8−7
@@ -16,6 +16,7 @@ import Control.Monad.Supply.Class (MonadSupply)
16import Data.List (foldl', find, sortBy, unzip5)
16import Data.List (foldl', find, sortBy, unzip5)
17import Data.Maybe (fromMaybe)
17import Data.Maybe (fromMaybe)
18import Data.Ord (comparing)
18import Data.Ord (comparing)
19+import Data.Text (Text)
19
20
20import Language.PureScript.AST
21import Language.PureScript.AST
21import Language.PureScript.Crash
22import Language.PureScript.Crash
@@ -118,7 +119,7 @@ deriveNewtypeInstance className ds tys tyConNm dargs = do
118 takeReverse :: Int -> [a] -> [a]
119 takeReverse :: Int -> [a] -> [a]
119 takeReverse n = take n . reverse
120 takeReverse n = take n . reverse
120
121
121− stripRight :: [(String, Maybe kind)] -> Type -> Maybe Type
122+ stripRight :: [(Text, Maybe kind)] -> Type -> Maybe Type
122 stripRight [] ty = Just ty
123 stripRight [] ty = Just ty
123 stripRight ((arg, _) : args) (TypeApp t (TypeVar arg'))
124 stripRight ((arg, _) : args) (TypeApp t (TypeVar arg'))
124 | arg == arg' = stripRight args t
125 | arg == arg' = stripRight args t
@@ -285,14 +286,14 @@ deriveGeneric mn ds tyConNm dargs = do
285 (App e unitVal)
286 (App e unitVal)
286 fromSpineFun e _ = App (mkGenVar (Ident C.fromSpine)) (App e unitVal)
287 fromSpineFun e _ = App (mkGenVar (Ident C.fromSpine)) (App e unitVal)
287
288
288− mkRecCase :: [(String, Type)] -> CaseAlternative
289+ mkRecCase :: [(Text, Type)] -> CaseAlternative
289 mkRecCase rs =
290 mkRecCase rs =
290 CaseAlternative
291 CaseAlternative
291 [ recordBinder [ LiteralBinder (ArrayLiteral (map (VarBinder . Ident . fst) rs)) ] ]
292 [ recordBinder [ LiteralBinder (ArrayLiteral (map (VarBinder . Ident . fst) rs)) ] ]
292 . Right
293 . Right
293 $ liftApplicative (mkRecFun rs) (map (\(x, y) -> fromSpineFun (Accessor "recValue" (mkVar (Ident x))) y) rs)
294 $ liftApplicative (mkRecFun rs) (map (\(x, y) -> fromSpineFun (Accessor "recValue" (mkVar (Ident x))) y) rs)
294
295
295− mkRecFun :: [(String, Type)] -> Expr
296+ mkRecFun :: [(Text, Type)] -> Expr
296 mkRecFun xs = mkJust $ foldr (lam . Ident . fst) recLiteral xs
297 mkRecFun xs = mkJust $ foldr (lam . Ident . fst) recLiteral xs
297 where recLiteral = Literal . ObjectLiteral $ map (\(s,_) -> (s, mkVar (Ident s))) xs
298 where recLiteral = Literal . ObjectLiteral $ map (\(s,_) -> (s, mkVar (Ident s))) xs
298 mkFromSpineFunction (PositionedDeclaration _ _ d) = mkFromSpineFunction d
299 mkFromSpineFunction (PositionedDeclaration _ _ d) = mkFromSpineFunction d
@@ -576,13 +577,13 @@ deriveOrd mn ds tyConNm = do
576 where
577 where
577 catchAll = CaseAlternative [NullBinder, NullBinder] (Right (orderingCtor "EQ"))
578 catchAll = CaseAlternative [NullBinder, NullBinder] (Right (orderingCtor "EQ"))
578
579
579− orderingName :: String -> Qualified (ProperName a)
580+ orderingName :: Text -> Qualified (ProperName a)
580 orderingName = Qualified (Just (ModuleName [ProperName "Data", ProperName "Ordering"])) . ProperName
581 orderingName = Qualified (Just (ModuleName [ProperName "Data", ProperName "Ordering"])) . ProperName
581
582
582− orderingCtor :: String -> Expr
583+ orderingCtor :: Text -> Expr
583 orderingCtor = Constructor . orderingName
584 orderingCtor = Constructor . orderingName
584
585
585− orderingBinder :: String -> Binder
586+ orderingBinder :: Text -> Binder
586 orderingBinder name = ConstructorBinder (orderingName name) []
587 orderingBinder name = ConstructorBinder (orderingName name) []
587
588
588 ordCompare :: Expr -> Expr -> Expr
589 ordCompare :: Expr -> Expr -> Expr
@@ -700,7 +701,7 @@ objectType :: Type -> Maybe Type
700objectType (TypeApp (TypeConstructor (Qualified (Just (ModuleName [ProperName "Prim"])) (ProperName "Record"))) rec) = Just rec
701objectType (TypeApp (TypeConstructor (Qualified (Just (ModuleName [ProperName "Prim"])) (ProperName "Record"))) rec) = Just rec
701objectType _ = Nothing
702objectType _ = Nothing
702
703
703−decomposeRec :: Type -> [(String, Type)]
704+decomposeRec :: Type -> [(Text, Type)]
704decomposeRec = sortBy (comparing fst) . go
705decomposeRec = sortBy (comparing fst) . go
705 where go (RCons str typ typs) = (str, typ) : decomposeRec typs
706 where go (RCons str typ typs) = (str, typ) : decomposeRec typs
706 go _ = []
707 go _ = []
src/Language/PureScript/TypeChecker.hs+11−8
@@ -22,6 +22,9 @@ import Data.Foldable (for_, traverse_)
22import Data.List (nub, nubBy, (\\), sort, group)
22import Data.List (nub, nubBy, (\\), sort, group)
23import Data.Maybe
23import Data.Maybe
24import qualified Data.Map as M
24import qualified Data.Map as M
25+import Data.Monoid ((<>))
26+import qualified Data.Text as T
27+import Data.Text (Text)
25
28
26import Language.PureScript.AST
29import Language.PureScript.AST
27import Language.PureScript.Crash
30import Language.PureScript.Crash
@@ -43,7 +46,7 @@ addDataType
43 => ModuleName
46 => ModuleName
44 -> DataDeclType
47 -> DataDeclType
45 -> ProperName 'TypeName
48 -> ProperName 'TypeName
46− -> [(String, Maybe Kind)]
49+ -> [(Text, Maybe Kind)]
47 -> [(ProperName 'ConstructorName, [Type])]
50 -> [(ProperName 'ConstructorName, [Type])]
48 -> Kind
51 -> Kind
49 -> m ()
52 -> m ()
@@ -59,7 +62,7 @@ addDataConstructor
59 => ModuleName
62 => ModuleName
60 -> DataDeclType
63 -> DataDeclType
61 -> ProperName 'TypeName
64 -> ProperName 'TypeName
62− -> [String]
65+ -> [Text]
63 -> ProperName 'ConstructorName
66 -> ProperName 'ConstructorName
64 -> [Type]
67 -> [Type]
65 -> m ()
68 -> m ()
@@ -69,14 +72,14 @@ addDataConstructor moduleName dtype name args dctor tys = do
69 let retTy = foldl TypeApp (TypeConstructor (Qualified (Just moduleName) name)) (map TypeVar args)
72 let retTy = foldl TypeApp (TypeConstructor (Qualified (Just moduleName) name)) (map TypeVar args)
70 let dctorTy = foldr function retTy tys
73 let dctorTy = foldr function retTy tys
71 let polyType = mkForAll args dctorTy
74 let polyType = mkForAll args dctorTy
72− let fields = [Ident ("value" ++ show n) | n <- [0..(length tys - 1)]]
75+ let fields = [Ident ("value" <> T.pack (show n)) | n <- [0..(length tys - 1)]]
73 putEnv $ env { dataConstructors = M.insert (Qualified (Just moduleName) dctor) (dtype, name, polyType, fields) (dataConstructors env) }
76 putEnv $ env { dataConstructors = M.insert (Qualified (Just moduleName) dctor) (dtype, name, polyType, fields) (dataConstructors env) }
74
77
75addTypeSynonym
78addTypeSynonym
76 :: (MonadState CheckState m, MonadError MultipleErrors m)
79 :: (MonadState CheckState m, MonadError MultipleErrors m)
77 => ModuleName
80 => ModuleName
78 -> ProperName 'TypeName
81 -> ProperName 'TypeName
79− -> [(String, Maybe Kind)]
82+ -> [(Text, Maybe Kind)]
80 -> Type
83 -> Type
81 -> Kind
84 -> Kind
82 -> m ()
85 -> m ()
@@ -112,7 +115,7 @@ addTypeClass
112 :: (MonadState CheckState m)
115 :: (MonadState CheckState m)
113 => ModuleName
116 => ModuleName
114 -> ProperName 'ClassName
117 -> ProperName 'ClassName
115− -> [(String, Maybe Kind)]
118+ -> [(Text, Maybe Kind)]
116 -> [Constraint]
119 -> [Constraint]
117 -> [FunctionalDependency]
120 -> [FunctionalDependency]
118 -> [Declaration]
121 -> [Declaration]
@@ -143,12 +146,12 @@ addTypeClassDictionaries mn entries =
143
146
144checkDuplicateTypeArguments
147checkDuplicateTypeArguments
145 :: (MonadState CheckState m, MonadError MultipleErrors m)
148 :: (MonadState CheckState m, MonadError MultipleErrors m)
146− => [String]
149+ => [Text]
147 -> m ()
150 -> m ()
148checkDuplicateTypeArguments args = for_ firstDup $ \dup ->
151checkDuplicateTypeArguments args = for_ firstDup $ \dup ->
149 throwError . errorMessage $ DuplicateTypeArgument dup
152 throwError . errorMessage $ DuplicateTypeArgument dup
150 where
153 where
151− firstDup :: Maybe String
154+ firstDup :: Maybe Text
152 firstDup = listToMaybe $ args \\ nub args
155 firstDup = listToMaybe $ args \\ nub args
153
156
154checkTypeClassInstance
157checkTypeClassInstance
@@ -325,7 +328,7 @@ typeCheckAll moduleName _ = traverse go
325 -- This function adds the argument kinds for a type constructor so that they may appear in the externs file,
328 -- This function adds the argument kinds for a type constructor so that they may appear in the externs file,
326 -- extracted from the kind of the type constructor itself.
329 -- extracted from the kind of the type constructor itself.
327 --
330 --
328− withKinds :: [(String, Maybe Kind)] -> Kind -> [(String, Maybe Kind)]
331+ withKinds :: [(Text, Maybe Kind)] -> Kind -> [(Text, Maybe Kind)]
329 withKinds [] _ = []
332 withKinds [] _ = []
330 withKinds (s@(_, Just _ ):ss) (FunKind _ k) = s : withKinds ss k
333 withKinds (s@(_, Just _ ):ss) (FunKind _ k) = s : withKinds ss k
331 withKinds ( (s, Nothing):ss) (FunKind k1 k2) = (s, Just k1) : withKinds ss k2
334 withKinds ( (s, Nothing):ss) (FunKind k1 k2) = (s, Just k1) : withKinds ss k2
src/Language/PureScript/TypeChecker/Entailment.hs+9−7
@@ -25,6 +25,8 @@ import Data.List (minimumBy, nub)
25import Data.Maybe (fromMaybe, maybeToList, mapMaybe)
25import Data.Maybe (fromMaybe, maybeToList, mapMaybe)
26import qualified Data.Map as M
26import qualified Data.Map as M
27import qualified Data.Set as S
27import qualified Data.Set as S
28+import qualified Data.Text as T
29+import Data.Text (Text)
28
30
29import Language.PureScript.AST
31import Language.PureScript.AST
30import Language.PureScript.Crash
32import Language.PureScript.Crash
@@ -41,7 +43,7 @@ import qualified Language.PureScript.Constants as C
41data Evidence
43data Evidence
42 = NamedInstance (Qualified Ident)
44 = NamedInstance (Qualified Ident)
43 -- ^ An existing named instance
45 -- ^ An existing named instance
44− | IsSymbolInstance String
46+ | IsSymbolInstance Text
45 -- ^ Computed instance of the IsSymbol type class for a given Symbol literal
47 -- ^ Computed instance of the IsSymbol type class for a given Symbol literal
46 deriving (Eq)
48 deriving (Eq)
47
49
@@ -62,7 +64,7 @@ type InstanceContext = M.Map (Maybe ModuleName)
62--
64--
63-- Note: we store many types per type variable name. For any name, all types
65-- Note: we store many types per type variable name. For any name, all types
64-- should unify if we are going to commit to an instance.
66-- should unify if we are going to commit to an instance.
65−type Matching a = M.Map String a
67+type Matching a = M.Map Text a
66
68
67combineContexts :: InstanceContext -> InstanceContext -> InstanceContext
69combineContexts :: InstanceContext -> InstanceContext -> InstanceContext
68combineContexts = M.unionWith (M.unionWith M.union)
70combineContexts = M.unionWith (M.unionWith M.union)
@@ -202,7 +204,7 @@ entails SolverOptions{..} constraint context hints =
202 return match
204 return match
203 Unsolved unsolved -> do
205 Unsolved unsolved -> do
204 -- Generate a fresh name for the unsolved constraint's new dictionary
206 -- Generate a fresh name for the unsolved constraint's new dictionary
205− ident <- freshIdent ("dict" ++ runProperName (disqualify (constraintClass unsolved)))
207+ ident <- freshIdent ("dict" <> runProperName (disqualify (constraintClass unsolved)))
206 let qident = Qualified Nothing ident
208 let qident = Qualified Nothing ident
207 -- Store the new dictionary in the InstanceContext so that we can solve this goal in
209 -- Store the new dictionary in the InstanceContext so that we can solve this goal in
208 -- future.
210 -- future.
@@ -296,7 +298,7 @@ entails SolverOptions{..} constraint context hints =
296 -- Turn a DictionaryValue into a Expr
298 -- Turn a DictionaryValue into a Expr
297 subclassDictionaryValue :: Expr -> Qualified (ProperName a) -> Integer -> Expr
299 subclassDictionaryValue :: Expr -> Qualified (ProperName a) -> Integer -> Expr
298 subclassDictionaryValue dict superclassName index =
300 subclassDictionaryValue dict superclassName index =
299− App (Accessor (C.__superclass_ ++ showQualified runProperName superclassName ++ "_" ++ show index)
301+ App (Accessor (C.__superclass_ <> showQualified runProperName superclassName <> "_" <> T.pack (show index))
300 dict)
302 dict)
301 valUndefined
303 valUndefined
302
304
@@ -362,7 +364,7 @@ matches deps TypeClassDictionaryInScope{..} tys = do
362 sd1 = [ (name, t1) | (name, t1) <- s1, name `notElem` map fst s2 ]
364 sd1 = [ (name, t1) | (name, t1) <- s1, name `notElem` map fst s2 ]
363 sd2 = [ (name, t2) | (name, t2) <- s2, name `notElem` map fst s1 ]
365 sd2 = [ (name, t2) | (name, t2) <- s2, name `notElem` map fst s1 ]
364
366
365− go :: [(String, Type)] -> Type -> [(String, Type)] -> Type -> (Bool, Matching [Type])
367+ go :: [(Text, Type)] -> Type -> [(Text, Type)] -> Type -> (Bool, Matching [Type])
366 go [] REmpty [] REmpty = (True, M.empty)
368 go [] REmpty [] REmpty = (True, M.empty)
367 go [] (TUnknown u1) [] (TUnknown u2) | u1 == u2 = (True, M.empty)
369 go [] (TUnknown u1) [] (TUnknown u2) | u1 == u2 = (True, M.empty)
368 go [] (TypeVar v1) [] (TypeVar v2) | v1 == v2 = (True, M.empty)
370 go [] (TypeVar v1) [] (TypeVar v2) | v1 == v2 = (True, M.empty)
@@ -400,7 +402,7 @@ matches deps TypeClassDictionaryInScope{..} tys = do
400 sd2 = [ (name, t2) | (name, t2) <- s2, name `notElem` map fst s1 ]
402 sd2 = [ (name, t2) | (name, t2) <- s2, name `notElem` map fst s1 ]
401 in all (uncurry typesAreEqual) int && go sd1 r1' sd2 r2'
403 in all (uncurry typesAreEqual) int && go sd1 r1' sd2 r2'
402 where
404 where
403− go :: [(String, Type)] -> Type -> [(String, Type)] -> Type -> Bool
405+ go :: [(Text, Type)] -> Type -> [(Text, Type)] -> Type -> Bool
404 go [] (TUnknown u1) [] (TUnknown u2) | u1 == u2 = True
406 go [] (TUnknown u1) [] (TUnknown u2) | u1 == u2 = True
405 go [] (Skolem _ s1 _ _) [] (Skolem _ s2 _ _) = s1 == s2
407 go [] (Skolem _ s1 _ _) [] (Skolem _ s2 _ _) = s1 == s2
406 go [] REmpty [] REmpty = True
408 go [] REmpty [] REmpty = True
@@ -430,7 +432,7 @@ newDictionaries path name (Constraint className instanceTy _) = do
430 ) typeClassSuperclasses [0..]
432 ) typeClassSuperclasses [0..]
431 return (TypeClassDictionaryInScope name path className instanceTy Nothing : supDicts)
433 return (TypeClassDictionaryInScope name path className instanceTy Nothing : supDicts)
432 where
434 where
433− instantiateSuperclass :: [String] -> [Type] -> [Type] -> [Type]
435+ instantiateSuperclass :: [Text] -> [Type] -> [Type] -> [Type]
434 instantiateSuperclass args supArgs tys = map (replaceAllTypeVars (zip args tys)) supArgs
436 instantiateSuperclass args supArgs tys = map (replaceAllTypeVars (zip args tys)) supArgs
435
437
436mkContext :: [NamedDict] -> InstanceContext
438mkContext :: [NamedDict] -> InstanceContext
src/Language/PureScript/TypeChecker/Kinds.hs+8−7
@@ -18,6 +18,7 @@ import Control.Monad.Error.Class (MonadError(..))
18import Control.Monad.State
18import Control.Monad.State
19
19
20import qualified Data.Map as M
20import qualified Data.Map as M
21+import Data.Text (Text)
21
22
22import Language.PureScript.Crash
23import Language.PureScript.Crash
23import Language.PureScript.Environment
24import Language.PureScript.Environment
@@ -104,7 +105,7 @@ kindOf ty = fst <$> kindOfWithScopedVars ty
104kindOfWithScopedVars ::
105kindOfWithScopedVars ::
105 (MonadError MultipleErrors m, MonadState CheckState m) =>
106 (MonadError MultipleErrors m, MonadState CheckState m) =>
106 Type ->
107 Type ->
107− m (Kind, [(String, Kind)])
108+ m (Kind, [(Text, Kind)])
108kindOfWithScopedVars ty =
109kindOfWithScopedVars ty =
109 withErrorMessageHint (ErrorCheckingKind ty) $
110 withErrorMessageHint (ErrorCheckingKind ty) $
110 fmap tidyUp . withFreshSubstitution . captureSubstitution $ infer ty
111 fmap tidyUp . withFreshSubstitution . captureSubstitution $ infer ty
@@ -119,7 +120,7 @@ kindsOf
119 => Bool
120 => Bool
120 -> ModuleName
121 -> ModuleName
121 -> ProperName 'TypeName
122 -> ProperName 'TypeName
122− -> [(String, Maybe Kind)]
123+ -> [(Text, Maybe Kind)]
123 -> [Type]
124 -> [Type]
124 -> m Kind
125 -> m Kind
125kindsOf isData moduleName name args ts = fmap tidyUp . withFreshSubstitution . captureSubstitution $ do
126kindsOf isData moduleName name args ts = fmap tidyUp . withFreshSubstitution . captureSubstitution $ do
@@ -134,7 +135,7 @@ kindsOf isData moduleName name args ts = fmap tidyUp . withFreshSubstitution . c
134
135
135freshKindVar
136freshKindVar
136 :: (MonadError MultipleErrors m, MonadState CheckState m)
137 :: (MonadError MultipleErrors m, MonadState CheckState m)
137− => (String, Maybe Kind)
138+ => (Text, Maybe Kind)
138 -> Kind
139 -> Kind
139 -> m (ProperName 'TypeName, Kind)
140 -> m (ProperName 'TypeName, Kind)
140freshKindVar (arg, Nothing) kind = return (ProperName arg, kind)
141freshKindVar (arg, Nothing) kind = return (ProperName arg, kind)
@@ -146,8 +147,8 @@ freshKindVar (arg, Just kind') kind = do
146kindsOfAll
147kindsOfAll
147 :: (MonadError MultipleErrors m, MonadState CheckState m)
148 :: (MonadError MultipleErrors m, MonadState CheckState m)
148 => ModuleName
149 => ModuleName
149− -> [(ProperName 'TypeName, [(String, Maybe Kind)], Type)]
150+ -> [(ProperName 'TypeName, [(Text, Maybe Kind)], Type)]
150− -> [(ProperName 'TypeName, [(String, Maybe Kind)], [Type])]
151+ -> [(ProperName 'TypeName, [(Text, Maybe Kind)], [Type])]
151 -> m ([Kind], [Kind])
152 -> m ([Kind], [Kind])
152kindsOfAll moduleName syns tys = fmap tidyUp . withFreshSubstitution . captureSubstitution $ do
153kindsOfAll moduleName syns tys = fmap tidyUp . withFreshSubstitution . captureSubstitution $ do
153 synVars <- replicateM (length syns) freshKind
154 synVars <- replicateM (length syns) freshKind
@@ -198,14 +199,14 @@ starIfUnknown k = k
198infer
199infer
199 :: (MonadError MultipleErrors m, MonadState CheckState m)
200 :: (MonadError MultipleErrors m, MonadState CheckState m)
200 => Type
201 => Type
201− -> m (Kind, [(String, Kind)])
202+ -> m (Kind, [(Text, Kind)])
202infer ty = withErrorMessageHint (ErrorCheckingKind ty) $ infer' ty
203infer ty = withErrorMessageHint (ErrorCheckingKind ty) $ infer' ty
203
204
204infer'
205infer'
205 :: forall m
206 :: forall m
206 . (MonadError MultipleErrors m, MonadState CheckState m)
207 . (MonadError MultipleErrors m, MonadState CheckState m)
207 => Type
208 => Type
208− -> m (Kind, [(String, Kind)])
209+ -> m (Kind, [(Text, Kind)])
209infer' (ForAll ident ty _) = do
210infer' (ForAll ident ty _) = do
210 k1 <- freshKind
211 k1 <- freshKind
211 Just moduleName <- checkCurrentModule <$> get
212 Just moduleName <- checkCurrentModule <$> get
src/Language/PureScript/TypeChecker/Monad.hs+2−1
@@ -15,6 +15,7 @@ import Control.Monad.Writer.Class (MonadWriter(..), censor)
15
15
16import Data.Maybe
16import Data.Maybe
17import qualified Data.Map as M
17import qualified Data.Map as M
18+import Data.Text (Text)
18
19
19import Language.PureScript.Environment
20import Language.PureScript.Environment
20import Language.PureScript.Errors
21import Language.PureScript.Errors
@@ -93,7 +94,7 @@ bindTypes newNames action = do
93withScopedTypeVars
94withScopedTypeVars
94 :: (MonadState CheckState m, MonadWriter MultipleErrors m)
95 :: (MonadState CheckState m, MonadWriter MultipleErrors m)
95 => ModuleName
96 => ModuleName
96− -> [(String, Kind)]
97+ -> [(Text, Kind)]
97 -> m a
98 -> m a
98 -> m a
99 -> m a
99withScopedTypeVars mn ks ma = do
100withScopedTypeVars mn ks ma = do
src/Language/PureScript/TypeChecker/Skolems.hs+6−5
@@ -18,6 +18,7 @@ import Control.Monad.State.Class (MonadState(..), gets, modify)
18import Data.Functor.Identity (Identity(), runIdentity)
18import Data.Functor.Identity (Identity(), runIdentity)
19import Data.List (nub, (\\))
19import Data.List (nub, (\\))
20import Data.Monoid
20import Data.Monoid
21+import Data.Text (Text)
21
22
22import Language.PureScript.AST
23import Language.PureScript.AST
23import Language.PureScript.Crash
24import Language.PureScript.Crash
@@ -56,7 +57,7 @@ newSkolemScope = do
56-- |
57-- |
57-- Skolemize a type variable by replacing its instances with fresh skolem constants
58-- Skolemize a type variable by replacing its instances with fresh skolem constants
58--
59--
59−skolemize :: String -> Int -> SkolemScope -> Maybe SourceSpan -> Type -> Type
60+skolemize :: Text -> Int -> SkolemScope -> Maybe SourceSpan -> Type -> Type
60skolemize ident sko scope ss = replaceTypeVars ident (Skolem ident sko scope ss)
61skolemize ident sko scope ss = replaceTypeVars ident (Skolem ident sko scope ss)
61
62
62-- |
63-- |
@@ -64,25 +65,25 @@ skolemize ident sko scope ss = replaceTypeVars ident (Skolem ident sko scope ss)
64-- DeferredDictionary placeholder. These type variables are somewhat unique since they are the
65-- DeferredDictionary placeholder. These type variables are somewhat unique since they are the
65-- only example of scoped type variables.
66-- only example of scoped type variables.
66--
67--
67−skolemizeTypesInValue :: String -> Int -> SkolemScope -> Maybe SourceSpan -> Expr -> Expr
68+skolemizeTypesInValue :: Text -> Int -> SkolemScope -> Maybe SourceSpan -> Expr -> Expr
68skolemizeTypesInValue ident sko scope ss =
69skolemizeTypesInValue ident sko scope ss =
69 let
70 let
70 (_, f, _, _, _) = everywhereWithContextOnValuesM [] defS onExpr onBinder defS defS
71 (_, f, _, _, _) = everywhereWithContextOnValuesM [] defS onExpr onBinder defS defS
71 in runIdentity . f
72 in runIdentity . f
72 where
73 where
73− onExpr :: [String] -> Expr -> Identity ([String], Expr)
74+ onExpr :: [Text] -> Expr -> Identity ([Text], Expr)
74 onExpr sco (DeferredDictionary c ts)
75 onExpr sco (DeferredDictionary c ts)
75 | ident `notElem` sco = return (sco, DeferredDictionary c (map (skolemize ident sko scope ss) ts))
76 | ident `notElem` sco = return (sco, DeferredDictionary c (map (skolemize ident sko scope ss) ts))
76 onExpr sco (TypedValue check val ty)
77 onExpr sco (TypedValue check val ty)
77 | ident `notElem` sco = return (sco ++ peelTypeVars ty, TypedValue check val (skolemize ident sko scope ss ty))
78 | ident `notElem` sco = return (sco ++ peelTypeVars ty, TypedValue check val (skolemize ident sko scope ss ty))
78 onExpr sco other = return (sco, other)
79 onExpr sco other = return (sco, other)
79
80
80− onBinder :: [String] -> Binder -> Identity ([String], Binder)
81+ onBinder :: [Text] -> Binder -> Identity ([Text], Binder)
81 onBinder sco (TypedBinder ty b)
82 onBinder sco (TypedBinder ty b)
82 | ident `notElem` sco = return (sco ++ peelTypeVars ty, TypedBinder (skolemize ident sko scope ss ty) b)
83 | ident `notElem` sco = return (sco ++ peelTypeVars ty, TypedBinder (skolemize ident sko scope ss ty) b)
83 onBinder sco other = return (sco, other)
84 onBinder sco other = return (sco, other)
84
85
85− peelTypeVars :: Type -> [String]
86+ peelTypeVars :: Type -> [Text]
86 peelTypeVars (ForAll i ty _) = i : peelTypeVars ty
87 peelTypeVars (ForAll i ty _) = i : peelTypeVars ty
87 peelTypeVars _ = []
88 peelTypeVars _ = []
88
89
src/Language/PureScript/TypeChecker/Types.hs+7−6
@@ -1,5 +1,4 @@
1{-# LANGUAGE LambdaCase #-}
1{-# LANGUAGE LambdaCase #-}
2−{-# LANGUAGE OverloadedStrings #-}
3{-# LANGUAGE NamedFieldPuns #-}
2{-# LANGUAGE NamedFieldPuns #-}
4
3
5-- |
4-- |
@@ -40,8 +39,10 @@ import Data.Either (lefts, rights)
40import Data.Functor (($>))
39import Data.Functor (($>))
41import Data.List (transpose, nub, (\\), partition, delete)
40import Data.List (transpose, nub, (\\), partition, delete)
42import Data.Maybe (fromMaybe)
41import Data.Maybe (fromMaybe)
42+import Data.Monoid ((<>))
43import qualified Data.Map as M
43import qualified Data.Map as M
44import qualified Data.Set as S
44import qualified Data.Set as S
45+import Data.Text (Text)
45
46
46import Language.PureScript.AST
47import Language.PureScript.AST
47import Language.PureScript.Crash
48import Language.PureScript.Crash
@@ -442,7 +443,7 @@ inferBinder val (LiteralBinder (ObjectLiteral props)) = do
442 unifyTypes val (TypeApp tyRecord row)
443 unifyTypes val (TypeApp tyRecord row)
443 return m1
444 return m1
444 where
445 where
445− inferRowProperties :: Type -> Type -> [(String, Binder)] -> m (M.Map Ident Type)
446+ inferRowProperties :: Type -> Type -> [(Text, Binder)] -> m (M.Map Ident Type)
446 inferRowProperties nrow row [] = unifyTypes nrow row >> return M.empty
447 inferRowProperties nrow row [] = unifyTypes nrow row >> return M.empty
447 inferRowProperties nrow row ((name, binder):binders) = do
448 inferRowProperties nrow row ((name, binder):binders) = do
448 propTy <- freshType
449 propTy <- freshType
@@ -559,7 +560,7 @@ check' val (ForAll ident ty _) = do
559 return $ TypedValue True val' (ForAll ident ty (Just scope))
560 return $ TypedValue True val' (ForAll ident ty (Just scope))
560check' val t@(ConstrainedType constraints ty) = do
561check' val t@(ConstrainedType constraints ty) = do
561 dictNames <- forM constraints $ \(Constraint (Qualified _ (ProperName className)) _ _) ->
562 dictNames <- forM constraints $ \(Constraint (Qualified _ (ProperName className)) _ _) ->
562− freshIdent ("dict" ++ className)
563+ freshIdent ("dict" <> className)
563 dicts <- join <$> zipWithM (newDictionaries []) (map (Qualified Nothing) dictNames) constraints
564 dicts <- join <$> zipWithM (newDictionaries []) (map (Qualified Nothing) dictNames) constraints
564 val' <- withBindingGroupVisible $ withTypeClassDictionaries dicts $ check val ty
565 val' <- withBindingGroupVisible $ withTypeClassDictionaries dicts $ check val ty
565 return $ TypedValue True (foldr (Abs . Left) val' dictNames) t
566 return $ TypedValue True (foldr (Abs . Left) val' dictNames) t
@@ -681,10 +682,10 @@ check' val ty = do
681checkProperties ::
682checkProperties ::
682 (MonadSupply m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) =>
683 (MonadSupply m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) =>
683 Expr ->
684 Expr ->
684− [(String, Expr)] ->
685+ [(Text, Expr)] ->
685 Type ->
686 Type ->
686 Bool ->
687 Bool ->
687− m [(String, Expr)]
688+ m [(Text, Expr)]
688checkProperties expr ps row lax = let (ts, r') = rowToList row in go ps ts r' where
689checkProperties expr ps row lax = let (ts, r') = rowToList row in go ps ts r' where
689 go [] [] REmpty = return []
690 go [] [] REmpty = return []
690 go [] [] u@(TUnknown _)
691 go [] [] u@(TUnknown _)
@@ -771,7 +772,7 @@ checkFunctionApplication' fn u arg = do
771-- |
772-- |
772-- Ensure a set of property names and value does not contain duplicate labels
773-- Ensure a set of property names and value does not contain duplicate labels
773--
774--
774−ensureNoDuplicateProperties :: (MonadError MultipleErrors m) => [(String, Expr)] -> m ()
775+ensureNoDuplicateProperties :: (MonadError MultipleErrors m) => [(Text, Expr)] -> m ()
775ensureNoDuplicateProperties ps =
776ensureNoDuplicateProperties ps =
776 let ls = map fst ps in
777 let ls = map fst ps in
777 case ls \\ nub ls of
778 case ls \\ nub ls of
src/Language/PureScript/TypeChecker/Unify.hs+5−3
@@ -24,6 +24,8 @@ import Control.Monad.Writer.Class (MonadWriter(..))
24
24
25import Data.List (nub, sort)
25import Data.List (nub, sort)
26import qualified Data.Map as M
26import qualified Data.Map as M
27+import Data.Text (Text)
28+import qualified Data.Text as T
27
29
28import Language.PureScript.Crash
30import Language.PureScript.Crash
29import Language.PureScript.Errors
31import Language.PureScript.Errors
@@ -137,7 +139,7 @@ unifyRows r1 r2 =
137 forM_ int (uncurry unifyTypes)
139 forM_ int (uncurry unifyTypes)
138 unifyRows' sd1 r1' sd2 r2'
140 unifyRows' sd1 r1' sd2 r2'
139 where
141 where
140− unifyRows' :: [(String, Type)] -> Type -> [(String, Type)] -> Type -> m ()
142+ unifyRows' :: [(Text, Type)] -> Type -> [(Text, Type)] -> Type -> m ()
141 unifyRows' [] (TUnknown u) sd r = solveType u (rowFromList (sd, r))
143 unifyRows' [] (TUnknown u) sd r = solveType u (rowFromList (sd, r))
142 unifyRows' sd r [] (TUnknown u) = solveType u (rowFromList (sd, r))
144 unifyRows' sd r [] (TUnknown u) = solveType u (rowFromList (sd, r))
143 unifyRows' sd1 (TUnknown u1) sd2 (TUnknown u2) = do
145 unifyRows' sd1 (TUnknown u1) sd2 (TUnknown u2) = do
@@ -155,7 +157,7 @@ unifyRows r1 r2 =
155-- |
157-- |
156-- Replace a single type variable with a new unification variable
158-- Replace a single type variable with a new unification variable
157--
159--
158−replaceVarWithUnknown :: (MonadState CheckState m) => String -> Type -> m Type
160+replaceVarWithUnknown :: (MonadState CheckState m) => Text -> Type -> m Type
159replaceVarWithUnknown ident ty = do
161replaceVarWithUnknown ident ty = do
160 tu <- freshType
162 tu <- freshType
161 return $ replaceTypeVars ident tu ty
163 return $ replaceTypeVars ident tu ty
@@ -179,7 +181,7 @@ replaceTypeWildcards = everywhereOnTypesM replace
179varIfUnknown :: Type -> Type
181varIfUnknown :: Type -> Type
180varIfUnknown ty =
182varIfUnknown ty =
181 let unks = nub $ unknownsInType ty
183 let unks = nub $ unknownsInType ty
182− toName = (:) 't' . show
184+ toName = T.cons 't' . T.pack . show
183 ty' = everywhereOnTypes typeToVar ty
185 ty' = everywhereOnTypes typeToVar ty
184 typeToVar :: Type -> Type
186 typeToVar :: Type -> Type
185 typeToVar (TUnknown u) = TypeVar (toName u)
187 typeToVar (TUnknown u) = TypeVar (toName u)
src/Language/PureScript/Types.hs+43−41
@@ -9,11 +9,13 @@ module Language.PureScript.Types where
9import Prelude.Compat
9import Prelude.Compat
10
10
11import Control.Monad ((<=<))
11import Control.Monad ((<=<))
12−
13−import Data.List (nub)
14−import Data.Maybe (fromMaybe)
15import qualified Data.Aeson as A
12import qualified Data.Aeson as A
16import qualified Data.Aeson.TH as A
13import qualified Data.Aeson.TH as A
14+import Data.List (nub)
15+import Data.Maybe (fromMaybe)
16+import Data.Monoid ((<>))
17+import Data.Text (Text)
18+import qualified Data.Text as T
17
19
18import Language.PureScript.AST.SourcePos
20import Language.PureScript.AST.SourcePos
19import Language.PureScript.Kinds
21import Language.PureScript.Kinds
@@ -32,9 +34,9 @@ data Type
32 -- | A unification variable of type Type
34 -- | A unification variable of type Type
33 = TUnknown Int
35 = TUnknown Int
34 -- | A named type variable
36 -- | A named type variable
35− | TypeVar String
37+ | TypeVar Text
36 -- | A type-level string
38 -- | A type-level string
37− | TypeLevelString String
39+ | TypeLevelString Text
38 -- | A type wildcard, as would appear in a partial type synonym
40 -- | A type wildcard, as would appear in a partial type synonym
39 | TypeWildcard SourceSpan
41 | TypeWildcard SourceSpan
40 -- | A type constructor
42 -- | A type constructor
@@ -45,15 +47,15 @@ data Type
45 -- | A type application
47 -- | A type application
46 | TypeApp Type Type
48 | TypeApp Type Type
47 -- | Forall quantifier
49 -- | Forall quantifier
48− | ForAll String Type (Maybe SkolemScope)
50+ | ForAll Text Type (Maybe SkolemScope)
49 -- | A type with a set of type class constraints
51 -- | A type with a set of type class constraints
50 | ConstrainedType [Constraint] Type
52 | ConstrainedType [Constraint] Type
51 -- | A skolem constant
53 -- | A skolem constant
52− | Skolem String Int SkolemScope (Maybe SourceSpan)
54+ | Skolem Text Int SkolemScope (Maybe SourceSpan)
53 -- | An empty row
55 -- | An empty row
54 | REmpty
56 | REmpty
55 -- | A non-empty row
57 -- | A non-empty row
56− | RCons String Type Type
58+ | RCons Text Type Type
57 -- | A type with a kind annotation
59 -- | A type with a kind annotation
58 | KindedType Type Kind
60 | KindedType Type Kind
59 -- | A placeholder used in pretty printing
61 -- | A placeholder used in pretty printing
@@ -61,7 +63,7 @@ data Type
61 -- | A placeholder used in pretty printing
63 -- | A placeholder used in pretty printing
62 | PrettyPrintObject Type
64 | PrettyPrintObject Type
63 -- | A placeholder used in pretty printing
65 -- | A placeholder used in pretty printing
64− | PrettyPrintForAll [String] Type
66+ | PrettyPrintForAll [Text] Type
65 -- | Binary operator application. During the rebracketing phase of desugaring,
67 -- | Binary operator application. During the rebracketing phase of desugaring,
66 -- this data constructor will be removed.
68 -- this data constructor will be removed.
67 | BinaryNoParensType Type Type Type
69 | BinaryNoParensType Type Type Type
@@ -75,7 +77,7 @@ data Type
75
77
76-- | Additional data relevant to type class constraints
78-- | Additional data relevant to type class constraints
77data ConstraintData
79data ConstraintData
78− = PartialConstraintData [[String]] Bool
80+ = PartialConstraintData [[Text]] Bool
79 -- ^ Data to accompany a Partial constraint generated by the exhaustivity checker.
81 -- ^ Data to accompany a Partial constraint generated by the exhaustivity checker.
80 -- It contains (rendered) binder information for those binders which were
82 -- It contains (rendered) binder information for those binders which were
81 -- not matched, and a flag indicating whether the list was truncated or not.
83 -- not matched, and a flag indicating whether the list was truncated or not.
@@ -106,7 +108,7 @@ $(A.deriveJSON A.defaultOptions ''ConstraintData)
106-- |
108-- |
107-- Convert a row to a list of pairs of labels and types
109-- Convert a row to a list of pairs of labels and types
108--
110--
109−rowToList :: Type -> ([(String, Type)], Type)
111+rowToList :: Type -> ([(Text, Type)], Type)
110rowToList (RCons name ty row) = let (tys, rest) = rowToList row
112rowToList (RCons name ty row) = let (tys, rest) = rowToList row
111 in ((name, ty):tys, rest)
113 in ((name, ty):tys, rest)
112rowToList r = ([], r)
114rowToList r = ([], r)
@@ -114,7 +116,7 @@ rowToList r = ([], r)
114-- |
116-- |
115-- Convert a list of labels and types to a row
117-- Convert a list of labels and types to a row
116--
118--
117−rowFromList :: ([(String, Type)], Type) -> Type
119+rowFromList :: ([(Text, Type)], Type) -> Type
118rowFromList ([], r) = r
120rowFromList ([], r) = r
119rowFromList ((name, t):ts, r) = RCons name t (rowFromList (ts, r))
121rowFromList ((name, t):ts, r) = RCons name t (rowFromList (ts, r))
120
122
@@ -128,23 +130,23 @@ isMonoType _ = True
128-- |
130-- |
129-- Universally quantify a type
131-- Universally quantify a type
130--
132--
131−mkForAll :: [String] -> Type -> Type
133+mkForAll :: [Text] -> Type -> Type
132mkForAll args ty = foldl (\t arg -> ForAll arg t Nothing) ty args
134mkForAll args ty = foldl (\t arg -> ForAll arg t Nothing) ty args
133
135
134-- |
136-- |
135-- Replace a type variable, taking into account variable shadowing
137-- Replace a type variable, taking into account variable shadowing
136--
138--
137−replaceTypeVars :: String -> Type -> Type -> Type
139+replaceTypeVars :: Text -> Type -> Type -> Type
138replaceTypeVars v r = replaceAllTypeVars [(v, r)]
140replaceTypeVars v r = replaceAllTypeVars [(v, r)]
139
141
140-- |
142-- |
141-- Replace named type variables with types
143-- Replace named type variables with types
142--
144--
143−replaceAllTypeVars :: [(String, Type)] -> Type -> Type
145+replaceAllTypeVars :: [(Text, Type)] -> Type -> Type
144replaceAllTypeVars = go []
146replaceAllTypeVars = go []
145 where
147 where
146
148
147− go :: [String] -> [(String, Type)] -> Type -> Type
149+ go :: [Text] -> [(Text, Type)] -> Type -> Type
148 go _ m (TypeVar v) = fromMaybe (TypeVar v) (v `lookup` m)
150 go _ m (TypeVar v) = fromMaybe (TypeVar v) (v `lookup` m)
149 go bs m (TypeApp t1 t2) = TypeApp (go bs m t1) (go bs m t2)
151 go bs m (TypeApp t1 t2) = TypeApp (go bs m t1) (go bs m t2)
150 go bs m f@(ForAll v t sco) | v `elem` keys = go bs (filter ((/= v) . fst) m) f
152 go bs m f@(ForAll v t sco) | v `elem` keys = go bs (filter ((/= v) . fst) m) f
@@ -163,16 +165,16 @@ replaceAllTypeVars = go []
163 go bs m (ParensInType t) = ParensInType (go bs m t)
165 go bs m (ParensInType t) = ParensInType (go bs m t)
164 go _ _ ty = ty
166 go _ _ ty = ty
165
167
166− genName orig inUse = try 0
168+ genName orig inUse = try' 0
167 where
169 where
168− try :: Integer -> String
170+ try' :: Integer -> Text
169− try n | (orig ++ show n) `elem` inUse = try (n + 1)
171+ try' n | (orig <> T.pack (show n)) `elem` inUse = try' (n + 1)
170− | otherwise = orig ++ show n
172+ | otherwise = orig <> T.pack (show n)
171
173
172-- |
174-- |
173-- Collect all type variables appearing in a type
175-- Collect all type variables appearing in a type
174--
176--
175−usedTypeVariables :: Type -> [String]
177+usedTypeVariables :: Type -> [Text]
176usedTypeVariables = nub . everythingOnTypes (++) go
178usedTypeVariables = nub . everythingOnTypes (++) go
177 where
179 where
178 go (TypeVar v) = [v]
180 go (TypeVar v) = [v]
@@ -181,10 +183,10 @@ usedTypeVariables = nub . everythingOnTypes (++) go
181-- |
183-- |
182-- Collect all free type variables appearing in a type
184-- Collect all free type variables appearing in a type
183--
185--
184−freeTypeVariables :: Type -> [String]
186+freeTypeVariables :: Type -> [Text]
185freeTypeVariables = nub . go []
187freeTypeVariables = nub . go []
186 where
188 where
187− go :: [String] -> Type -> [String]
189+ go :: [Text] -> Type -> [Text]
188 go bound (TypeVar v) | v `notElem` bound = [v]
190 go bound (TypeVar v) | v `notElem` bound = [v]
189 go bound (TypeApp t1 t2) = go bound t1 ++ go bound t2
191 go bound (TypeApp t1 t2) = go bound t1 ++ go bound t2
190 go bound (ForAll v t _) = go (v : bound) t
192 go bound (ForAll v t _) = go (v : bound) t
@@ -292,32 +294,32 @@ everywhereOnTypesTopDownM f = go <=< f
292 go other = f other
294 go other = f other
293
295
294everythingOnTypes :: (r -> r -> r) -> (Type -> r) -> Type -> r
296everythingOnTypes :: (r -> r -> r) -> (Type -> r) -> Type -> r
295−everythingOnTypes (<>) f = go
297+everythingOnTypes (<+>) f = go
296 where
298 where
297− go t@(TypeApp t1 t2) = f t <> go t1 <> go t2
299+ go t@(TypeApp t1 t2) = f t <+> go t1 <+> go t2
298− go t@(ForAll _ ty _) = f t <> go ty
300+ go t@(ForAll _ ty _) = f t <+> go ty
299− go t@(ConstrainedType cs ty) = foldl (<>) (f t) (map go $ concatMap constraintArgs cs) <> go ty
301+ go t@(ConstrainedType cs ty) = foldl (<+>) (f t) (map go $ concatMap constraintArgs cs) <+> go ty
300− go t@(RCons _ ty rest) = f t <> go ty <> go rest
302+ go t@(RCons _ ty rest) = f t <+> go ty <+> go rest
301− go t@(KindedType ty _) = f t <> go ty
303+ go t@(KindedType ty _) = f t <+> go ty
302− go t@(PrettyPrintFunction t1 t2) = f t <> go t1 <> go t2
304+ go t@(PrettyPrintFunction t1 t2) = f t <+> go t1 <+> go t2
303− go t@(PrettyPrintObject t1) = f t <> go t1
305+ go t@(PrettyPrintObject t1) = f t <+> go t1
304− go t@(PrettyPrintForAll _ t1) = f t <> go t1
306+ go t@(PrettyPrintForAll _ t1) = f t <+> go t1
305− go t@(BinaryNoParensType t1 t2 t3) = f t <> go t1 <> go t2 <> go t3
307+ go t@(BinaryNoParensType t1 t2 t3) = f t <+> go t1 <+> go t2 <+> go t3
306− go t@(ParensInType t1) = f t <> go t1
308+ go t@(ParensInType t1) = f t <+> go t1
307 go other = f other
309 go other = f other
308
310
309everythingWithContextOnTypes :: s -> r -> (r -> r -> r) -> (s -> Type -> (s, r)) -> Type -> r
311everythingWithContextOnTypes :: s -> r -> (r -> r -> r) -> (s -> Type -> (s, r)) -> Type -> r
310−everythingWithContextOnTypes s0 r0 (<>) f = go' s0
312+everythingWithContextOnTypes s0 r0 (<+>) f = go' s0
311 where
313 where
312− go' s t = let (s', r) = f s t in r <> go s' t
314+ go' s t = let (s', r) = f s t in r <+> go s' t
313− go s (TypeApp t1 t2) = go' s t1 <> go' s t2
315+ go s (TypeApp t1 t2) = go' s t1 <+> go' s t2
314 go s (ForAll _ ty _) = go' s ty
316 go s (ForAll _ ty _) = go' s ty
315− go s (ConstrainedType cs ty) = foldl (<>) r0 (map (go' s) $ concatMap constraintArgs cs) <> go' s ty
317+ go s (ConstrainedType cs ty) = foldl (<+>) r0 (map (go' s) $ concatMap constraintArgs cs) <+> go' s ty
316− go s (RCons _ ty rest) = go' s ty <> go' s rest
318+ go s (RCons _ ty rest) = go' s ty <+> go' s rest
317 go s (KindedType ty _) = go' s ty
319 go s (KindedType ty _) = go' s ty
318− go s (PrettyPrintFunction t1 t2) = go' s t1 <> go' s t2
320+ go s (PrettyPrintFunction t1 t2) = go' s t1 <+> go' s t2
319 go s (PrettyPrintObject t1) = go' s t1
321 go s (PrettyPrintObject t1) = go' s t1
320 go s (PrettyPrintForAll _ t1) = go' s t1
322 go s (PrettyPrintForAll _ t1) = go' s t1
321− go s (BinaryNoParensType t1 t2 t3) = go' s t1 <> go' s t2 <> go' s t3
323+ go s (BinaryNoParensType t1 t2 t3) = go' s t1 <+> go' s t2 <+> go' s t3
322 go s (ParensInType t1) = go' s t1
324 go s (ParensInType t1) = go' s t1
323 go _ _ = r0
325 go _ _ = r0
tests/Language/PureScript/Ide/ReexportsSpec.hs+1−2
@@ -2,7 +2,6 @@
2{-# LANGUAGE NoImplicitPrelude #-}
2{-# LANGUAGE NoImplicitPrelude #-}
3module Language.PureScript.Ide.ReexportsSpec where
3module Language.PureScript.Ide.ReexportsSpec where
4
4
5−import qualified Prelude
6import Protolude
5import Protolude
7
6
8import qualified Data.Map as Map
7import qualified Data.Map as Map
@@ -11,7 +10,7 @@ import Language.PureScript.Ide.Types
11import qualified Language.PureScript as P
10import qualified Language.PureScript as P
12import Test.Hspec
11import Test.Hspec
13
12
14−m :: Prelude.String -> P.ModuleName
13+m :: Text -> P.ModuleName
15m = P.moduleNameFromString
14m = P.moduleNameFromString
16
15
17d :: IdeDeclaration -> IdeDeclarationAnn
16d :: IdeDeclaration -> IdeDeclarationAnn
tests/TestCompiler.hs+9−8
@@ -2,6 +2,7 @@
2{-# LANGUAGE DoAndIfThenElse #-}
2{-# LANGUAGE DoAndIfThenElse #-}
3{-# LANGUAGE TupleSections #-}
3{-# LANGUAGE TupleSections #-}
4{-# LANGUAGE FlexibleInstances #-}
4{-# LANGUAGE FlexibleInstances #-}
5+{-# LANGUAGE OverloadedStrings #-}
5
6
6module TestCompiler where
7module TestCompiler where
7
8
@@ -30,8 +31,8 @@ import Data.Function (on)
30import Data.List (sort, stripPrefix, intercalate, groupBy, sortBy, minimumBy)
31import Data.List (sort, stripPrefix, intercalate, groupBy, sortBy, minimumBy)
31import Data.Maybe (mapMaybe)
32import Data.Maybe (mapMaybe)
32import Data.Time.Clock (UTCTime())
33import Data.Time.Clock (UTCTime())
33−import Data.Tuple (swap)
34import qualified Data.Text as T
34import qualified Data.Text as T
35+import Data.Tuple (swap)
35
36
36import qualified Data.Map as M
37import qualified Data.Map as M
37
38
@@ -72,7 +73,7 @@ spec = do
72 supportPurs <- supportFiles "purs"
73 supportPurs <- supportFiles "purs"
73 supportPursFiles <- readInput supportPurs
74 supportPursFiles <- readInput supportPurs
74 supportExterns <- runExceptT $ do
75 supportExterns <- runExceptT $ do
75− modules <- ExceptT . return $ P.parseModulesFromFiles id (map (fmap T.pack) supportPursFiles)
76+ modules <- ExceptT . return $ P.parseModulesFromFiles id supportPursFiles
76 foreigns <- inferForeignModules modules
77 foreigns <- inferForeignModules modules
77 externs <- ExceptT . fmap fst . runTest $ P.make (makeActions foreigns) (map snd modules)
78 externs <- ExceptT . fmap fst . runTest $ P.make (makeActions foreigns) (map snd modules)
78 return (zip (map snd modules) externs)
79 return (zip (map snd modules) externs)
@@ -169,20 +170,20 @@ makeActions foreigns = (P.buildMakeActions modulesDir (P.internalError "makeActi
169 where
170 where
170 getInputTimestamp :: P.ModuleName -> P.Make (Either P.RebuildPolicy (Maybe UTCTime))
171 getInputTimestamp :: P.ModuleName -> P.Make (Either P.RebuildPolicy (Maybe UTCTime))
171 getInputTimestamp mn
172 getInputTimestamp mn
172− | isSupportModule (P.runModuleName mn) = return (Left P.RebuildNever)
173+ | isSupportModule (T.unpack (P.runModuleName mn)) = return (Left P.RebuildNever)
173 | otherwise = return (Left P.RebuildAlways)
174 | otherwise = return (Left P.RebuildAlways)
174 where
175 where
175 isSupportModule = flip elem supportModules
176 isSupportModule = flip elem supportModules
176
177
177 getOutputTimestamp :: P.ModuleName -> P.Make (Maybe UTCTime)
178 getOutputTimestamp :: P.ModuleName -> P.Make (Maybe UTCTime)
178 getOutputTimestamp mn = do
179 getOutputTimestamp mn = do
179− let filePath = modulesDir </> P.runModuleName mn
180+ let filePath = modulesDir </> T.unpack (P.runModuleName mn)
180 exists <- liftIO $ doesDirectoryExist filePath
181 exists <- liftIO $ doesDirectoryExist filePath
181 return (if exists then Just (P.internalError "getOutputTimestamp: read timestamp") else Nothing)
182 return (if exists then Just (P.internalError "getOutputTimestamp: read timestamp") else Nothing)
182
183
183−readInput :: [FilePath] -> IO [(FilePath, String)]
184+readInput :: [FilePath] -> IO [(FilePath, T.Text)]
184readInput inputFiles = forM inputFiles $ \inputFile -> do
185readInput inputFiles = forM inputFiles $ \inputFile -> do
185− text <- readUTF8File inputFile
186+ text <- readUTF8FileT inputFile
186 return (inputFile, text)
187 return (inputFile, text)
187
188
188runTest :: P.Make a -> IO (Either P.MultipleErrors a, P.MultipleErrors)
189runTest :: P.Make a -> IO (Either P.MultipleErrors a, P.MultipleErrors)
@@ -195,7 +196,7 @@ compile
195 -> IO (Either P.MultipleErrors [P.ExternsFile], P.MultipleErrors)
196 -> IO (Either P.MultipleErrors [P.ExternsFile], P.MultipleErrors)
196compile supportExterns inputFiles check = silence $ runTest $ do
197compile supportExterns inputFiles check = silence $ runTest $ do
197 fs <- liftIO $ readInput inputFiles
198 fs <- liftIO $ readInput inputFiles
198− ms <- P.parseModulesFromFiles id (map (fmap T.pack) fs)
199+ ms <- P.parseModulesFromFiles id fs
199 foreigns <- inferForeignModules ms
200 foreigns <- inferForeignModules ms
200 liftIO (check (map snd ms))
201 liftIO (check (map snd ms))
201 let actions = makeActions foreigns
202 let actions = makeActions foreigns
@@ -222,7 +223,7 @@ checkMain ms =
222checkShouldFailWith :: [String] -> P.MultipleErrors -> Maybe String
223checkShouldFailWith :: [String] -> P.MultipleErrors -> Maybe String
223checkShouldFailWith expected errs =
224checkShouldFailWith expected errs =
224 let actual = map P.errorCode $ P.runMultipleErrors errs
225 let actual = map P.errorCode $ P.runMultipleErrors errs
225− in if sort expected == sort actual
226+ in if sort expected == sort (map T.unpack actual)
226 then Nothing
227 then Nothing
227 else Just $ "Expected these errors: " ++ show expected ++ ", but got these: " ++ show actual
228 else Just $ "Expected these errors: " ++ show expected ++ ", but got these: " ++ show actual
228
229
tests/TestDocs.hs+7−6
@@ -13,6 +13,7 @@ import Data.Monoid
13import Data.Maybe (fromMaybe)
13import Data.Maybe (fromMaybe)
14import Data.List ((\\))
14import Data.List ((\\))
15import Data.Foldable
15import Data.Foldable
16+import qualified Data.Text as T
16import System.Exit
17import System.Exit
17
18
18import qualified Language.PureScript as P
19import qualified Language.PureScript as P
@@ -36,8 +37,8 @@ main = pushd "examples/docs" $ do
36 case res of
37 case res of
37 Left e -> Publish.printErrorToStdout e >> exitFailure
38 Left e -> Publish.printErrorToStdout e >> exitFailure
38 Right Docs.Package{..} ->
39 Right Docs.Package{..} ->
39− forM_ testCases $ \(P.moduleNameFromString -> mn, pragmas) ->
40+ forM_ testCases $ \(P.moduleNameFromString . T.pack -> mn, pragmas) ->
40− let mdl = takeJust ("module not found in docs: " ++ P.runModuleName mn)
41+ let mdl = takeJust ("module not found in docs: " ++ T.unpack (P.runModuleName mn))
41 (find ((==) mn . Docs.modName) pkgModules)
42 (find ((==) mn . Docs.modName) pkgModules)
42 in forM_ pragmas (`runAssertionIO` mdl)
43 in forM_ pragmas (`runAssertionIO` mdl)
43
44
@@ -197,11 +198,11 @@ checkConstrained ty tyClass =
197 False
198 False
198 where
199 where
199 matches className =
200 matches className =
200− (==) className . P.runProperName . P.disqualify . P.constraintClass
201+ (==) className . T.unpack . P.runProperName . P.disqualify . P.constraintClass
201
202
202runAssertionIO :: Assertion -> Docs.Module -> IO ()
203runAssertionIO :: Assertion -> Docs.Module -> IO ()
203runAssertionIO assertion mdl = do
204runAssertionIO assertion mdl = do
204− putStrLn ("In " ++ P.runModuleName (Docs.modName mdl) ++ ": " ++ show assertion)
205+ putStrLn ("In " ++ T.unpack (P.runModuleName (Docs.modName mdl)) ++ ": " ++ show assertion)
205 case runAssertion assertion mdl of
206 case runAssertion assertion mdl of
206 Pass -> pure ()
207 Pass -> pure ()
207 Fail reason -> do
208 Fail reason -> do
@@ -298,12 +299,12 @@ testCases =
298 ]
299 ]
299
300
300 where
301 where
301− n = P.moduleNameFromString
302+ n = P.moduleNameFromString . T.pack
302
303
303 hasTypeVar varName =
304 hasTypeVar varName =
304 getAny . P.everythingOnTypes (<>) (Any . isVar varName)
305 getAny . P.everythingOnTypes (<>) (Any . isVar varName)
305
306
306− isVar varName (P.TypeVar name) | varName == name = True
307+ isVar varName (P.TypeVar name) | varName == T.unpack name = True
307 isVar _ _ = False
308 isVar _ _ = False
308
309
309 renderedType expected =
310 renderedType expected =
tests/TestPsci.hs+3−2
@@ -10,6 +10,7 @@ import Control.Monad.Trans.State.Strict (evalStateT)
10import Control.Monad (when)
10import Control.Monad (when)
11
11
12import Data.List (sort)
12import Data.List (sort)
13+import qualified Data.Text as T
13
14
14import System.Exit (exitFailure)
15import System.Exit (exitFailure)
15import System.Console.Haskeline
16import System.Console.Haskeline
@@ -127,11 +128,11 @@ getPSCiState = do
127 Left err ->
128 Left err ->
128 print err >> exitFailure
129 print err >> exitFailure
129 Right modules ->
130 Right modules ->
130− let imports = [controlMonadSTasST, (P.ModuleName [P.ProperName "Prelude"], P.Implicit, Nothing)]
131+ let imports = [controlMonadSTasST, (P.ModuleName [P.ProperName (T.pack "Prelude")], P.Implicit, Nothing)]
131 dummyExterns = P.internalError "TestPsci: dummyExterns should not be used"
132 dummyExterns = P.internalError "TestPsci: dummyExterns should not be used"
132 in return (PSCiState imports [] (zip (map snd modules) (repeat dummyExterns)))
133 in return (PSCiState imports [] (zip (map snd modules) (repeat dummyExterns)))
133
134
134controlMonadSTasST :: ImportedModule
135controlMonadSTasST :: ImportedModule
135controlMonadSTasST = (s "Control.Monad.ST", P.Implicit, Just (s "ST"))
136controlMonadSTasST = (s "Control.Monad.ST", P.Implicit, Just (s "ST"))
136 where
137 where
137− s = P.moduleNameFromString
138+ s = P.moduleNameFromString . T.pack