on 8a89c86 help sign in
elk/src/AST/Module/Name.hs
190 lines 2.9 kB history raw
1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
3module AST.Module.Name
4 ( Canonical(..)
5 , basics, char, string, debug
6 , maybe, list, array
7 , platform, cmd, sub, virtualDom
8 , jsonDecode, jsonEncode
9 , webgl, vector2, vector3, vector4, matrix4
10 , canonicalToText
11 , isKernel, getKernel, canonicalIsKernel
12 )
13 where
16import Prelude hiding (maybe)
17import Control.Monad (liftM2)
18import Data.Binary
19import qualified Data.Text as Text
20import Data.Text (Text)
22import qualified Elm.Name as N
23import qualified Elm.Package as Pkg
27-- NAMES
30data Canonical =
31 Canonical
32 { _package :: !Pkg.Name
33 , _module :: !N.Name
34 }
35 deriving (Ord)
38instance Eq Canonical where
39 (==) (Canonical pkg home) (Canonical pkg' home') =
40 home == home' && pkg == pkg'
44-- PRIMITIVES
47{-# NOINLINE basics #-}
48basics :: Canonical
49basics = Canonical Pkg.core "Basics"
52{-# NOINLINE char #-}
53char :: Canonical
54char = Canonical Pkg.core N.char
57{-# NOINLINE string #-}
58string :: Canonical
59string = Canonical Pkg.core N.string
62{-# NOINLINE debug #-}
63debug :: Canonical
64debug = Canonical Pkg.core N.debug
68-- CONTAINERS
71{-# NOINLINE maybe #-}
72maybe :: Canonical
73maybe = Canonical Pkg.core N.maybe
76{-# NOINLINE list #-}
77list :: Canonical
78list = Canonical Pkg.core N.list
81{-# NOINLINE array #-}
82array :: Canonical
83array = Canonical Pkg.core N.array
87-- EFFECTS
90{-# NOINLINE platform #-}
91platform :: Canonical
92platform = Canonical Pkg.core "Platform"
95{-# NOINLINE cmd #-}
96cmd :: Canonical
97cmd = Canonical Pkg.core "Platform.Cmd"
100{-# NOINLINE sub #-}
101sub :: Canonical
102sub = Canonical Pkg.core "Platform.Sub"
105{-# NOINLINE virtualDom #-}
106virtualDom :: Canonical
107virtualDom = Canonical Pkg.virtualDom "VirtualDom"
111-- JSON
114{-# NOINLINE jsonDecode #-}
115jsonDecode :: Canonical
116jsonDecode = Canonical Pkg.core "Json.Decode"
119{-# NOINLINE jsonEncode #-}
120jsonEncode :: Canonical
121jsonEncode = Canonical Pkg.core "Json.Encode"
125-- WEBGL
128{-# NOINLINE webgl #-}
129webgl :: Canonical
130webgl = Canonical Pkg.webgl "WebGL"
133{-# NOINLINE vector2 #-}
134vector2 :: Canonical
135vector2 = Canonical Pkg.linearAlgebra "Math.Vector2"
138{-# NOINLINE vector3 #-}
139vector3 :: Canonical
140vector3 = Canonical Pkg.linearAlgebra "Math.Vector3"
143{-# NOINLINE vector4 #-}
144vector4 :: Canonical
145vector4 = Canonical Pkg.linearAlgebra "Math.Vector4"
148{-# NOINLINE matrix4 #-}
149matrix4 :: Canonical
150matrix4 = Canonical Pkg.linearAlgebra "Math.Matrix4"
154-- CONVERSIONS
157canonicalToText :: Canonical -> Text
158canonicalToText (Canonical _ name) =
159 name
163-- IS KERNEL
166isKernel :: N.Name -> Bool
167isKernel name =
168 Text.isPrefixOf "Elm.Kernel." name
171getKernel :: N.Name -> Text
172getKernel name =
173 Text.drop 11 name
176canonicalIsKernel :: Canonical -> Bool
177canonicalIsKernel (Canonical _ name) =
178 isKernel name
182-- BINARY
185instance Binary Canonical where
186 put (Canonical a b) =
187 put a >> put b
189 get =
190 liftM2 Canonical get get