on master help sign in
Merge branch 'master' into patch-2
commita691999335b5c061ff1cdcefcabc8e046b5ee31e authorJanis Voigtländer <jvoigtlaender@users.noreply.github.com> dateThu 21 Apr 2016, 10:20 (11 years ago) parent01eaf19ec69a6c
2 files changed+21−59
src/Elm/Compiler.hs+20−4 src/Elm/Utils.hs+1−55
src/Elm/Compiler.hs+20−4
@@ -1,7 +1,7 @@
11{-# OPTIONS_GHC -Wall #-}
22module Elm.Compiler
33 ( version
4− , parseDependencies
4+ , parseDependencies, Tag(..)
55 , compile, Context(..), Result(..)
66 , Localizer, dummyLocalizer
77 , Error, errorToString, errorToJson, printError
@@ -47,14 +47,30 @@ version =
4747-- DEPENDENCIES
4848
4949
50−parseDependencies :: String -> Either [Error] (PublicModule.Raw, [PublicModule.Raw])
50+data Tag
51+ = Normal
52+ | Effect
53+ | Port
54+
55+
56+parseDependencies :: String -> Either [Error] (Tag, PublicModule.Raw, [PublicModule.Raw])
5157parseDependencies sourceCode =
5258 let
5359 (Result.Result _ _ answer) =
5460 Parse.parse sourceCode Parse.header
5561
56− getDeps (Module.Header _ name _ _ _ imports) =
57− ( name, map (fst . A.drop) imports )
62+ getDeps (Module.Header sourceTag name _ _ _ imports) =
63+ let
64+ tag =
65+ case sourceTag of
66+ Module.Normal -> Normal
67+ Module.Port _ -> Port
68+ Module.Effect _ -> Effect
69+ in
70+ ( tag
71+ , name
72+ , map (fst . A.drop) imports
73+ )
5874 in
5975 Result.answerToEither (Error . A.map Error.Syntax) getDeps answer
6076
src/Elm/Utils.hs+1−55
@@ -1,9 +1,7 @@
11{-# OPTIONS_GHC -Wall #-}
22{-# LANGUAGE FlexibleContexts #-}
3−{-# LANGUAGE MultiParamTypeClasses #-}
43module Elm.Utils
54 ( (|>), (<|)
6− , getAsset
75 , run, unwrappedRun
86 , CommandError(..)
97 , isDeclaration
@@ -11,16 +9,10 @@ module Elm.Utils
119
1210import Control.Monad.Except (MonadError, MonadIO, liftIO, throwError)
1311import qualified Data.List as List
14−import System.Directory (doesFileExist)
15−import System.Environment (getEnv)
1612import System.Exit (ExitCode(ExitSuccess, ExitFailure))
17−import System.FilePath ((</>))
18−import System.IO.Error (tryIOError)
1913import System.Process (readProcessWithExitCode)
2014
2115import qualified AST.Pattern as Pattern
22−import qualified Elm.Compiler.Version as Version
23−import qualified Elm.Package as Pkg
2416import qualified Parse.Helpers as Parse
2517import qualified Parse.Expression as Parse
2618import qualified Reporting.Annotation as A
@@ -69,7 +61,7 @@ run command args =
6961
7062 message err =
7163 case err of
72− CommandFailed stderr stdout ->
64+ CommandFailed stdout stderr ->
7365 stdout ++ stderr
7466
7567 MissingExe msg ->
@@ -103,52 +95,6 @@ missingExe command =
10395
10496
10597
106−-- GET STATIC ASSETS
107−
108−{-| Get the absolute path to a data file. If you install with cabal it will look
109−in a directory generated by cabal. If that is not found, it will look for the
110−directory pointed to by the environment variable ELM_HOME.
111−-}
112−getAsset :: String -> (FilePath -> IO FilePath) -> FilePath -> IO FilePath
113−getAsset project getDataFileName name =
114− do path <- getDataFileName name
115− exists <- doesFileExist path
116− if exists
117− then return path
118− else do
119− environment <- tryIOError (getEnv "ELM_HOME")
120− case environment of
121− Right env ->
122− return (env </> project </> name)
123−
124− Left _ ->
125− fail (errorNotFound name)
126−
127−
128−errorNotFound :: FilePath -> String
129−errorNotFound name =
130− unlines
131− [ "Unable to find the ELM_HOME environment variable when searching"
132− , "for the " ++ name ++ " file."
133− , ""
134− , "If you installed Elm Platform with the Mac or Windows installer, it looks like"
135− , "ELM_HOME was not set automatically. Look up how to set environment variables"
136− , "on your platform and set ELM_HOME to the directory that contains Elm's static"
137− , "files:"
138− , ""
139− , " * On Mac it is /usr/local/share/elm"
140− , " * On Windows it is one of the following:"
141− , " C:/Program Files/Elm Platform/" ++ (Pkg.versionToString Version.version) ++ "/share"
142− , " C:/Program Files (x86)/Elm Platform/" ++ (Pkg.versionToString Version.version) ++ "/share"
143− , ""
144− , "If you installed using npm, you have to set ELM_HOME to a certain directory"
145− , "of the form .../node_modules/elm/share"
146− , ""
147− , "If it seems like a more complex issue, please report it here:"
148− , " <https://github.com/elm-lang/elm-platform/issues>"
149− ]
150−
151−
15298-- DECL CHECKER
15399
154100isDeclaration :: String -> Maybe String