1module Elm.Compiler.Module
2 ( Interface, Interfaces
5 , nameToString, nameFromString
6 , hyphenate, dehyphenate
9 , interfaceAliasedTypes
10 , CanonicalName, canonicalName
14import Control.Monad (mzero)
15import qualified Data.Aeson as Json
17import qualified Data.Char as Char
18import qualified Data.List as List
19import qualified Data.Map as Map
20import qualified Data.Text as Text
21import System.FilePath ((</>))
23import qualified AST.Module as Module
24import qualified AST.Module.Name as ModuleName
25import qualified Elm.Compiler.Imports as Imports
26import qualified Elm.Compiler.Type as Type
27import qualified Elm.Compiler.Type.Extract as Extract
28import qualified Elm.Package as Package
35type Interface = Module.Interface
38type Interfaces = Module.Interfaces
41interfacePorts :: Interface -> [String]
42interfacePorts interface =
43 Module.iPorts interface
46interfaceAliasedTypes :: Interface -> Map.Map String Type.Type
47interfaceAliasedTypes interface =
48 Map.map Extract.toAliasedType (Module.iTypes interface)
55newtype Name = Name ModuleName.Raw
59type CanonicalName = ModuleName.Canonical
62canonicalName :: Package.Name -> Name -> CanonicalName
63canonicalName pkgName (Name name) =
64 ModuleName.Canonical pkgName name
67defaultImports :: [Name]
69 map (Name . fst) Imports.defaults
73-- 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` "_'"
124instance Json.ToJSON Name where
126 Json.toJSON (nameToString name)
129instance Json.FromJSON Name where
130 parseJSON (Json.String text) =
131 let rawName = Text.unpack text in
132 case nameFromString rawName of
133 Nothing -> fail (rawName ++ " is not a valid module name")
134 Just name -> return name
143instance 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