HJavaScript-0.4.7: HJavaScript is an abstract syntax for a typed subset of JavaScript.Source codeContentsIndex
Language.HJavaScript.Syntax
Stabilityexperimental
MaintainerJoel Bjornson joel.bjornson@gmail.com Niklas Broberg nibro@cs.chalmers.se
Contents
Primitive type classes.
Fundamental data types.
Data types and classes for object representation.
Misc
Types for functions and parameters.
Array representation.
Type synonyms.
Type classes for expression representation.
Helper functions
Render function producing multi-line pretty-printed JavaScript code.
Description
Synopsis
class JType t
data Exp t where
JInt :: Int -> Exp Int
JFloat :: Float -> Exp Float
JBool :: Bool -> Exp Bool
JString :: String -> Exp String
JRec :: Exp a -> Exp b -> Exp (Rec a b)
JFst :: Exp (Rec a b) -> Exp a
JSnd :: Exp (Rec a b) -> Exp b
JConst :: String -> Exp t
JAssign :: Var t -> Exp t -> Exp t
JAssignWith :: Var t -> AssignOp t -> Exp t -> Exp t
JNeg :: Exp t -> Exp t
JNot :: Exp Bool -> Exp Bool
JBinOp :: Exp t -> BinOp t r -> Exp t -> Exp r
JIncrement :: Num t => PostPre -> Var t -> Exp t
JDecrement :: Num t => PostPre -> Var t -> Exp t
JIfOp :: Exp Bool -> Exp t -> Exp t -> Exp t
JCall :: Args e t => Exp (t -> r) -> e -> Exp r
JNew :: (Args e t, HasConstructor c e t) => c -> e -> Exp c
JDelete :: Var a -> Exp Bool
JDeref :: IsDeref d => d -> String -> Exp t
JFunction :: FormalParams a t => Maybe String -> a -> Block r -> Exp (t -> r)
JThis :: IsClass c => Exp c
JBlock :: Block () -> Exp ()
JNull :: IsNullable t => Exp t
JCastObject :: (IsClass c1, IsClass c2) => Exp c1 -> Exp c2
JValueOf :: Var t -> Exp t
JIsImpl :: (IsClass c, IsFeature f) => Exp c -> f -> Exp Bool
JShow :: JShow t => Exp t -> Exp String
data Rec a b
data Var t where
JVar :: String -> Var a
JParam :: String -> Var a
JMember :: String -> Var a
JDerefVar :: IsDeref d => d -> String -> Var a
JArrayIndex :: Exp (Array t) -> Exp Int -> Var t
JPropertyVar :: (IsDeref d, JShow p) => d -> Exp p -> Var a
data Stmt t where
VarDecl :: String -> Stmt ()
VarDeclAssign :: String -> Exp t -> Stmt ()
VarAssign :: String -> Exp t -> Stmt ()
ExpStmt :: Exp t -> Stmt ()
While :: Exp Bool -> Block () -> Stmt ()
DoWhile :: Block () -> Exp Bool -> Stmt ()
For :: Stmt t1 -> Exp Bool -> Exp t2 -> Block () -> Stmt ()
ForIn :: IsDeref d => Var String -> d -> Block () -> Stmt ()
Break :: Stmt ()
Continue :: Stmt ()
Return :: Exp t -> Stmt t
If :: Exp Bool -> Block t -> Elses t -> Stmt ()
data Block t where
EmptyBlock :: Block ()
Sequence :: Block () -> Stmt t -> Block t
class Show c => IsClass c
class (IsClass c, Args e t) => HasConstructor c e t
class Show r => IsDeref r
data AssignOp t where
PlusAssign :: Num t => AssignOp t
MinusAssign :: Num t => AssignOp t
TimesAssign :: Num t => AssignOp t
DivAssign :: AssignOp Float
ModAssign :: AssignOp Int
AndAssign :: AssignOp Bool
OrAssign :: AssignOp Bool
data BinOp t r where
Plus :: PlusOpType t => BinOp t t
Minus :: Num t => BinOp t t
Times :: Num t => BinOp t t
Div :: Num t => BinOp t t
Mod :: BinOp Int Int
And :: BinOp Bool Bool
Or :: BinOp Bool Bool
Equals :: BinOp t Bool
NotEquals :: BinOp t Bool
GThan :: Num t => BinOp t Bool
LThan :: Num t => BinOp t Bool
GEThan :: Num t => BinOp t Bool
LEThan :: Num t => BinOp t Bool
class PlusOpType a
data PostPre
= Pst
| Pre
data Elses t where
Elseif :: Exp Bool -> Block t -> Elses t -> Elses t
Else :: Block t -> Elses t
NoElse :: Elses ()
class IsNullable a
class Show a => IsFeature a
class JShow a where
jshow :: a -> JString
class Show e => Args e t | e -> t
class ParamType t
class (Show a, ParamType t) => FormalParams a t | a -> t where
mkFParams :: forall b. (a -> b) -> Int -> a
showsFParams :: a -> ShowS
class VarsToExps v e | v -> e, e -> v where
v2e :: v -> e
data Array t = Array
type JInt = Exp Int
type JString = Exp String
type JBool = Exp Bool
type JFloat = Exp Float
type JVoid = Exp ()
type JObject c = Exp c
type JArray t = Exp (Array t)
class IsExp e t | e -> t where
toExp :: e -> Exp t
class IsExp e String => IsJString e where
toJString :: e -> Exp String
class IsExp e Bool => IsJBool e where
toJBool :: e -> Exp Bool
class IsExp e Int => IsJInt e where
toJInt :: e -> Exp Int
class IsExp e Float => IsJFloat e where
toJFloat :: e -> Exp Float
val :: Var t -> Exp t
toBlock :: Stmt t -> Block t
deref :: IsDeref d => String -> d -> Exp t
derefVar :: IsDeref d => String -> d -> Var a
propertyVar :: (IsDeref d, JShow p) => Exp p -> d -> Var a
call :: Args e t => Exp (t -> r) -> e -> Exp r
methodCall :: (Args e t1, IsDeref d) => String -> e -> d -> Exp t2
voidMethodCall :: (Args e t1, IsDeref a) => String -> e -> a -> Stmt ()
methodCallNoArgs :: IsDeref d => String -> d -> Exp t
voidMethodCallNoArgs :: IsDeref d => String -> d -> Stmt ()
renderBlock :: Block r -> String
Primitive type classes.
class JType t Source
JavaScript types
Fundamental data types.
data Exp t whereSource
Constructors
JInt :: Int -> Exp Int
JFloat :: Float -> Exp Float
JBool :: Bool -> Exp Bool
JString :: String -> Exp String
JRec :: Exp a -> Exp b -> Exp (Rec a b)
JFst :: Exp (Rec a b) -> Exp a
JSnd :: Exp (Rec a b) -> Exp b
JConst :: String -> Exp t
JAssign :: Var t -> Exp t -> Exp t
JAssignWith :: Var t -> AssignOp t -> Exp t -> Exp t
JNeg :: Exp t -> Exp t
JNot :: Exp Bool -> Exp Bool
JBinOp :: Exp t -> BinOp t r -> Exp t -> Exp r
JIncrement :: Num t => PostPre -> Var t -> Exp t
JDecrement :: Num t => PostPre -> Var t -> Exp t
JIfOp :: Exp Bool -> Exp t -> Exp t -> Exp t
JCall :: Args e t => Exp (t -> r) -> e -> Exp r
JNew :: (Args e t, HasConstructor c e t) => c -> e -> Exp c
JDelete :: Var a -> Exp Bool
JDeref :: IsDeref d => d -> String -> Exp t
JFunction :: FormalParams a t => Maybe String -> a -> Block r -> Exp (t -> r)
JThis :: IsClass c => Exp c
JBlock :: Block () -> Exp ()
JNull :: IsNullable t => Exp t
JCastObject :: (IsClass c1, IsClass c2) => Exp c1 -> Exp c2
JValueOf :: Var t -> Exp t
JIsImpl :: (IsClass c, IsFeature f) => Exp c -> f -> Exp Bool
JShow :: JShow t => Exp t -> Exp String
data Rec a b Source
data Var t whereSource
Constructors
JVar :: String -> Var a
JParam :: String -> Var a
JMember :: String -> Var a
JDerefVar :: IsDeref d => d -> String -> Var a
JArrayIndex :: Exp (Array t) -> Exp Int -> Var t
JPropertyVar :: (IsDeref d, JShow p) => d -> Exp p -> Var a
data Stmt t whereSource
Constructors
VarDecl :: String -> Stmt ()
VarDeclAssign :: String -> Exp t -> Stmt ()
VarAssign :: String -> Exp t -> Stmt ()
ExpStmt :: Exp t -> Stmt ()
While :: Exp Bool -> Block () -> Stmt ()
DoWhile :: Block () -> Exp Bool -> Stmt ()
For :: Stmt t1 -> Exp Bool -> Exp t2 -> Block () -> Stmt ()
ForIn :: IsDeref d => Var String -> d -> Block () -> Stmt ()
Break :: Stmt ()
Continue :: Stmt ()
Return :: Exp t -> Stmt t
If :: Exp Bool -> Block t -> Elses t -> Stmt ()
data Block t whereSource
Constructors
EmptyBlock :: Block ()
Sequence :: Block () -> Stmt t -> Block t
Data types and classes for object representation.
class Show c => IsClass c Source
class (IsClass c, Args e t) => HasConstructor c e t Source
Class for binding objects with constructors. E.g. o = new Date();
class Show r => IsDeref r Source
Class for derefable data types, used to allow the creation of dereferencing objects. Examples: Math.random() or document.write()
Misc
data AssignOp t whereSource
Assign Operator
Constructors
PlusAssign :: Num t => AssignOp t
MinusAssign :: Num t => AssignOp t
TimesAssign :: Num t => AssignOp t
DivAssign :: AssignOp Float
ModAssign :: AssignOp Int
AndAssign :: AssignOp Bool
OrAssign :: AssignOp Bool
data BinOp t r whereSource
Binary Operator
Constructors
Plus :: PlusOpType t => BinOp t t
Minus :: Num t => BinOp t t
Times :: Num t => BinOp t t
Div :: Num t => BinOp t t
Mod :: BinOp Int Int
And :: BinOp Bool Bool
Or :: BinOp Bool Bool
Equals :: BinOp t Bool
NotEquals :: BinOp t Bool
GThan :: Num t => BinOp t Bool
LThan :: Num t => BinOp t Bool
GEThan :: Num t => BinOp t Bool
LEThan :: Num t => BinOp t Bool
class PlusOpType a Source
Class for expression that may be plussed. Examples: 1 + 2, ha + skell.
data PostPre Source
Post or Pre prefix , i.e. --x or x++
Constructors
Pst
Pre
data Elses t whereSource
Constructors
Elseif :: Exp Bool -> Block t -> Elses t -> Elses t
Else :: Block t -> Elses t
NoElse :: Elses ()
class IsNullable a Source
Allows values to be compared to JNull. E.g. for checking that an object is instantiated or is accessible.
class Show a => IsFeature a Source
Class for representing JavaScript features, e.g. names of objects or functions. Example: window hasFeature alert
class JShow a whereSource
Class that represents showable types
Methods
jshow :: a -> JStringSource
Types for functions and parameters.
class Show e => Args e t | e -> tSource
Args represents types that can be passed as arguments to JavaScript functions.
class ParamType t Source
Class for parameter types to JavaScript functions
class (Show a, ParamType t) => FormalParams a t | a -> t whereSource
JFormal params represents parameters passed to a function along with their corresponding types.
Methods
mkFParams :: forall b. (a -> b) -> Int -> aSource
showsFParams :: a -> ShowSSource
class VarsToExps v e | v -> e, e -> v whereSource
Methods
v2e :: v -> eSource
Array representation.
data Array t Source
Array representation
Constructors
Array
Type synonyms.
type JInt = Exp IntSource
type JString = Exp StringSource
type JBool = Exp BoolSource
type JFloat = Exp FloatSource
type JVoid = Exp ()Source
type JObject c = Exp cSource
type JArray t = Exp (Array t)Source
Type classes for expression representation.
class IsExp e t | e -> t whereSource
Class for representing expressions. First parameter is the expression, second a TBool for variable or constant. Third parameter represents the type.
Methods
toExp :: e -> Exp tSource
class IsExp e String => IsJString e whereSource
Class for JString expressions
Methods
toJString :: e -> Exp StringSource
class IsExp e Bool => IsJBool e whereSource
Class for JBool expressions
Methods
toJBool :: e -> Exp BoolSource
class IsExp e Int => IsJInt e whereSource
Class for JInt expressions
Methods
toJInt :: e -> Exp IntSource
class IsExp e Float => IsJFloat e whereSource
Class for JFloat expressions
Methods
toJFloat :: e -> Exp FloatSource
Helper functions
val :: Var t -> Exp tSource
Get the value of a variable.
toBlock :: Stmt t -> Block tSource
Generates a Block from a Stmt.
deref :: IsDeref d => String -> d -> Exp tSource
derefVar :: IsDeref d => String -> d -> Var aSource
propertyVar :: (IsDeref d, JShow p) => Exp p -> d -> Var aSource
call :: Args e t => Exp (t -> r) -> e -> Exp rSource
methodCall :: (Args e t1, IsDeref d) => String -> e -> d -> Exp t2Source
voidMethodCall :: (Args e t1, IsDeref a) => String -> e -> a -> Stmt ()Source
methodCallNoArgs :: IsDeref d => String -> d -> Exp tSource
voidMethodCallNoArgs :: IsDeref d => String -> d -> Stmt ()Source
Render function producing multi-line pretty-printed JavaScript code.
renderBlock :: Block r -> StringSource
Produced by Haddock version 2.6.1