Get the haskell library working

This commit is contained in:
Evan Czaplicki 2013-07-31 09:31:48 -07:00
parent e677f27bc5
commit 2c96bf0c33
2 changed files with 75 additions and 98 deletions

170
Elm.cabal
View file

@ -29,72 +29,73 @@ source-repository head
type: git type: git
location: git://github.com/evancz/Elm.git location: git://github.com/evancz/Elm.git
--Library Library
-- exposed-modules: Language.Elm, exposed-modules: Language.Elm,
-- Language.Elm.Quasi Language.Elm.Quasi
-- Hs-Source-Dirs: compiler Hs-Source-Dirs: compiler
-- other-modules: Unique, other-modules: Unique,
-- SourceSyntax.Declaration, SourceSyntax.Declaration,
-- SourceSyntax.Expression, SourceSyntax.Expression,
-- SourceSyntax.Everything, SourceSyntax.Everything,
-- SourceSyntax.Helpers, SourceSyntax.Helpers,
-- SourceSyntax.Literal, SourceSyntax.Literal,
-- SourceSyntax.Location, SourceSyntax.Location,
-- SourceSyntax.Module, SourceSyntax.Module,
-- SourceSyntax.Pattern, SourceSyntax.Pattern,
-- SourceSyntax.Type, SourceSyntax.Type,
-- Generate.JavaScript, Generate.JavaScript,
-- Generate.Noscript, Generate.Noscript,
-- Generate.Html, Generate.Html,
-- Generate.Cases, Generate.Cases,
-- Transform.Canonicalize, Transform.Canonicalize,
-- Transform.Substitute, Transform.SortDefinitions,
-- Transform.Optimize, Transform.Substitute,
-- Metadata.Prelude, Transform.Optimize,
-- Initialize, Metadata.Prelude,
-- Parse.Binop, Initialize,
-- Parse.Declaration, Parse.Binop,
-- Parse.Expression, Parse.Declaration,
-- Parse.Helpers, Parse.Expression,
-- Parse.Literal, Parse.Helpers,
-- Parse.Module, Parse.Literal,
-- Parse.Parse, Parse.Module,
-- Parse.Pattern, Parse.Parse,
-- Parse.Type, Parse.Pattern,
-- Type.Constrain.Declaration, Parse.Type,
-- Type.Constrain.Expression, Type.Constrain.Declaration,
-- Type.Constrain.Literal, Type.Constrain.Expression,
-- Type.Constrain.Pattern, Type.Constrain.Literal,
-- Type.Environment, Type.Constrain.Pattern,
-- Type.Fragment, Type.Environment,
-- Type.Solve, Type.Fragment,
-- Type.State, Type.Solve,
-- Type.Type, Type.State,
-- Type.Unify, Type.Type,
-- Paths_Elm Type.Unify,
-- Paths_Elm
-- Build-depends: base >=4.2 && <5,
-- binary, Build-depends: base >=4.2 && <5,
-- blaze-html == 0.5.* || == 0.6.*, binary,
-- blaze-markup == 0.5.1.*, blaze-html == 0.5.* || == 0.6.*,
-- bytestring, blaze-markup == 0.5.1.*,
-- cmdargs, bytestring,
-- containers >= 0.3, cmdargs,
-- deepseq, containers >= 0.3,
-- directory, deepseq,
-- filepath, directory,
-- hjsmin, filepath,
-- indents, hjsmin,
-- mtl >= 2, indents,
-- pandoc >= 1.10, mtl >= 2,
-- parsec >= 3.1.1, pandoc >= 1.10,
-- pretty, parsec >= 3.1.1,
-- shakespeare, pretty,
-- text, shakespeare,
-- template-haskell, text,
-- transformers >= 0.2, template-haskell,
-- union-find, transformers >= 0.2,
-- uniplate union-find,
uniplate
Executable elm Executable elm
Main-is: Compiler.hs Main-is: Compiler.hs
@ -114,6 +115,7 @@ Executable elm
Generate.Html, Generate.Html,
Generate.Cases, Generate.Cases,
Transform.Canonicalize, Transform.Canonicalize,
Transform.SortDefinitions,
Transform.Substitute, Transform.Substitute,
Transform.Optimize, Transform.Optimize,
Metadata.Prelude, Metadata.Prelude,
@ -159,34 +161,8 @@ Executable elm
union-find, union-find,
uniplate uniplate
--Executable elm-doc Test-Suite test-elm
-- Main-is: Docs.hs Type: exitcode-stdio-1.0
-- Hs-Source-Dirs: compiler Hs-Source-Dirs: tests
-- other-modules: SourceSyntax.Helpers, Main-is: Everything.hs
-- SourceSyntax.Location, build-depends: base
-- SourceSyntax.Literal,
-- SourceSyntax.Pattern,
-- SourceSyntax.Expression,
-- SourceSyntax.Declaration,
-- SourceSyntax.Module,
-- Parse.Helpers,
-- Parse.Module
--
-- Build-depends: base >=4.2 && <5,
-- binary,
-- containers >= 0.3,
-- transformers >= 0.2,
-- mtl >= 2,
-- parsec >= 3.1.1,
-- pandoc >= 1.10,
-- pretty,
-- cmdargs,
-- filepath,
-- union-find,
-- indents
--Test-Suite test-elm
-- Type: exitcode-stdio-1.0
-- Hs-Source-Dirs: tests
-- Main-is: Everything.hs
-- build-depends: base

View file

@ -23,13 +23,14 @@ import SourceSyntax.Module
import Text.Blaze.Html (Html) import Text.Blaze.Html (Html)
import Text.Parsec (option,optional) import Text.Parsec (option,optional)
import qualified Text.PrettyPrint as P import qualified Text.PrettyPrint as P
import qualified Metadata.Prelude as Prelude
import Paths_Elm import Paths_Elm
-- |This function compiles Elm code to JavaScript. It will return either -- |This function compiles Elm code to JavaScript. It will return either
-- an error message or the compiled JS code. -- an error message or the compiled JS code.
compile :: String -> Either String String compile :: String -> Either String String
compile source = compile source =
case buildFromSource Map.empty source of case buildFromSource False Prelude.interfaces source of
Left docs -> Left . unlines $ map P.render docs Left docs -> Left . unlines $ map P.render docs
Right modul -> Right $ jsModule (modul :: MetadataModule () ()) Right modul -> Right $ jsModule (modul :: MetadataModule () ())