1{-# OPTIONS_GHC -Wall #-}
2module Elm.Compiler.Module
3 ( Interface, Interfaces
6 , nameToString, nameFromString
7 , hyphenate, dehyphenate
8 , RawForJson(RawForJson), fromJson
10 , interfaceAliasedTypes, programTypes
11 , ModuleName.Canonical(..), qualifiedVar
15import 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 PublicType
26import qualified Elm.Compiler.Type.Extract as Extract
27import qualified Generate.JavaScript.Variable as Gen
34type Interface = Module.Interface
37type Interfaces = Module.Interfaces
40interfaceAliasedTypes :: Interface -> Map.Map String PublicType.Type
41interfaceAliasedTypes interface =
42 Map.map Extract.extract (Module.iTypes interface)
45programTypes :: Interfaces -> ModuleName.Canonical -> Maybe PublicType.Program
47 Extract.extractProgram
54newtype RawForJson = RawForJson ModuleName.Raw
57fromJson :: RawForJson -> ModuleName.Raw
58fromJson (RawForJson raw) =
62qualifiedVar :: ModuleName.Canonical -> String -> String
67defaultImports :: [ModuleName.Raw]
69 map fst Imports.defaults
73-- STRING CONVERSIONS for RAW NAMES
76nameToPath :: ModuleName.Raw -> FilePath
78 List.foldl1 (</>) names
81nameToString :: ModuleName.Raw -> String
83 List.intercalate "." names
86nameFromString :: String -> Maybe ModuleName.Raw
91hyphenate :: ModuleName.Raw -> String
93 List.intercalate "-" names
96dehyphenate :: String -> Maybe ModuleName.Raw
101fromString :: Char -> String -> Maybe ModuleName.Raw
106 filter (/= [sep]) (List.groupBy (\a b -> a /= sep && b /= sep) raw)
112 if Char.isUpper char && all legitChar rest
117 Char.isAlphaNum char || char `elem` "_'"
124instance Json.ToJSON RawForJson where
125 toJSON (RawForJson name) =
126 Json.toJSON (nameToString name)
129instance Json.FromJSON RawForJson where
130 parseJSON (Json.String text) =
135 case nameFromString rawString of
137 fail (rawString ++ " is not a valid module name")
140 return (RawForJson name)
143 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