Safe Haskell | None |
---|---|
Language | Haskell2010 |
Language.ECMAScript3.Syntax
Contents
Description
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
- data Prop a
- data UnaryAssignOp
- 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
- isReservedWord :: String -> Bool
- isValidIdStart :: Char -> Bool
- isValidIdPart :: Char -> 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
- isIter :: EnclosingStatement -> Bool
- isIterSwitch :: EnclosingStatement -> Bool
Documentation
data JavaScript a #
Instances
Functor 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) # | |
Default a => Default (JavaScript a) # | |
Data a => Fixable (JavaScript a) # | |
Pretty (JavaScript a) # | |
unJavaScript :: JavaScript a -> [Statement a] #
extracts statements from a JavaScript type
Statements, spec 12.
Constructors
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 #
Returns True
if the statement is an IterationStatement
according to spec 12.6.
data CaseClause a #
Case clauses, spec 12.11
Constructors
CaseClause a (Expression a) [Statement a] | case e: stmts; |
CaseDefault a [Statement a] | default: stmts; |
Instances
Functor 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) # | |
Data a => Fixable (CaseClause a) # | |
Pretty (CaseClause a) # | |
data CatchClause a #
Catch clause, spec 12.14
Constructors
CatchClause a (Id a) (Statement a) | catch (x) {...} |
Instances
Functor 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) # | |
Data a => Fixable (CatchClause a) # | |
Pretty (CatchClause a) # | |
for initializer, spec 12.6
Constructors
NoInit | empty |
VarInit [VarDecl a] | var x, y=42 |
ExprInit (Expression a) | expr |
for..in initializer, spec 12.6
A variable declaration, spec 12.2
Constructors
VarDecl a (Id a) (Maybe (Expression a)) | var x = e; |
data Expression a #
Expressions, see spec 11
Constructors
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] |
|
Instances
Functor 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) # | |
Data a => Fixable (Expression a) # | |
Pretty (Expression a) # | |
Infix operators: see spec 11.5-11.11
Constructors
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
Constructors
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)
Constructors
PrefixLNot | ! |
PrefixBNot | ~ |
PrefixPlus | + |
PrefixMinus | - |
PrefixTypeof | typeof |
PrefixVoid | void |
PrefixDelete | delete |
Property names in an object initializer: see spec 11.1.5
data UnaryAssignOp #
Unary assignment operators: see spec 11.3, 11.4.4, 11.4.5
Constructors
PrefixInc | ++x |
PrefixDec | --x |
PostfixInc | x++ |
PostfixDec | x-- |
Instances
Left-hand side expressions: see spec 11.2
Constructors
LVar a String | variable reference, |
LDot a (Expression a) String | foo.bar |
LBracket a (Expression a) (Expression a) | foo[bar] |
isValid :: forall a. (Data a, Typeable a) => JavaScript a -> Bool #
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 -> Bool #
Checks if an identifier name is valid according to the spec
isValidIdentifierName :: String -> Bool #
Checks if the String
represents a valid identifier name
isReservedWord :: String -> Bool #
Checks if a string is in the list of reserved ECMAScript words
isValidIdStart :: Char -> Bool #
Checks if a character is valid at the start of an identifier
isValidIdPart :: Char -> Bool #
Checks if a character is valid in an identifier part
data EnclosingStatement #
Constructors
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, |
Instances
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 #
isIter :: EnclosingStatement -> Bool #
isIterSwitch :: EnclosingStatement -> Bool #