HJavaScript-0.4.7: HJavaScript is an abstract syntax for a typed subset of JavaScript.

Stabilityexperimental
MaintainerJoel Bjornson joel.bjornson@gmail.com Niklas Broberg nibro@cs.chalmers.se

Language.HJavaScript.Syntax

Contents

Description

 

Synopsis

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

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 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

Render function producing multi-line pretty-printed JavaScript code.