1module Elm.Compiler.Module
2 ( Interface, Interfaces, Name(Name)
4 , nameToString, nameFromString
5 , hyphenate, dehyphenate
8 , interfaceAliasedTypes
9 , ModuleName.Canonical(..)
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
31type Interface = Module.Interface
34type Interfaces = Module.Interfaces
37newtype Name = Name ModuleName.Raw
41defaultImports :: [Name]
43 map (Name . fst) Imports.defaults
46-- POKING AROUND INTERFACES
48interfacePorts :: Interface -> [String]
49interfacePorts interface =
50 Module.iPorts interface
53interfaceAliasedTypes :: Interface -> Map.Map String Type.Type
54interfaceAliasedTypes interface =
55 Map.map Extract.toAliasedType (Module.iTypes interface)
58-- STRING CONVERSIONS for NAMES
60nameToPath :: Name -> FilePath
61nameToPath (Name names) =
62 List.foldl1 (</>) names
65nameToString :: Name -> String
66nameToString (Name names) =
67 List.intercalate "." names
70nameFromString :: String -> Maybe Name
75hyphenate :: Name -> String
76hyphenate (Name names) =
77 List.intercalate "-" names
80dehyphenate :: String -> Maybe Name
85fromString :: Char -> String -> Maybe Name
87 Name `fmap` mapM isLegit names
90 filter (/= [sep]) (List.groupBy (\a b -> a /= sep && b /= sep) raw)
96 if Char.isUpper char && all legitChar rest
101 Char.isAlphaNum char || char `elem` "_'"
106instance Json.ToJSON Name where
108 Json.toJSON (nameToString name)
111instance Json.FromJSON Name where
112 parseJSON (Json.String text) =
113 let rawName = Text.unpack text in
114 case nameFromString rawName of
115 Nothing -> fail (rawName ++ " is not a valid module name")
116 Just name -> return name
123instance 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