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

Copyright(c) Joel Bjornson 2008
LicenseBSD-style
MaintainerJoel Bjornson joel.bjornson@gmail.com Niklas Broberg nibro@cs.chalmers.se
Stabilityexperimental
Safe HaskellNone
LanguageHaskell98

Language.HJavaScript.Syntax

Contents

Description

 

Synopsis

Primitive type classes.

class JType t Source

JavaScript types

Instances

JType Bool 
JType Float 
JType Int 
JType String 
JType () 
IsClass c => JType c 
(Show t1, JType t1, Show t2, JType t2) => JType (t1 -> t2) 

Fundamental data types.

data Exp t where Source

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 

Instances

Show (Exp t)

Show for Exp

IsClass c => IsDeref (Exp c) 
JShow a => JShow (Exp a) 
IsExp (Exp t) t 
Args (Exp t) t 
VarsToExps (Var t) (Exp t) 
VarsToExps (Var t1, Var t2) (Exp t1, Exp t2) 
Args (Exp t1, Exp t2) (t1, t2) 
VarsToExps (Var t1, Var t2, Var t3) (Exp t1, Exp t2, Exp t3) 
Args (Exp t1, Exp t2, Exp t3) (t1, t2, t3) 
VarsToExps (Var t1, Var t2, Var t3, Var t4) (Exp t1, Exp t2, Exp t3, Exp t4) 
Args (Exp t1, Exp t2, Exp t3, Exp t4) (t1, t2, t3, t4) 
VarsToExps (Var t1, Var t2, Var t3, Var t4, Var t5) (Exp t1, Exp t2, Exp t3, Exp t4, Exp t5) 
Args (Exp t1, Exp t2, Exp t3, Exp t4, Exp t5) (t1, t2, t3, t4, t5) 

data Rec a b Source

data Var t where Source

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 

Instances

Show (Var t) 
ParamType t => FormalParams (Var t) t 
VarsToExps (Var t) (Exp t) 
VarsToExps (Var t1, Var t2) (Exp t1, Exp t2) 
ParamType (t1, t2) => FormalParams (Var t1, Var t2) (t1, t2) 
VarsToExps (Var t1, Var t2, Var t3) (Exp t1, Exp t2, Exp t3) 
ParamType (t1, t2, t3) => FormalParams (Var t1, Var t2, Var t3) (t1, t2, t3) 
VarsToExps (Var t1, Var t2, Var t3, Var t4) (Exp t1, Exp t2, Exp t3, Exp t4) 
ParamType (t1, t2, t3, t4) => FormalParams (Var t1, Var t2, Var t3, Var t4) (t1, t2, t3, t4) 
VarsToExps (Var t1, Var t2, Var t3, Var t4, Var t5) (Exp t1, Exp t2, Exp t3, Exp t4, Exp t5) 
ParamType (t1, t2, t3, t4, t5) => FormalParams (Var t1, Var t2, Var t3, Var t4, Var t5) (t1, t2, t3, t4, t5) 

data Stmt t where Source

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

Instances

Show (Stmt t) 

data Block t where Source

Constructors

EmptyBlock :: Block () 
Sequence :: Block () -> Stmt t -> Block t 

Instances

Show (Block t) 

Data types and classes for object representation.

class Show c => IsClass c Source

Instances

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

Instances

IsClass c => IsDeref c 
IsClass c => IsDeref (Exp c) 

Misc

data AssignOp t where Source

Assign Operator

Instances

data BinOp t r where Source

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 

Instances

Show (BinOp t r) 

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 

Instances

data Elses t where Source

Constructors

Elseif :: Exp Bool -> Block t -> Elses t -> Elses t 
Else :: Block t -> Elses t 
NoElse :: Elses () 

Instances

Show (Elses t) 

class IsNullable a Source

Allows values to be compared to JNull. E.g. for checking that an object is instantiated or is accessible.

Instances

IsNullable String

All JString values along with all objects and all functions can be null.

IsClass c => IsNullable c 
IsNullable (t -> r) 

class Show a => IsFeature a Source

Class for representing JavaScript "features", e.g. names of objects or functions. Example: window hasFeature "alert"

Minimal complete definition

showsFeature

Instances

IsFeature String

Any string value can be a feature.

IsClass c => IsFeature c 

class JShow a where Source

Class that represents showable types

Methods

jshow :: a -> JString Source

Instances

Types for functions and parameters.

