@@ -1,28 +1,124 @@
1−{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
1{-# LANGUAGE OverloadedStrings #-}
3−module AST.Module.Name
2+module Elm.ModuleName
4− ( Canonical(..)
10+ , Canonical(..)
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
9 , jsonDecode, jsonEncode
17 , jsonDecode, jsonEncode
10 , webgl, texture, vector2, vector3, vector4, matrix4
18 , webgl, texture, vector2, vector3, vector4, matrix4
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
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
43+nameToString :: Raw -> String
48+nameToSlashPath :: Raw -> FilePath
49+nameToSlashPath name =
50+ map (\c -> if c == '.' then FP.pathSeparator else c) (Name.toString name)
53+nameToHyphenPath :: Raw -> FilePath
54+nameToHyphenPath name =
55+ map (\c -> if c == '.' then '-' else c) (Name.toString name)
58+fromHyphenPath :: Text.Text -> Maybe Raw
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))
70+encode :: Raw -> Encode.Value
75+decoder :: Decode.Decoder Text.Text Raw
77+ do txt <- Decode.text
78+ let str = Text.unpack txt
79+ if all isGoodChunk (splitOn '.' str)
80+ then Decode.succeed (Name.fromString str)
84+isGoodChunk :: String -> Bool
91+ Char.isUpper first && all isGoodChar rest
94+isGoodChar :: Char -> Bool
96+ Char.isAlphaNum c || c == '_'
99+splitOn :: Char -> String -> [String]
101+ uncurry (:) (splitOnHelp sep str)
104+splitOnHelp :: Char -> String -> (String, [String])
105+splitOnHelp sep str =
112+ (chunk,chunks) = splitOnHelp sep rest
28data Canonical =
124data Canonical =
@@ -33,18 +129,32 @@ data Canonical =
33 deriving (Ord)
129 deriving (Ord)
132+canonicalIsKernel :: Canonical -> Bool
133+canonicalIsKernel (Canonical _ name) =
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
146+instance Binary Canonical where
147+ put (Canonical a b) = put a >> put b
148+ get = liftM2 Canonical get get
42−-- PRIMITIVES
152+-- CORE
45{-# NOINLINE basics #-}
155{-# NOINLINE basics #-}
46basics :: Canonical
156basics :: Canonical
47−basics = Canonical Pkg.core "Basics"
157+basics = Canonical Pkg.core Name.basics
50{-# NOINLINE char #-}
160{-# NOINLINE char #-}
@@ -57,10 +167,6 @@ string :: Canonical
57string = Canonical Pkg.core Name.string
167string = Canonical Pkg.core Name.string
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
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"
117−{-# NOINLINE virtualDom #-}
118−virtualDom :: Canonical
119−virtualDom = Canonical Pkg.virtualDom Name.virtualDom
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
229+{-# NOINLINE virtualDom #-}
230+virtualDom :: Canonical
231+virtualDom = Canonical Pkg.virtualDom Name.virtualDom
@@ -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"
184−canonicalIsKernel :: Canonical -> Bool
185−canonicalIsKernel (Canonical _ name) =
193−instance Binary Canonical where
194− put (Canonical a b) =
198− liftM2 Canonical get get