module Language.Fay.Types
(JsStmt(..)
,JsExp(..)
,JsLit(..)
,JsParam
,JsName
,CompileError(..)
,Compile(..)
,CompilesTo(..)
,Printable(..)
,Fay
,CompileConfig(..)
,CompileState(..)
,FundamentalType(..))
where
import Control.Applicative
import Control.Exception
import Control.Monad.Error (Error, ErrorT, MonadError)
import Control.Monad.Identity (Identity)
import Control.Monad.State
import Data.Data
import Data.Default
import Language.Haskell.Exts
data CompileConfig = CompileConfig
{ configTCO :: Bool
, configInlineForce :: Bool
, configFlattenApps :: Bool
, configExportBuiltins :: Bool
} deriving (Show)
instance Default CompileConfig where
def = CompileConfig False False False True
data CompileState = CompileState
{ stateConfig :: CompileConfig
, stateExports :: [Name]
, stateExportAll :: Bool
, stateModuleName :: ModuleName
, stateRecords :: [(Name,[Name])]
} deriving (Show)
newtype Compile a = Compile { unCompile :: StateT CompileState (ErrorT CompileError IO) a }
deriving (MonadState CompileState
,MonadError CompileError
,MonadIO
,Monad
,Functor
,Applicative)
type JsParam = JsName
type JsName = QName
class (Parseable from,Printable to) => CompilesTo from to | from -> to where
compileTo :: from -> Compile to
class Printable a where
printJS :: a -> String
data CompileError
= ParseError SrcLoc String
| UnsupportedDeclaration Decl
| UnsupportedExportSpec ExportSpec
| UnsupportedMatchSyntax Match
| UnsupportedWhereInMatch Match
| UnsupportedExpression Exp
| UnsupportedLiteral Literal
| UnsupportedLetBinding Decl
| UnsupportedOperator QOp
| UnsupportedPattern Pat
| UnsupportedRhs Rhs
| UnsupportedGuardedAlts GuardedAlts
| EmptyDoBlock
| UnsupportedModuleSyntax Module
| LetUnsupported
| InvalidDoBlock
| RecursiveDoUnsupported
| FfiNeedsTypeSig Decl
| FfiFormatBadChars String
| FfiFormatNoSuchArg Int
| FfiFormatIncompleteArg
| FfiFormatInvalidJavaScript String String
deriving (Show,Eq,Data,Typeable)
instance Error CompileError
instance Exception CompileError
newtype Fay a = Fay (Identity a)
deriving Monad
data JsStmt
= JsVar JsName JsExp
| JsIf JsExp [JsStmt] [JsStmt]
| JsEarlyReturn JsExp
| JsThrow JsExp
| JsWhile JsExp [JsStmt]
| JsUpdate JsName JsExp
| JsSetProp JsName JsName JsExp
| JsContinue
deriving (Show,Eq)
data JsExp
= JsName JsName
| JsRawExp String
| JsFun [JsParam] [JsStmt] (Maybe JsExp)
| JsLit JsLit
| JsApp JsExp [JsExp]
| JsTernaryIf JsExp JsExp JsExp
| JsNull
| JsSequence [JsExp]
| JsParen JsExp
| JsGetProp JsExp JsName
| JsLookup JsExp JsExp
| JsUpdateProp JsExp JsName JsExp
| JsGetPropExtern JsExp JsName
| JsUpdatePropExtern JsExp JsName JsExp
| JsList [JsExp]
| JsNew JsName [JsExp]
| JsThrowExp JsExp
| JsInstanceOf JsExp JsName
| JsIndex Int JsExp
| JsEq JsExp JsExp
| JsInfix String JsExp JsExp
deriving (Show,Eq)
data JsLit
= JsChar Char
| JsStr String
| JsInt Int
| JsFloating Double
| JsBool Bool
deriving (Show,Eq)
data FundamentalType
= FunctionType [FundamentalType]
| JsType FundamentalType
| ListType FundamentalType
| DateType
| StringType
| DoubleType
| BoolType
| UnknownType
deriving (Show,Eq)