1module Elm.Compiler.Module
2 ( Interface, Interfaces
5 , nameToString, nameFromString
6 , hyphenate, dehyphenate
8 , interfaceAliasedTypes
9 , CanonicalName, canonicalName
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 AST.Module.Name as ModuleName
24import qualified Elm.Compiler.Imports as Imports
25import qualified Elm.Compiler.Type as Type
26import qualified Elm.Compiler.Type.Extract as Extract
27import qualified Elm.Package as Package
34type Interface = Module.Interface
37type Interfaces = Module.Interfaces
40interfaceAliasedTypes :: Interface -> Map.Map String Type.Type
41interfaceAliasedTypes interface =
42 Map.map Extract.toAliasedType (Module.iTypes interface)
49newtype Name = Name ModuleName.Raw
53type CanonicalName = ModuleName.Canonical
56canonicalName :: Package.Name -> Name -> CanonicalName
57canonicalName pkgName (Name name) =
58 ModuleName.Canonical pkgName name
61defaultImports :: [Name]
63 map (Name . fst) Imports.defaults
67-- STRING CONVERSIONS for NAMES
70nameToPath :: Name -> FilePath
71nameToPath (Name names) =
72 List.foldl1 (</>) names
75nameToString :: Name -> String
76nameToString (Name names) =
77 List.intercalate "." names
80nameFromString :: String -> Maybe Name
85hyphenate :: Name -> String
86hyphenate (Name names) =
87 List.intercalate "-" names
90dehyphenate :: String -> Maybe Name
95fromString :: Char -> String -> Maybe Name
97 Name `fmap` mapM isLegit names
100 filter (/= [sep]) (List.groupBy (\a b -> a /= sep && b /= sep) raw)
106 if Char.isUpper char && all legitChar rest
111 Char.isAlphaNum char || char `elem` "_'"
118instance Json.ToJSON Name where
120 Json.toJSON (nameToString name)
123instance Json.FromJSON Name where
124 parseJSON (Json.String text) =
125 let rawName = Text.unpack text in
126 case nameFromString rawName of
127 Nothing -> fail (rawName ++ " is not a valid module name")
128 Just name -> return name
137instance 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