on 00a3069 help sign in
elk/src/Elm/Name.hs
226 lines 3.1 kB history raw
1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Elm.Name
4 ( Name
5 , length
6 , startsWith
7 , toString
8 , toBuilder
9 , toShort
10 , addIndex
11 , toCompositeName
12 , fromForeignPtr
13 , int, float, bool, char, string
14 , maybe, list, array, tuple, jsArray
15 , task, router, cmd, sub, platform, browser
16 , shader, debug, bitwise, basics
17 , utils, negate, value
18 , node, program, main, dollar, identity
19 )
20 where
23import Prelude hiding (length, maybe, negate)
24import qualified Data.ByteString.Builder as B
25import qualified Data.ByteString.Internal as B
26import qualified Data.ByteString.Short as S
27import qualified Data.Set as Set
28import qualified Data.Text as Text
29import qualified Data.Text.Encoding as Text
30import Data.Word (Word8)
31import Foreign.ForeignPtr (ForeignPtr)
35-- NAME
38type Name = Text.Text
41length :: Name -> Int
42length =
43 Text.length
46startsWith :: Name -> Name -> Bool
47startsWith =
48 Text.isPrefixOf
51toString :: Name -> String
52toString =
53 Text.unpack
56toBuilder :: Name -> B.Builder
57toBuilder =
58 Text.encodeUtf8Builder
61toShort :: Name -> S.ShortByteString
62toShort =
63 error "TODO"
66addIndex :: Name -> Int -> Name
67addIndex name i =
68 Text.append name (Text.pack (show i))
71toCompositeName :: Set.Set Name -> Name
72toCompositeName names =
73 Text.cons '$' (Text.intercalate "$" (Set.toList names))
77-- FROM PARSER
80fromForeignPtr :: ForeignPtr Word8 -> Int -> Int -> Name
81fromForeignPtr fptr offset len =
82 Text.decodeUtf8 (B.PS fptr offset len)
86-- COMMON NAMES
89{-# NOINLINE int #-}
90int :: Name
91int = "Int"
94{-# NOINLINE float #-}
95float :: Name
96float = "Float"
99{-# NOINLINE bool #-}
100bool :: Name
101bool = "Bool"
104{-# NOINLINE char #-}
105char :: Name
106char = "Char"
109{-# NOINLINE string #-}
110string :: Name
111string = "String"
114{-# NOINLINE maybe #-}
115maybe :: Name
116maybe = "Maybe"
119{-# NOINLINE list #-}
120list :: Name
121list = "List"
124{-# NOINLINE array #-}
125array :: Name
126array = "Array"
129{-# NOINLINE tuple #-}
130tuple :: Name
131tuple = "Tuple"
134{-# NOINLINE jsArray #-}
135jsArray :: Name
136jsArray = "JsArray"
139{-# NOINLINE task #-}
140task :: Name
141task = "Task"
144{-# NOINLINE router #-}
145router :: Name
146router = "Router"
149{-# NOINLINE cmd #-}
150cmd :: Name
151cmd = "Cmd"
154{-# NOINLINE sub #-}
155sub :: Name
156sub = "Sub"
159{-# NOINLINE platform #-}
160platform :: Name
161platform = "Platform"
164{-# NOINLINE browser #-}
165browser :: Name
166browser = "Browser"
169{-# NOINLINE shader #-}
170shader :: Name
171shader = "Shader"
174{-# NOINLINE debug #-}
175debug :: Name
176debug = "Debug"
179{-# NOINLINE bitwise #-}
180bitwise :: Name
181bitwise = "Bitwise"
184{-# NOINLINE basics #-}
185basics :: Name
186basics = "Basics"
189{-# NOINLINE utils #-}
190utils :: Name
191utils = "Utils"
194{-# NOINLINE negate #-}
195negate :: Name
196negate = "negate"
199{-# NOINLINE value #-}
200value :: Name
201value = "Value"
204{-# NOINLINE node #-}
205node :: Name
206node = "Node"
209{-# NOINLINE program #-}
210program :: Name
211program = "Program"
214{-# NOINLINE main #-}
215main :: Name
216main = "main"
219{-# NOINLINE dollar #-}
220dollar :: Name
221dollar = "$"
224{-# NOINLINE identity #-}
225identity :: Name
226identity = "identity"