1module Elm.Compiler.Module
2 ( Interface, Name(Name)
4 , nameToString, nameFromString
5 , hyphenate, dehyphenate
12import Control.Monad (mzero)
13import qualified Data.Aeson as Json
14import qualified Data.Char as Char
15import qualified Data.List as List
16import qualified Data.Map as Map
17import qualified Data.Text as Text
18import System.FilePath ((</>))
20import qualified AST.Module as Module
21import qualified Elm.Compiler.Imports as Imports
22import qualified Elm.Compiler.Type as Type
23import qualified Elm.Compiler.Type.Extract as Extract
28type Interface = Module.Interface
31newtype Name = Name [String]
35defaultImports :: [Name]
37 map (Name . fst) Imports.defaults
40-- POKING AROUND INTERFACES
42interfacePorts :: Interface -> [String]
43interfacePorts interface =
44 Module.iPorts interface
47interfaceTypes :: Interface -> Map.Map String Type.Type
48interfaceTypes interface =
49 Map.map Extract.fromInternalType (Module.iTypes interface)
52-- STRING CONVERSIONS for NAMES
54nameToPath :: Name -> FilePath
55nameToPath (Name names) =
56 List.foldl1 (</>) names
59nameToString :: Name -> String
60nameToString (Name names) =
61 List.intercalate "." names
64nameFromString :: String -> Maybe Name
69hyphenate :: Name -> String
70hyphenate (Name names) =
71 List.intercalate "-" names
74dehyphenate :: String -> Maybe Name
79fromString :: Char -> String -> Maybe Name
81 Name `fmap` mapM isLegit names
84 filter (/= [sep]) (List.groupBy (\a b -> a /= sep && b /= sep) raw)
90 if Char.isUpper char && all legitChar rest
95 Char.isAlphaNum char || char `elem` "_'"
100instance Json.ToJSON Name where
102 Json.toJSON (nameToString name)
105instance Json.FromJSON Name where
106 parseJSON (Json.String text) =
107 let rawName = Text.unpack text in
108 case nameFromString rawName of
109 Nothing -> fail (rawName ++ " is not a valid module name")
110 Just name -> return name
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