on ea5c662 help sign in
elk/src/AST/Module/Name.hs
175 lines 2.6 kB history raw
1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
3module AST.Module.Name
4 ( Canonical(..)
5 , basics, char, string
6 , maybe, list, array
7 , platform, cmd, sub
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 (Eq, Ord)
39-- PRIMITIVES
42{-# NOINLINE basics #-}
43basics :: Canonical
44basics = Canonical Pkg.core "Basics"
47{-# NOINLINE char #-}
48char :: Canonical
49char = Canonical Pkg.core "Char"
52{-# NOINLINE string #-}
53string :: Canonical
54string = Canonical Pkg.core "String"
58-- CONTAINERS
61{-# NOINLINE maybe #-}
62maybe :: Canonical
63maybe = Canonical Pkg.core "Maybe"
66{-# NOINLINE list #-}
67list :: Canonical
68list = Canonical Pkg.core "List"
71{-# NOINLINE array #-}
72array :: Canonical
73array = Canonical Pkg.core "Array"
77-- EFFECTS
80{-# NOINLINE platform #-}
81platform :: Canonical
82platform = Canonical Pkg.core "Platform"
85{-# NOINLINE cmd #-}
86cmd :: Canonical
87cmd = Canonical Pkg.core "Platform.Cmd"
90{-# NOINLINE sub #-}
91sub :: Canonical
92sub = Canonical Pkg.core "Platform.Sub"
96-- JSON
99{-# NOINLINE jsonDecode #-}
100jsonDecode :: Canonical
101jsonDecode = Canonical Pkg.core "Json.Decode"
104{-# NOINLINE jsonEncode #-}
105jsonEncode :: Canonical
106jsonEncode = Canonical Pkg.core "Json.Encode"
110-- WEBGL
113{-# NOINLINE webgl #-}
114webgl :: Canonical
115webgl = Canonical Pkg.webgl "WebGL"
118{-# NOINLINE vector2 #-}
119vector2 :: Canonical
120vector2 = Canonical Pkg.linearAlgebra "Math.Vector2"
123{-# NOINLINE vector3 #-}
124vector3 :: Canonical
125vector3 = Canonical Pkg.linearAlgebra "Math.Vector3"
128{-# NOINLINE vector4 #-}
129vector4 :: Canonical
130vector4 = Canonical Pkg.linearAlgebra "Math.Vector4"
133{-# NOINLINE matrix4 #-}
134matrix4 :: Canonical
135matrix4 = Canonical Pkg.linearAlgebra "Math.Matrix4"
139-- CONVERSIONS
142canonicalToText :: Canonical -> Text
143canonicalToText (Canonical _ name) =
144 name
148-- IS KERNEL
151isKernel :: N.Name -> Bool
152isKernel name =
153 Text.isPrefixOf "Elm.Kernel." name
156getKernel :: N.Name -> Text
157getKernel name =
158 Text.drop 11 name
161canonicalIsKernel :: Canonical -> Bool
162canonicalIsKernel (Canonical _ name) =
163 isKernel name
167-- BINARY
170instance Binary Canonical where
171 put (Canonical a b) =
172 put a >> put b
174 get =
175 liftM2 Canonical get get