Safe Haskell | None |
---|
ECMAScript 3 syntax. Spec refers to the ECMA-262 specification, 3rd edition.
- data JavaScript a = Script a [Statement a]
- unJavaScript :: JavaScript a -> [Statement a]
- data Statement a
- = BlockStmt a [Statement a]
- | EmptyStmt a
- | ExprStmt a (Expression a)
- | IfStmt a (Expression a) (Statement a) (Statement a)
- | IfSingleStmt a (Expression a) (Statement a)
- | SwitchStmt a (Expression a) [CaseClause a]
- | WhileStmt a (Expression a) (Statement a)
- | DoWhileStmt a (Statement a) (Expression a)
- | BreakStmt a (Maybe (Id a))
- | ContinueStmt a (Maybe (Id a))
- | LabelledStmt a (Id a) (Statement a)
- | ForInStmt a (ForInInit a) (Expression a) (Statement a)
- | ForStmt a (ForInit a) (Maybe (Expression a)) (Maybe (Expression a)) (Statement a)
- | TryStmt a (Statement a) (Maybe (CatchClause a)) (Maybe (Statement a))
- | ThrowStmt a (Expression a)
- | ReturnStmt a (Maybe (Expression a))
- | WithStmt a (Expression a) (Statement a)
- | VarDeclStmt a [VarDecl a]
- | FunctionStmt a (Id a) [Id a] [Statement a]
- isIterationStmt :: Statement a -> Bool
- data CaseClause a
- = CaseClause a (Expression a) [Statement a]
- | CaseDefault a [Statement a]
- data CatchClause a = CatchClause a (Id a) (Statement a)
- data ForInit a
- = NoInit
- | VarInit [VarDecl a]
- | ExprInit (Expression a)
- data ForInInit a
- data VarDecl a = VarDecl a (Id a) (Maybe (Expression a))
- data Expression a
- = StringLit a String
- | RegexpLit a String Bool Bool
- | NumLit a Double
- | IntLit a Int
- | BoolLit a Bool
- | NullLit a
- | ArrayLit a [Expression a]
- | ObjectLit a [(Prop a, Expression a)]
- | ThisRef a
- | VarRef a (Id a)
- | DotRef a (Expression a) (Id a)
- | BracketRef a (Expression a) (Expression a)
- | NewExpr a (Expression a) [Expression a]
- | PrefixExpr a PrefixOp (Expression a)
- | UnaryAssignExpr a UnaryAssignOp (LValue a)
- | InfixExpr a InfixOp (Expression a) (Expression a)
- | CondExpr a (Expression a) (Expression a) (Expression a)
- | AssignExpr a AssignOp (LValue a) (Expression a)
- | ListExpr a [Expression a]
- | CallExpr a (Expression a) [Expression a]
- | FuncExpr a (Maybe (Id a)) [Id a] [Statement a]
- data InfixOp
- = OpLT
- | OpLEq
- | OpGT
- | OpGEq
- | OpIn
- | OpInstanceof
- | OpEq
- | OpNEq
- | OpStrictEq
- | OpStrictNEq
- | OpLAnd
- | OpLOr
- | OpMul
- | OpDiv
- | OpMod
- | OpSub
- | OpLShift
- | OpSpRShift
- | OpZfRShift
- | OpBAnd
- | OpBXor
- | OpBOr
- | OpAdd
- data AssignOp
- data Id a = Id a String
- unId :: Id a -> String
- data PrefixOp
- = PrefixLNot
- | PrefixBNot
- | PrefixPlus
- | PrefixMinus
- | PrefixTypeof
- | PrefixVoid
- | PrefixDelete
- data Prop a
- data UnaryAssignOp
- = PrefixInc
- | PrefixDec
- | PostfixInc
- | PostfixDec
- data LValue a
- = LVar a String
- | LDot a (Expression a) String
- | LBracket a (Expression a) (Expression a)
- data SourcePos
- isValid :: forall a. (Data a, Typeable a) => JavaScript a -> Bool
- isValidIdentifier :: Id a -> Bool
- isValidIdentifierName :: String -> Bool
- data EnclosingStatement
- = EnclosingIter [Label]
- | EnclosingSwitch [Label]
- | EnclosingOther [Label]
- pushLabel :: Monad m => Id b -> StateT ([Label], [EnclosingStatement]) m a -> StateT ([Label], [EnclosingStatement]) m a
- pushEnclosing :: Monad m => ([Label] -> EnclosingStatement) -> StateT ([Label], [EnclosingStatement]) m a -> StateT ([Label], [EnclosingStatement]) m a
- class HasLabelSet a where
- getLabelSet :: a -> [Label]
- setLabelSet :: [Label] -> a -> a
- isIter :: EnclosingStatement -> Bool
- isIterSwitch :: EnclosingStatement -> Bool
Documentation
data JavaScript a Source
Functor JavaScript | |
Typeable1 JavaScript | |
Foldable JavaScript | |
Traversable JavaScript | |
Eq a => Eq (JavaScript a) | |
Data a => Data (JavaScript a) | |
Ord a => Ord (JavaScript a) | |
Show a => Show (JavaScript a) | |
(Data a, Arbitrary a, Enumerable a) => Arbitrary (JavaScript a) | |
Default a => Default (JavaScript a) | |
Enumerable a0 => Enumerable (JavaScript a0) | |
Pretty (JavaScript a) | |
Data a => Fixable (JavaScript a) |
unJavaScript :: JavaScript a -> [Statement a]Source
extracts statements from a JavaScript type
Statements, spec 12.
BlockStmt a [Statement a] |
|
EmptyStmt a |
|
ExprStmt a (Expression a) |
|
IfStmt a (Expression a) (Statement a) (Statement a) |
|
IfSingleStmt a (Expression a) (Statement a) |
|
SwitchStmt a (Expression a) [CaseClause a] |
|
WhileStmt a (Expression a) (Statement a) |
|
DoWhileStmt a (Statement a) (Expression a) |
|
BreakStmt a (Maybe (Id a)) |
|
ContinueStmt a (Maybe (Id a)) |
|
LabelledStmt a (Id a) (Statement a) |
|
ForInStmt a (ForInInit a) (Expression a) (Statement a) |
|
ForStmt a (ForInit a) (Maybe (Expression a)) (Maybe (Expression a)) (Statement a) |
|
TryStmt a (Statement a) (Maybe (CatchClause a)) (Maybe (Statement a)) |
|
ThrowStmt a (Expression a) |
|
ReturnStmt a (Maybe (Expression a)) |
|
WithStmt a (Expression a) (Statement a) |
|
VarDeclStmt a [VarDecl a] |
|
FunctionStmt a (Id a) [Id a] [Statement a] |
|
Functor Statement | |
Typeable1 Statement | |
Foldable Statement | |
Traversable Statement | |
HasAnnotation Statement | |
Eq a => Eq (Statement a) | |
Data a => Data (Statement a) | |
Ord a => Ord (Statement a) | |
Show a => Show (Statement a) | |
(Enumerable a, Arbitrary a, Data a) => Arbitrary (Statement a) | |
Enumerable a0 => Enumerable (Statement a0) | |
Pretty [Statement a] | |
Pretty (Statement a) | |
Data a => Fixable (Statement a) |
isIterationStmt :: Statement a -> BoolSource
Returns True
if the statement is an IterationStatement
according to spec 12.6.
data CaseClause a Source
Case clauses, spec 12.11
CaseClause a (Expression a) [Statement a] | case e: stmts; |
CaseDefault a [Statement a] | default: stmts; |
Functor CaseClause | |
Typeable1 CaseClause | |
Foldable CaseClause | |
Traversable CaseClause | |
HasAnnotation CaseClause | |
Eq a => Eq (CaseClause a) | |
Data a => Data (CaseClause a) | |
Ord a => Ord (CaseClause a) | |
Show a => Show (CaseClause a) | |
(Enumerable a, Arbitrary a, Data a) => Arbitrary (CaseClause a) | |
Enumerable a0 => Enumerable (CaseClause a0) | |
Pretty (CaseClause a) | |
Data a => Fixable (CaseClause a) |
data CatchClause a Source
Catch clause, spec 12.14
CatchClause a (Id a) (Statement a) | catch (x) {...} |
Functor CatchClause | |
Typeable1 CatchClause | |
Foldable CatchClause | |
Traversable CatchClause | |
HasAnnotation CatchClause | |
Eq a => Eq (CatchClause a) | |
Data a => Data (CatchClause a) | |
Ord a => Ord (CatchClause a) | |
Show a => Show (CatchClause a) | |
(Enumerable a, Arbitrary a, Data a) => Arbitrary (CatchClause a) | |
Enumerable a0 => Enumerable (CatchClause a0) | |
Pretty (CatchClause a) | |
Data a => Fixable (CatchClause a) |
for initializer, spec 12.6
NoInit | empty |
VarInit [VarDecl a] | var x, y=42 |
ExprInit (Expression a) | expr |
Functor ForInit | |
Typeable1 ForInit | |
Foldable ForInit | |
Traversable ForInit | |
Eq a => Eq (ForInit a) | |
Data a => Data (ForInit a) | |
Ord a => Ord (ForInit a) | |
Show a => Show (ForInit a) | |
(Enumerable a, Arbitrary a, Data a) => Arbitrary (ForInit a) | |
Enumerable a0 => Enumerable (ForInit a0) | |
Pretty (ForInit a) | |
Data a => Fixable (ForInit a) |
for..in initializer, spec 12.6
Functor ForInInit | |
Typeable1 ForInInit | |
Foldable ForInInit | |
Traversable ForInInit | |
Eq a => Eq (ForInInit a) | |
Data a => Data (ForInInit a) | |
Ord a => Ord (ForInInit a) | |
Show a => Show (ForInInit a) | |
(Enumerable a, Arbitrary a, Data a) => Arbitrary (ForInInit a) | |
Enumerable a0 => Enumerable (ForInInit a0) | |
Pretty (ForInInit a) | |
Data a => Fixable (ForInInit a) |
A variable declaration, spec 12.2
VarDecl a (Id a) (Maybe (Expression a)) | var x = e; |
Functor VarDecl | |
Typeable1 VarDecl | |
Foldable VarDecl | |
Traversable VarDecl | |
HasAnnotation VarDecl | |
Eq a => Eq (VarDecl a) | |
Data a => Data (VarDecl a) | |
Ord a => Ord (VarDecl a) | |
Show a => Show (VarDecl a) | |
(Enumerable a, Arbitrary a, Data a) => Arbitrary (VarDecl a) | |
Enumerable a0 => Enumerable (VarDecl a0) | |
Pretty (VarDecl a) | |
Data a => Fixable (VarDecl a) |
data Expression a Source
Expressions, see spec 11
StringLit a String |
|
RegexpLit a String Bool Bool |
|
NumLit a Double |
|
IntLit a Int |
|
BoolLit a Bool |
|
NullLit a |
|
ArrayLit a [Expression a] |
|
ObjectLit a [(Prop a, Expression a)] |
|
ThisRef a |
|
VarRef a (Id a) |
|
DotRef a (Expression a) (Id a) |
|
BracketRef a (Expression a) (Expression a) |
|
NewExpr a (Expression a) [Expression a] |
|
PrefixExpr a PrefixOp (Expression a) |
|
UnaryAssignExpr a UnaryAssignOp (LValue a) |
|
InfixExpr a InfixOp (Expression a) (Expression a) |
|
CondExpr a (Expression a) (Expression a) (Expression a) |
|
AssignExpr a AssignOp (LValue a) (Expression a) |
|
ListExpr a [Expression a] |
|
CallExpr a (Expression a) [Expression a] |
|
FuncExpr a (Maybe (Id a)) [Id a] [Statement a] |
|
Functor Expression | |
Typeable1 Expression | |
Foldable Expression | |
Traversable Expression | |
HasAnnotation Expression | |
Eq a => Eq (Expression a) | |
Data a => Data (Expression a) | |
Ord a => Ord (Expression a) | |
Show a => Show (Expression a) | |
(Enumerable a, Arbitrary a, Data a) => Arbitrary (Expression a) | |
Enumerable a0 => Enumerable (Expression a0) | |
Pretty (Expression a) | |
Data a => Fixable (Expression a) |
Infix operators: see spec 11.5-11.11
OpLT | < |
OpLEq | <= |
OpGT | > |
OpGEq | >= |
OpIn | in |
OpInstanceof | instanceof |
OpEq | == |
OpNEq | != |
OpStrictEq | === |
OpStrictNEq | !=== |
OpLAnd | && |
OpLOr | || |
OpMul | * |
OpDiv | / |
OpMod | % |
OpSub | - |
OpLShift | << |
OpSpRShift | >> |
OpZfRShift | >>> |
OpBAnd | & |
OpBXor | ^ |
OpBOr | | |
OpAdd | + |
Assignment operators: see spec 11.13
OpAssign | simple assignment, |
OpAssignAdd | += |
OpAssignSub | -= |
OpAssignMul | *= |
OpAssignDiv | /= |
OpAssignMod | %= |
OpAssignLShift | <<= |
OpAssignSpRShift | >>= |
OpAssignZfRShift | >>>= |
OpAssignBAnd | &= |
OpAssignBXor | ^= |
OpAssignBOr | |= |
Prefix operators: see spec 11.4 (excluding 11.4.4, 11.4.5)
PrefixLNot | ! |
PrefixBNot | ~ |
PrefixPlus | + |
PrefixMinus | - |
PrefixTypeof | typeof |
PrefixVoid | void |
PrefixDelete | delete |
Property names in an object initializer: see spec 11.1.5
data UnaryAssignOp Source
Unary assignment operators: see spec 11.3, 11.4.4, 11.4.5
PrefixInc | ++x |
PrefixDec | --x |
PostfixInc | x++ |
PostfixDec | x-- |
Left-hand side expressions: see spec 11.2
LVar a String | variable reference, |
LDot a (Expression a) String | foo.bar |
LBracket a (Expression a) (Expression a) | foo[bar] |
Functor LValue | |
Typeable1 LValue | |
Foldable LValue | |
Traversable LValue | |
HasAnnotation LValue | |
Eq a => Eq (LValue a) | |
Data a => Data (LValue a) | |
Ord a => Ord (LValue a) | |
Show a => Show (LValue a) | |
(Data a, Enumerable a, Arbitrary a) => Arbitrary (LValue a) | |
Enumerable a0 => Enumerable (LValue a0) | |
Pretty (LValue a) | |
Data a => Fixable (LValue a) |
data SourcePos
isValid :: forall a. (Data a, Typeable a) => JavaScript a -> BoolSource
The ECMAScript standard defines certain syntactic restrictions on
programs (or, more precisely, statements) that aren't easily
enforced in the AST datatype. These restrictions have to do with
labeled statements and break/continue statement, as well as
identifier names. Thus, it is possible to manually generate AST's
that correspond to syntactically incorrect programs. Use this
predicate to check if an JavaScript
AST corresponds to a
syntactically correct ECMAScript program.
isValidIdentifier :: Id a -> BoolSource
Checks if an identifier name is valid according to the spec
data EnclosingStatement Source
EnclosingIter [Label] | The enclosing statement is an iteration statement |
EnclosingSwitch [Label] | The enclosing statement is a switch statement |
EnclosingOther [Label] | The enclosing statement is some other
statement. Note, |
pushLabel :: Monad m => Id b -> StateT ([Label], [EnclosingStatement]) m a -> StateT ([Label], [EnclosingStatement]) m aSource
pushEnclosing :: Monad m => ([Label] -> EnclosingStatement) -> StateT ([Label], [EnclosingStatement]) m a -> StateT ([Label], [EnclosingStatement]) m aSource
class HasLabelSet a whereSource
getLabelSet :: a -> [Label]Source
setLabelSet :: [Label] -> a -> aSource