class Show e => Args e t | e -> t Source

Args represents types that can be passed as arguments to JavaScript functions.

Minimal complete definition

showsArgs

Instances

Args () () 
Args (Exp t) t 
Args (Exp t1, Exp t2) (t1, t2) 
Args (Exp t1, Exp t2, Exp t3) (t1, t2, t3) 
Args (Exp t1, Exp t2, Exp t3, Exp t4) (t1, t2, t3, t4) 
Args (Exp t1, Exp t2, Exp t3, Exp t4, Exp t5) (t1, t2, t3, t4, t5) 

class ParamType t Source

Class for parameter types to JavaScript functions

Instances

ParamType ()

Instanses for tuples,triples etc..

JType t => ParamType t 
(JType t1, JType t2) => ParamType (t1, t2) 
(JType t1, JType t2, JType t3) => ParamType (t1, t2, t3) 
(JType t1, JType t2, JType t3, JType t4) => ParamType (t1, t2, t3, t4) 
(JType t1, JType t2, JType t3, JType t4, JType t5) => ParamType (t1, t2, t3, t4, t5) 

class (Show a, ParamType t) => FormalParams a t | a -> t where Source

JFormal params represents parameters passed to a function along with their corresponding types.

Methods

mkFParams :: forall b. (a -> b) -> Int -> a Source

showsFParams :: a -> ShowS Source

Instances

FormalParams () () 
ParamType t => FormalParams (Var t) t 
ParamType (t1, t2) => FormalParams (Var t1, Var t2) (t1, t2) 
ParamType (t1, t2, t3) => FormalParams (Var t1, Var t2, Var t3) (t1, t2, t3) 
ParamType (t1, t2, t3, t4) => FormalParams (Var t1, Var t2, Var t3, Var t4) (t1, t2, t3, t4) 
ParamType (t1, t2, t3, t4, t5) => FormalParams (Var t1, Var t2, Var t3, Var t4, Var t5) (t1, t2, t3, t4, t5) 

class VarsToExps v e | v -> e, e -> v where Source

Methods

v2e :: v -> e Source

Instances

VarsToExps () () 
VarsToExps (Var t) (Exp t) 
VarsToExps (Var t1, Var t2) (Exp t1, Exp t2) 
VarsToExps (Var t1, Var t2, Var t3) (Exp t1, Exp t2, Exp t3) 
VarsToExps (Var t1, Var t2, Var t3, Var t4) (Exp t1, Exp t2, Exp t3, Exp t4) 
VarsToExps (Var t1, Var t2, Var t3, Var t4, Var t5) (Exp t1, Exp t2, Exp t3, Exp t4, Exp t5) 

Array representation.

data Array t Source

Array representation

Constructors

Array 

Instances

Show (Array t) 
IsClass (Array t) 

Type synonyms.

type JVoid = Exp () Source

type JObject c = Exp c Source

type JArray t = Exp (Array t) Source

Type classes for expression representation.

class IsExp e t | e -> t where Source

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

class IsExp e String => IsJString e where Source

Class for JString expressions

Minimal complete definition

Nothing

Methods

toJString :: e -> Exp String Source

Instances

class IsExp e Bool => IsJBool e where Source

Class for JBool expressions

Minimal complete definition

Nothing

Methods

toJBool :: e -> Exp Bool Source

Instances

IsExp e Bool => IsJBool e 

class IsExp e Int => IsJInt e where Source

Class for JInt expressions

Minimal complete definition

Nothing

Methods

toJInt :: e -> Exp Int Source

Instances

IsExp e Int => IsJInt e 

class IsExp e Float => IsJFloat e where Source

Class for JFloat expressions

Minimal complete definition

Nothing

Methods

toJFloat :: e -> Exp Float Source

Instances

Helper functions

val :: Var t -> Exp t Source

Get the value of a variable.

toBlock :: Stmt t -> Block t Source

Generates a Block from a Stmt.

deref :: IsDeref d => String -> d -> Exp t Source

derefVar :: IsDeref d => String -> d -> Var a Source

propertyVar :: (IsDeref d, JShow p) => Exp p -> d -> Var a Source

call :: Args e t => Exp (t -> r) -> e -> Exp r Source

methodCall :: (Args e t1, IsDeref d) => String -> e -> d -> Exp t2 Source

voidMethodCall :: (Args e t1, IsDeref a) => String -> e -> a -> Stmt () Source

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