1module Elm.Compiler.Module
2 ( Interface, Name(Name)
4 , nameToString, nameFromString
5 , hyphenate, dehyphenate
8 , interfaceAliasedTypes
12import Control.Monad (mzero)
13import qualified Data.Aeson as Json
15import qualified Data.Char as Char
16import qualified Data.List as List
17import qualified Data.Map as Map
18import qualified Data.Text as Text
19import System.FilePath ((</>))
21import qualified AST.Module as Module
22import qualified Elm.Compiler.Imports as Imports
23import qualified Elm.Compiler.Type as Type
24import qualified Elm.Compiler.Type.Extract as Extract
29type Interface = Module.Interface
32newtype Name = Name [String]
36defaultImports :: [Name]
38 map (Name . fst) Imports.defaults
41-- POKING AROUND INTERFACES
43interfacePorts :: Interface -> [String]
44interfacePorts interface =
45 Module.iPorts interface
48interfaceAliasedTypes :: Interface -> Map.Map String Type.Type
49interfaceAliasedTypes interface =
50 Map.map Extract.toAliasedType (Module.iTypes interface)
53-- STRING CONVERSIONS for NAMES
55nameToPath :: Name -> FilePath
56nameToPath (Name names) =
57 List.foldl1 (</>) names
60nameToString :: Name -> String
61nameToString (Name names) =
62 List.intercalate "." names
65nameFromString :: String -> Maybe Name
70hyphenate :: Name -> String
71hyphenate (Name names) =
72 List.intercalate "-" names
75dehyphenate :: String -> Maybe Name
80fromString :: Char -> String -> Maybe Name
82 Name `fmap` mapM isLegit names
85 filter (/= [sep]) (List.groupBy (\a b -> a /= sep && b /= sep) raw)
91 if Char.isUpper char && all legitChar rest
96 Char.isAlphaNum char || char `elem` "_'"
101instance Json.ToJSON Name where
103 Json.toJSON (nameToString name)
106instance Json.FromJSON Name where
107 parseJSON (Json.String text) =
108 let rawName = Text.unpack text in
109 case nameFromString rawName of
110 Nothing -> fail (rawName ++ " is not a valid module name")
111 Just name -> return name
118instance 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