1{-# OPTIONS_GHC -Wall #-}
2module Elm.Compiler.Module
3 ( Interface, Interfaces
6 , nameToString, nameFromString
7 , hyphenate, dehyphenate
8 , RawForJson(RawForJson), fromJson
9 , interfaceAliasedTypes, programTypes
10 , ModuleName.Canonical(..), qualifiedVar
14import 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 AST.Module.Name as ModuleName
23import qualified Elm.Compiler.Type as PublicType
24import qualified Elm.Compiler.Type.Extract as Extract
25import qualified Generate.JavaScript.Variable as Gen
32type Interface = Module.Interface
35type Interfaces = Module.Interfaces
38interfaceAliasedTypes :: Interface -> Map.Map String PublicType.Type
39interfaceAliasedTypes interface =
40 Map.map Extract.extract (Module.iTypes interface)
43programTypes :: Interfaces -> ModuleName.Canonical -> Maybe PublicType.Program
45 Extract.extractProgram
52newtype RawForJson = RawForJson ModuleName.Raw
55fromJson :: RawForJson -> ModuleName.Raw
56fromJson (RawForJson raw) =
60qualifiedVar :: ModuleName.Canonical -> String -> String
66-- STRING CONVERSIONS for RAW NAMES
69nameToPath :: ModuleName.Raw -> FilePath
71 List.foldl1 (</>) names
74nameToString :: ModuleName.Raw -> String
76 List.intercalate "." names
79nameFromString :: String -> Maybe ModuleName.Raw
84hyphenate :: ModuleName.Raw -> String
86 List.intercalate "-" names
89dehyphenate :: String -> Maybe ModuleName.Raw
94fromString :: Char -> String -> Maybe ModuleName.Raw
99 filter (/= [sep]) (List.groupBy (\a b -> a /= sep && b /= sep) raw)
105 if Char.isUpper char && all legitChar rest
110 Char.isAlphaNum char || char `elem` "_'"
117instance Json.ToJSON RawForJson where
118 toJSON (RawForJson name) =
119 Json.toJSON (nameToString name)
122instance Json.FromJSON RawForJson where
123 parseJSON (Json.String text) =
128 case nameFromString rawString of
130 fail (rawString ++ " is not a valid module name")
133 return (RawForJson name)
136 fail "expecting the module name to be a string"
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