1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Elm.Compiler.Module
8 , interfaceAliasedTypes
22 , ModuleName.Canonical(..)
30import qualified Data.Aeson as Json
31import qualified Data.Char as Char
32import qualified Data.List as List
33import qualified Data.Map as Map
34import qualified Data.Text as Text
35import Data.Text (Text)
36import System.FilePath ((</>))
38import qualified AST.Module as Module
39import qualified AST.Module.Name as ModuleName
40import qualified AST.Variable as Var
41import qualified Elm.Compiler.Type as PublicType
42import qualified Elm.Compiler.Type.Extract as Extract
43import qualified Generate.JavaScript.Variable as Gen
50interfaceAliasedTypes :: Module.Interface -> Map.Map Text PublicType.Type
51interfaceAliasedTypes interface =
52 Map.map Extract.extract (Module.iTypes interface)
55programTypes :: Module.Interfaces -> ModuleName.Canonical -> Maybe PublicType.Program
57 Extract.extractProgram
64newtype RawForJson = RawForJson ModuleName.Raw
67fromJson :: RawForJson -> ModuleName.Raw
68fromJson (RawForJson raw) =
72qualifiedVar :: ModuleName.Canonical -> Text -> Text
78-- STRING CONVERSIONS for RAW NAMES
81nameToPath :: ModuleName.Raw -> FilePath
83 List.foldl1 (</>) (map Text.unpack (Text.splitOn "." name))
86nameToString :: ModuleName.Raw -> String
91nameFromText :: Text -> Maybe ModuleName.Raw
96hyphenate :: ModuleName.Raw -> Text
98 Text.replace "." "-" name
101dehyphenate :: Text -> Maybe ModuleName.Raw
106fromText :: Char -> Text -> Maybe ModuleName.Raw
110 Text.splitOn (Text.singleton sep) name
112 if all isGoodChunk chunks then Just name else Nothing
115isGoodChunk :: Text -> Bool
117 case Text.uncons chunk of
121 Just (first, rest) ->
122 Char.isUpper first && Text.all isGoodChar rest
125isGoodChar :: Char -> Bool
127 Char.isAlphaNum char || char == '_'
134instance Json.ToJSON RawForJson where
135 toJSON (RawForJson name) =
136 Json.toJSON (nameToString name)
139instance Json.FromJSON RawForJson where
140 parseJSON (Json.String text) =
141 case nameFromText text of
143 fail (Text.unpack text ++ " is not a valid module name")
146 return (RawForJson name)
149 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