1module Elm.Compiler.Module
2 ( Interface, Name(Name), name
3 , CanonicalName(CanonicalName), canonicalName, canonPkg, canonModul, fromCanonicalName
5 , nameToString, nameFromString
6 , hyphenate, dehyphenate
9 , interfaceAliasedTypes
13import Control.Monad (mzero)
14import qualified Data.Aeson as Json
16import qualified Data.Char as Char
17import qualified Data.List as List
18import qualified Data.Map as Map
19import qualified Data.Text as Text
20import System.FilePath ((</>))
22import qualified AST.Module as Module
23import qualified Elm.Compiler.Imports as Imports
24import qualified Elm.Compiler.Type as Type
25import qualified Elm.Compiler.Type.Extract as Extract
26import qualified Elm.Package as Package
31type Interface = Module.Interface
34newtype Name = Name [String]
39 { canonPkg :: Package.Name
44fromCanonicalName :: CanonicalName -> Module.CanonicalName
45fromCanonicalName (CanonicalName p (Name n)) =
46 Module.CanonicalName p n
49canonicalName :: Package.Name -> Name -> CanonicalName
50canonicalName = CanonicalName
53name :: [String] -> Name
57defaultImports :: [Name]
59 map (Name . fst) Imports.defaults
62-- POKING AROUND INTERFACES
64interfacePorts :: Interface -> [String]
65interfacePorts interface =
66 Module.iPorts interface
69interfaceAliasedTypes :: Interface -> Map.Map String Type.Type
70interfaceAliasedTypes interface =
71 Map.map Extract.toAliasedType (Module.iTypes interface)
74-- STRING CONVERSIONS for NAMES
76nameToPath :: Name -> FilePath
77nameToPath (Name names) =
78 List.foldl1 (</>) names
81nameToString :: Name -> String
82nameToString (Name names) =
83 List.intercalate "." names
86nameFromString :: String -> Maybe Name
91hyphenate :: Name -> String
92hyphenate (Name names) =
93 List.intercalate "-" names
96dehyphenate :: String -> Maybe Name
101fromString :: Char -> String -> Maybe Name
103 Name `fmap` mapM isLegit names
106 filter (/= [sep]) (List.groupBy (\a b -> a /= sep && b /= sep) raw)
112 if Char.isUpper char && all legitChar rest
117 Char.isAlphaNum char || char `elem` "_'"
122instance Json.ToJSON Name where
124 Json.toJSON (nameToString name)
127instance Json.FromJSON Name where
128 parseJSON (Json.String text) =
129 let rawName = Text.unpack text in
130 case nameFromString rawName of
131 Nothing -> fail (rawName ++ " is not a valid module name")
132 Just name -> return name
139instance Binary Name where
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list