on master help sign in
Combine AST.Module.Name and Elm.Compiler.Module into Elm.ModuleName
0fb8be0Evan Czaplicki
compiler/src/Elm/Compiler/Module.hsdeleted−116
@@ -1,116 +0,0 @@
1−{-# OPTIONS_GHC -Wall #-}
2−{-# LANGUAGE OverloadedStrings #-}
3−module Elm.Compiler.Module
4− -- interfaces
5− ( I.Interface
6− , I.Interfaces
7−
8− -- module names
9− , Raw
10− , nameToString
11− , nameToSlashPath
12− , nameToHyphenPath
13− , fromHyphenPath
14− , encode
15− , decoder
16−
17− -- canonical names
18− , ModuleName.Canonical(..)
19− )
20− where
21−
22−
23−import qualified Data.Char as Char
24−import qualified Data.Name as Name
25−import qualified Data.Text as Text
26−import qualified System.FilePath as FP
27−
28−import qualified AST.Module.Name as ModuleName
29−import qualified Elm.Interface as I
30−import qualified Json.Decode as Decode
31−import qualified Json.Encode as Encode
32−
33−
34−
35−-- NAMES
36−
37−
38−type Raw = Name.Name
39−
40−
41−nameToString :: Raw -> String
42−nameToString =
43− Name.toString
44−
45−
46−nameToSlashPath :: Raw -> FilePath
47−nameToSlashPath name =
48− map (\c -> if c == '.' then FP.pathSeparator else c) (Name.toString name)
49−
50−
51−nameToHyphenPath :: Raw -> FilePath
52−nameToHyphenPath name =
53− map (\c -> if c == '.' then '-' else c) (Name.toString name)
54−
55−
56−fromHyphenPath :: Text.Text -> Maybe Raw
57−fromHyphenPath txt =
58− let str = Text.unpack txt in
59− if all isGoodChunk (splitOn '-' str)
60− then Just (Name.fromString (map (\c -> if c == '-' then '.' else c) str))
61− else Nothing
62−
63−
64−
65−-- JSON
66−
67−
68−encode :: Raw -> Encode.Value
69−encode =
70− Encode.name
71−
72−
73−decoder :: Decode.Decoder Text.Text Raw
74−decoder =
75− do txt <- Decode.text
76− let str = Text.unpack txt
77− if all isGoodChunk (splitOn '.' str)
78− then Decode.succeed (Name.fromString str)
79− else Decode.fail txt
80−
81−
82−isGoodChunk :: String -> Bool
83−isGoodChunk chunk =
84− case chunk of
85− [] ->
86− False
87−
88− first : rest ->
89− Char.isUpper first && all isGoodChar rest
90−
91−
92−isGoodChar :: Char -> Bool
93−isGoodChar char =
94− Char.isAlphaNum char || char == '_'
95−
96−
97−splitOn :: Char -> String -> [String]
98−splitOn sep string =
99− uncurry (:) (splitOnHelp sep string)
100−
101−
102−splitOnHelp :: Char -> String -> (String, [String])
103−splitOnHelp sep string =
104− case string of
105− [] ->
106− ("",[])
107−
108− char : rest ->
109− let
110− (chunk,chunks) = splitOnHelp sep rest
111− in
112− if char == sep then
113− ("", chunk:chunks)
114− else
115− (char:chunk, chunks)
116−
compiler/src/AST/Module/Name.hs → compiler/src/Elm/ModuleName.hsrenamed+131−50
@@ -1,28 +1,124 @@
1−{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
1{-# LANGUAGE OverloadedStrings #-}
3−module AST.Module.Name
2+module Elm.ModuleName
3+ ( Raw
4+ , nameToString
5+ , nameToSlashPath
6+ , nameToHyphenPath
7+ , fromHyphenPath
8+ , encode
9+ , decoder
4− ( Canonical(..)
10+ , Canonical(..)
11+ , canonicalIsKernel
5 , basics, char, string
12 , basics, char, string
6 , maybe, result, list, array, dict, tuple
13 , maybe, result, list, array, dict, tuple
7 , platform, cmd, sub
14 , platform, cmd, sub
8− , virtualDom, debug, bitwise
15+ , debug, bitwise
16+ , virtualDom
9 , jsonDecode, jsonEncode
17 , jsonDecode, jsonEncode
10 , webgl, texture, vector2, vector3, vector4, matrix4
18 , webgl, texture, vector2, vector3, vector4, matrix4
11− , canonicalIsKernel
12 )
19 )
13 where
20 where
14
21
15
22
16−import Prelude hiding (maybe)
17import Control.Monad (liftM2)
23import Control.Monad (liftM2)
18−import Data.Binary
24+import Data.Binary (Binary(..))
25+import qualified Data.Char as Char
19import qualified Data.Name as Name
26import qualified Data.Name as Name
27+import qualified Data.Text as Text
28+import Prelude hiding (maybe)
29+import qualified System.FilePath as FP
20
30
21import qualified Elm.Package as Pkg
31import qualified Elm.Package as Pkg
32+import qualified Json.Decode as Decode
33+import qualified Json.Encode as Encode
34+
35+
36+
37+-- RAW
38+
39+
40+type Raw = Name.Name
41+
42+
43+nameToString :: Raw -> String
44+nameToString =
45+ Name.toString
46+
47+
48+nameToSlashPath :: Raw -> FilePath
49+nameToSlashPath name =
50+ map (\c -> if c == '.' then FP.pathSeparator else c) (Name.toString name)
51+
52+
53+nameToHyphenPath :: Raw -> FilePath
54+nameToHyphenPath name =
55+ map (\c -> if c == '.' then '-' else c) (Name.toString name)
56+
57+
58+fromHyphenPath :: Text.Text -> Maybe Raw
59+fromHyphenPath txt =
60+ let str = Text.unpack txt in
61+ if all isGoodChunk (splitOn '-' str)
62+ then Just (Name.fromString (map (\c -> if c == '-' then '.' else c) str))
63+ else Nothing
64+
65+
66+
67+-- JSON
22
68
23
69
70+encode :: Raw -> Encode.Value
71+encode =
72+ Encode.name
24
73
25−-- NAMES
74+
75+decoder :: Decode.Decoder Text.Text Raw
76+decoder =
77+ do txt <- Decode.text
78+ let str = Text.unpack txt
79+ if all isGoodChunk (splitOn '.' str)
80+ then Decode.succeed (Name.fromString str)
81+ else Decode.fail txt
82+
83+
84+isGoodChunk :: String -> Bool
85+isGoodChunk chunk =
86+ case chunk of
87+ [] ->
88+ False
89+
90+ first : rest ->
91+ Char.isUpper first && all isGoodChar rest
92+
93+
94+isGoodChar :: Char -> Bool
95+isGoodChar c =
96+ Char.isAlphaNum c || c == '_'
97+
98+
99+splitOn :: Char -> String -> [String]
100+splitOn sep str =
101+ uncurry (:) (splitOnHelp sep str)
102+
103+
104+splitOnHelp :: Char -> String -> (String, [String])
105+splitOnHelp sep str =
106+ case str of
107+ [] ->
108+ ("",[])
109+
110+ c : rest ->
111+ let
112+ (chunk,chunks) = splitOnHelp sep rest
113+ in
114+ if c == sep then
115+ ("", chunk:chunks)
116+ else
117+ (c:chunk, chunks)
118+
119+
120+
121+-- CANONICAL
26
122
27
123
28data Canonical =
124data Canonical =
@@ -33,18 +129,32 @@ data Canonical =
33 deriving (Ord)
129 deriving (Ord)
34
130
35
131
132+canonicalIsKernel :: Canonical -> Bool
133+canonicalIsKernel (Canonical _ name) =
134+ Name.isKernel name
135+
136+
137+
138+-- INSTANCES
139+
140+
36instance Eq Canonical where
141instance Eq Canonical where
37− (==) (Canonical pkg home) (Canonical pkg' home') =
142+ (==) (Canonical pkg1 name1) (Canonical pkg2 name2) =
38− home == home' && pkg == pkg'
143+ name1 == name2 && pkg1 == pkg2
144+
145+
146+instance Binary Canonical where
147+ put (Canonical a b) = put a >> put b
148+ get = liftM2 Canonical get get
39
149
40
150
41
151
42−-- PRIMITIVES
152+-- CORE
43
153
44
154
45{-# NOINLINE basics #-}
155{-# NOINLINE basics #-}
46basics :: Canonical
156basics :: Canonical
47−basics = Canonical Pkg.core "Basics"
157+basics = Canonical Pkg.core Name.basics
48
158
49
159
50{-# NOINLINE char #-}
160{-# NOINLINE char #-}
@@ -57,10 +167,6 @@ string :: Canonical
57string = Canonical Pkg.core Name.string
167string = Canonical Pkg.core Name.string
58
168
59
169
60−
61−-- CONTAINERS
62−
63−
64{-# NOINLINE maybe #-}
170{-# NOINLINE maybe #-}
65maybe :: Canonical
171maybe :: Canonical
66maybe = Canonical Pkg.core Name.maybe
172maybe = Canonical Pkg.core Name.maybe
@@ -91,10 +197,6 @@ tuple :: Canonical
91tuple = Canonical Pkg.core Name.tuple
197tuple = Canonical Pkg.core Name.tuple
92
198
93
199
94−
95−-- EFFECTS
96−
97−
98{-# NOINLINE platform #-}
200{-# NOINLINE platform #-}
99platform :: Canonical
201platform :: Canonical
100platform = Canonical Pkg.core Name.platform
202platform = Canonical Pkg.core Name.platform
@@ -110,15 +212,6 @@ sub :: Canonical
110sub = Canonical Pkg.core "Platform.Sub"
212sub = Canonical Pkg.core "Platform.Sub"
111
213
112
214
113−
114−-- MISC
115−
116−
117−{-# NOINLINE virtualDom #-}
118−virtualDom :: Canonical
119−virtualDom = Canonical Pkg.virtualDom Name.virtualDom
120−
121−
122{-# NOINLINE debug #-}
215{-# NOINLINE debug #-}
123debug :: Canonical
216debug :: Canonical
124debug = Canonical Pkg.core Name.debug
217debug = Canonical Pkg.core Name.debug
@@ -130,6 +223,15 @@ bitwise = Canonical Pkg.core Name.bitwise
130
223
131
224
132
225
226+-- HTML
227+
228+
229+{-# NOINLINE virtualDom #-}
230+virtualDom :: Canonical
231+virtualDom = Canonical Pkg.virtualDom Name.virtualDom
232+
233+
234+
133-- JSON
235-- JSON
134
236
135
237
@@ -175,24 +277,3 @@ vector4 = Canonical Pkg.linearAlgebra "Math.Vector4"
175{-# NOINLINE matrix4 #-}
277{-# NOINLINE matrix4 #-}
176matrix4 :: Canonical
278matrix4 :: Canonical
177matrix4 = Canonical Pkg.linearAlgebra "Math.Matrix4"
279matrix4 = Canonical Pkg.linearAlgebra "Math.Matrix4"
178−
179−
180−
181−-- IS KERNEL
182−
183−
184−canonicalIsKernel :: Canonical -> Bool
185−canonicalIsKernel (Canonical _ name) =
186− Name.isKernel name
187−
188−
189−
190−-- BINARY
191−
192−
193−instance Binary Canonical where
194− put (Canonical a b) =
195− put a >> put b
196−
197− get =
198− liftM2 Canonical get get
elm.cabal+3−3
@@ -130,12 +130,12 @@ Executable elm
130
130
131 -- shared from compiler/
131 -- shared from compiler/
132 Elm.Compiler
132 Elm.Compiler
133− Elm.Compiler.Module
134 Elm.Compiler.Objects
133 Elm.Compiler.Objects
135 Elm.Compiler.Type
134 Elm.Compiler.Type
136 Elm.Docs
135 Elm.Docs
137− Elm.Kernel
138 Elm.Header
136 Elm.Header
137+ Elm.Kernel
138+ Elm.ModuleName
139 Elm.Package
139 Elm.Package
140 Json.Decode
140 Json.Decode
141 Json.Encode
141 Json.Encode
@@ -144,7 +144,6 @@ Executable elm
144 AST.Canonical
144 AST.Canonical
145 AST.Optimized
145 AST.Optimized
146 AST.Source
146 AST.Source
147− AST.Module.Name
148 AST.Utils.Binop
147 AST.Utils.Binop
149 AST.Utils.Shader
148 AST.Utils.Shader
150 AST.Utils.Type
149 AST.Utils.Type
@@ -240,6 +239,7 @@ Executable elm
240 directory >= 1.2.3.0 && < 2.0,
239 directory >= 1.2.3.0 && < 2.0,
241 edit-distance >= 0.2 && < 0.3,
240 edit-distance >= 0.2 && < 0.3,
242 file-embed,
241 file-embed,
242+ filelock,
243 filepath >= 1 && < 2.0,
243 filepath >= 1 && < 2.0,
244 ghc-prim >= 0.5.2,
244 ghc-prim >= 0.5.2,
245 haskeline,
245 haskeline,