on aee2191 help sign in
elk/src/AST/Module/Name.hs
101 lines 1.4 kB history raw
1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
3module AST.Module.Name
4 ( Raw
5 , Canonical(..)
6 , inVirtualDom, inCore, inHtml
7 , toString, toText, canonicalToText
8 , isKernel, getKernel, canonicalIsKernel
9 )
10 where
12import Data.Binary
13import qualified Data.Text as Text
14import Data.Text (Text)
16import qualified Elm.Package as Package
20-- NAMES
23type Raw = Text -- must be non-empty
26data Canonical =
27 Canonical
28 { _package :: !Package.Name
29 , _module :: !Raw
30 }
31 deriving (Eq, Ord)
35-- HELPERS
38inVirtualDom :: Raw -> Canonical
39inVirtualDom raw =
40 Canonical Package.virtualDom raw
43inCore :: Raw -> Canonical
44inCore raw =
45 Canonical Package.core raw
48inHtml :: Raw -> Canonical
49inHtml raw =
50 Canonical Package.html raw
54-- CONVERSIONS
57toString :: Raw -> String
58toString =
59 Text.unpack
62{-# INLINE toText #-}
63toText :: Raw -> Text
64toText name =
65 name
68canonicalToText :: Canonical -> Text
69canonicalToText (Canonical _ name) =
70 toText name
74-- IS KERNEL
77isKernel :: Raw -> Bool
78isKernel name =
79 Text.isPrefixOf "Elm.Kernel." name
82getKernel :: Raw -> Text
83getKernel name =
84 Text.drop 11 name
87canonicalIsKernel :: Canonical -> Bool
88canonicalIsKernel (Canonical _ name) =
89 isKernel name
93-- BINARY
96instance Binary Canonical where
97 put (Canonical home name) =
98 put home >> put name
100 get =
101 Canonical <$> get <*> get