Skip to content

Commit

Permalink
Merge branch 'master' into patch-2
Browse files Browse the repository at this point in the history
  • Loading branch information
jvoigtlaender committed Apr 21, 2016
2 parents 01eaf19 + ec69a6c commit a691999
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 59 deletions.
24 changes: 20 additions & 4 deletions src/Elm/Compiler.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{-# OPTIONS_GHC -Wall #-}
module Elm.Compiler
( version
, parseDependencies
, parseDependencies, Tag(..)
, compile, Context(..), Result(..)
, Localizer, dummyLocalizer
, Error, errorToString, errorToJson, printError
Expand Down Expand Up @@ -47,14 +47,30 @@ version =
-- DEPENDENCIES


parseDependencies :: String -> Either [Error] (PublicModule.Raw, [PublicModule.Raw])
data Tag
= Normal
| Effect
| Port


parseDependencies :: String -> Either [Error] (Tag, PublicModule.Raw, [PublicModule.Raw])
parseDependencies sourceCode =
let
(Result.Result _ _ answer) =
Parse.parse sourceCode Parse.header

getDeps (Module.Header _ name _ _ _ imports) =
( name, map (fst . A.drop) imports )
getDeps (Module.Header sourceTag name _ _ _ imports) =
let
tag =
case sourceTag of
Module.Normal -> Normal
Module.Port _ -> Port
Module.Effect _ -> Effect
in
( tag
, name
, map (fst . A.drop) imports
)
in
Result.answerToEither (Error . A.map Error.Syntax) getDeps answer

Expand Down
56 changes: 1 addition & 55 deletions src/Elm/Utils.hs
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
{-# OPTIONS_GHC -Wall #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module Elm.Utils
( (|>), (<|)
, getAsset
, run, unwrappedRun
, CommandError(..)
, isDeclaration
) where

import Control.Monad.Except (MonadError, MonadIO, liftIO, throwError)
import qualified Data.List as List
import System.Directory (doesFileExist)
import System.Environment (getEnv)
import System.Exit (ExitCode(ExitSuccess, ExitFailure))
import System.FilePath ((</>))
import System.IO.Error (tryIOError)
import System.Process (readProcessWithExitCode)

import qualified AST.Pattern as Pattern
import qualified Elm.Compiler.Version as Version
import qualified Elm.Package as Pkg
import qualified Parse.Helpers as Parse
import qualified Parse.Expression as Parse
import qualified Reporting.Annotation as A
Expand Down Expand Up @@ -69,7 +61,7 @@ run command args =

message err =
case err of
CommandFailed stderr stdout ->
CommandFailed stdout stderr ->
stdout ++ stderr

MissingExe msg ->
Expand Down Expand Up @@ -103,52 +95,6 @@ missingExe command =



-- GET STATIC ASSETS

{-| Get the absolute path to a data file. If you install with cabal it will look
in a directory generated by cabal. If that is not found, it will look for the
directory pointed to by the environment variable ELM_HOME.
-}
getAsset :: String -> (FilePath -> IO FilePath) -> FilePath -> IO FilePath
getAsset project getDataFileName name =
do path <- getDataFileName name
exists <- doesFileExist path
if exists
then return path
else do
environment <- tryIOError (getEnv "ELM_HOME")
case environment of
Right env ->
return (env </> project </> name)

Left _ ->
fail (errorNotFound name)


errorNotFound :: FilePath -> String
errorNotFound name =
unlines
[ "Unable to find the ELM_HOME environment variable when searching"
, "for the " ++ name ++ " file."
, ""
, "If you installed Elm Platform with the Mac or Windows installer, it looks like"
, "ELM_HOME was not set automatically. Look up how to set environment variables"
, "on your platform and set ELM_HOME to the directory that contains Elm's static"
, "files:"
, ""
, " * On Mac it is /usr/local/share/elm"
, " * On Windows it is one of the following:"
, " C:/Program Files/Elm Platform/" ++ (Pkg.versionToString Version.version) ++ "/share"
, " C:/Program Files (x86)/Elm Platform/" ++ (Pkg.versionToString Version.version) ++ "/share"
, ""
, "If you installed using npm, you have to set ELM_HOME to a certain directory"
, "of the form .../node_modules/elm/share"
, ""
, "If it seems like a more complex issue, please report it here:"
, " <https://github.com/elm-lang/elm-platform/issues>"
]


-- DECL CHECKER

isDeclaration :: String -> Maybe String
Expand Down

0 comments on commit a691999

Please sign in to comment.