on master help sign in
Switch terminal/ over to Data.Name
commit541409c5c539b538fca44ffc5be479303a6ea2c8 authorEvan Czaplicki <evancz@users.noreply.github.com> dateMon 19 Nov 2018, 14:08 (8 years ago) parent843893a
3 files changed+22−16
compiler/src/Data/Name.hs+6 terminal/src/Develop/Generate/Help.hs+3−3 terminal/src/Repl.hs+13−13
compiler/src/Data/Name.hs+6
@@ -19,6 +19,7 @@ module Data.Name
1919 , isAppendableType
2020 , isCompappendType
2121 , fromVarIndex
22+ , fromReplCount
2223 , fromWords
2324 , fromManyNames
2425 , fromTypeVariable
@@ -477,6 +478,11 @@ fromTypeVariableScheme scheme =
477478 )
478479
479480
481+fromReplCount :: Int -> Name
482+fromReplCount n =
483+ fromString ("repl_value_" ++ show n)
484+
485+
480486
481487-- FROM MANY NAMES
482488
terminal/src/Develop/Generate/Help.hs+3−3
@@ -10,9 +10,9 @@ module Develop.Generate.Help
1010
1111import qualified Data.ByteString.Builder as B
1212import Data.Monoid ((<>))
13+import qualified Data.Name as Name
1314import Text.RawString.QQ (r)
1415
15−import qualified Elm.Name as N
1616import qualified Json.Encode as Encode
1717
1818
@@ -20,7 +20,7 @@ import qualified Json.Encode as Encode
2020-- PAGES
2121
2222
23−makePageHtml :: N.Name -> Maybe Encode.Value -> B.Builder
23+makePageHtml :: Name.Name -> Maybe Encode.Value -> B.Builder
2424makePageHtml moduleName maybeFlags =
2525 [r|<!DOCTYPE HTML>
2626<html>
@@ -31,7 +31,7 @@ makePageHtml moduleName maybeFlags =
3131</head>
3232<body>
3333<script>
34−Elm.|] <> N.toBuilder moduleName <> [r|.init({ flags: |] <> maybe "undefined" Encode.encode maybeFlags <> [r| });
34+Elm.|] <> Name.toBuilder moduleName <> [r|.init({ flags: |] <> maybe "undefined" Encode.encode maybeFlags <> [r| });
3535</script>
3636</body>
3737</html>
terminal/src/Repl.hs+13−13
@@ -15,6 +15,7 @@ import qualified Data.ByteString.Lazy as LBS
1515import qualified Data.List as List
1616import qualified Data.Map as Map
1717import Data.Monoid ((<>))
18+import qualified Data.Name as Name
1819import qualified Data.Text as Text
1920import qualified Data.Text.Encoding as Text
2021import qualified System.Console.Haskeline as Repl
@@ -25,7 +26,6 @@ import qualified System.IO as IO
2526import qualified System.Process as Proc
2627
2728import qualified Elm.Compiler as Elm (version)
28−import qualified Elm.Name as N
2929import qualified Elm.Project as Project
3030import qualified Elm.Package as Pkg
3131import qualified Elm.PerUserCache as PerUserCache
@@ -151,7 +151,7 @@ report msg =
151151 return Nothing
152152
153153
154−data Output = None | Def N.Name | Expr Text.Text
154+data Output = None | Def Name.Name | Expr Text.Text
155155
156156
157157interpret :: Output -> State -> Runner (Maybe a)
@@ -220,9 +220,9 @@ toInput string =
220220data State =
221221 State
222222 { _count :: !Int
223− , _imports :: Map.Map N.Name Text.Text
224− , _types :: Map.Map N.Name Text.Text
225− , _defs :: Map.Map N.Name Text.Text
223+ , _imports :: Map.Map Name.Name Text.Text
224+ , _types :: Map.Map Name.Name Text.Text
225+ , _defs :: Map.Map Name.Name Text.Text
226226 , _tricks :: [Text.Text]
227227 , _localizer :: L.Localizer
228228 }
@@ -237,7 +237,7 @@ compile :: Bool -> Output -> State -> Task.Task (Maybe FilePath)
237237compile noColors output (State count imports types defs tricks localizer) =
238238 let
239239 header =
240− "module " <> N.toBuilder N.replModule <> " exposing (..)\n\n"
240+ "module " <> Name.toBuilder Name.replModule <> " exposing (..)\n\n"
241241
242242 elmSourceCode =
243243 (<>) header $
@@ -259,14 +259,14 @@ compile noColors output (State count imports types defs tricks localizer) =
259259
260260 Expr expr ->
261261 let
262− name = N.addIndex "repl_value_" count
262+ name = Name.fromReplCount count
263263 text = Text.replace "\n" "\n " expr
264− def = N.toBuilder name <> " =\n " <> Text.encodeUtf8Builder text <> "\n"
264+ def = Name.toBuilder name <> " =\n " <> Text.encodeUtf8Builder text <> "\n"
265265 in
266266 compileForRepl (elmSourceCode <> def) (Just name)
267267
268268
269−addLines :: Map.Map N.Name Text.Text -> B.Builder -> B.Builder
269+addLines :: Map.Map Name.Name Text.Text -> B.Builder -> B.Builder
270270addLines dict builder =
271271 Map.foldr (\text b -> Text.encodeUtf8Builder text <> "\n" <> b) builder dict
272272
@@ -296,19 +296,19 @@ lookupCompletions string =
296296 addMatches string False commands []
297297
298298
299−commands :: Map.Map N.Name ()
299+commands :: Map.Map Name.Name ()
300300commands =
301301 Map.fromList [ (":exit", ()), (":quit", ()), (":reset", ()), (":help", ()) ]
302302
303303
304−addMatches :: String -> Bool -> Map.Map N.Name v -> [Repl.Completion] -> [Repl.Completion]
304+addMatches :: String -> Bool -> Map.Map Name.Name v -> [Repl.Completion] -> [Repl.Completion]
305305addMatches string isFinished dict completions =
306306 Map.foldrWithKey (addMatch string isFinished) completions dict
307307
308308
309−addMatch :: String -> Bool -> N.Name -> v -> [Repl.Completion] -> [Repl.Completion]
309+addMatch :: String -> Bool -> Name.Name -> v -> [Repl.Completion] -> [Repl.Completion]
310310addMatch string isFinished name _ completions =
311− let suggestion = N.toString name in
311+ let suggestion = Name.toString name in
312312 if List.isPrefixOf string suggestion then
313313 Repl.Completion suggestion suggestion isFinished : completions
314314 else