module Elm
(
Expr
, bool
, string
, int
, float
, under
, var
, app
, list
, op
, let_
, case_
, parens
, Type
, tvar
, tparam
, tparams
, tapp
, tunit
, ttuple
, trecord
, trecordParam
, Dec
, decVariable
, decFunction
, decType
, decTypeAlias
, Import
, ImportExpr
, ImportItem
, select
, subSelect
, subSelectEvery
, importSome
, importEvery
, import_
, Module
, module_
, renderModule
, render
, genStr
)
where
import Protolude hiding (Type, bool, list)
import Control.Monad.Writer
import Data.String
import Elm.Classes
import qualified Elm.Decleration
import qualified Elm.Expression
import Elm.GenError (GenError (WarningList))
import qualified Elm.Import
import qualified Elm.Program
import qualified Elm.Type (TypeDec (..))
import qualified Text.PrettyPrint
type Expr = Elm.Expression.Expr
type Type = Elm.Type.TypeDec
type Dec = Elm.Decleration.Dec
type Import = Elm.Import.Import
type ImportExpr = Elm.Import.ImportType
type ImportItem = Elm.Import.ImportItem
type Module = Elm.Program.Program
bool :: Bool -> Expr
bool = Elm.Expression.Bool
string :: String -> Expr
string = Elm.Expression.Str
int :: Int -> Expr
int = Elm.Expression.Int
float :: Float -> Expr
float = Elm.Expression.Float
under :: Expr
under = Elm.Expression.Under
var :: String -> Expr
var = Elm.Expression.Var
app :: [Expr] -> Expr
app = Elm.Expression.App
list :: [Expr] -> Expr
list = Elm.Expression.List
op :: String -> Expr -> Expr -> Expr
op = Elm.Expression.Op
let_ :: Expr -> [(Expr, Expr)] -> Expr
let_ = Elm.Expression.Let
case_ :: Expr -> [(Expr, Expr)] -> Expr
case_ = Elm.Expression.Case
parens :: Expr -> Expr
parens = Elm.Expression.Parens
tvar :: String -> Type
tvar name = Elm.Type.Params name []
tparam :: String -> Type -> Type
tparam name type_ = Elm.Type.Params name [type_]
tparams :: String -> [Type] -> Type
tparams = Elm.Type.Params
tunit :: Type
tunit = Elm.Type.TTuple []
ttuple :: [Type] -> Type
ttuple = Elm.Type.TTuple
tapp :: [Type] -> Type
tapp = Elm.Type.TApp
trecord :: [(String, Type)] -> Type
trecord = Elm.Type.TRecord Nothing
trecordParam :: String -> [(String, Type)] -> Type
trecordParam = Elm.Type.TRecord . Just
decVariable :: String
-> Type
-> Expr
-> Dec
decVariable name type_ expr = Elm.Decleration.Dec name type_ [] expr
decFunction :: String
-> Type
-> [Expr]
-> Expr
-> Dec
decFunction = Elm.Decleration.Dec
decType :: String
-> [String]
-> [(String, [Type])]
-> Dec
decType = Elm.Decleration.DecType
decTypeAlias :: String
-> [String]
-> Type
-> Dec
decTypeAlias = Elm.Decleration.DecTypeAlias
select :: String -> ImportItem
select = Elm.Import.Item
subSelect :: String -> [String] -> ImportItem
subSelect = Elm.Import.ItemExposing
subSelectEvery :: String -> ImportItem
subSelectEvery = Elm.Import.ItemEvery
importSome :: [ImportItem] -> ImportExpr
importSome = Elm.Import.Select
importEvery :: ImportExpr
importEvery = Elm.Import.Everything
import_ :: String
-> (Maybe String)
-> (Maybe ImportExpr)
-> Import
import_ = Elm.Import.Import
module_ :: String
-> ImportExpr
-> [Import]
-> [Dec]
-> Module
module_ = Elm.Program.Program
renderModule :: Module -> (String, GenError)
renderModule = Elm.Program.renderProgram
render :: Module -> String
render module' =
let
(str, err) = renderModule module'
in
if err == WarningList [] then
str
else
error . show $ err
genStr :: (Generate a) => a -> String
genStr g =
let
(str, err) = runWriter . generate $ g
in
if err == WarningList [] then
Text.PrettyPrint.render str
else
error . show $ err