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 Source #
Instances
Functor JavaScript Source # | |
Foldable JavaScript Source # | |
Traversable JavaScript Source # | |
Eq a => Eq (JavaScript a) Source # | |
Data a => Data (JavaScript a) Source # | |
Ord a => Ord (JavaScript a) Source # | |
Show a => Show (JavaScript a) Source # | |
Default a => Default (JavaScript a) Source # | |
Data a => Fixable (JavaScript a) Source # | |
Pretty (JavaScript a) Source # | |
unJavaScript :: JavaScript a -> [Statement a] Source #
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] |
|
Instances
Functor Statement Source # | |
Foldable Statement Source # | |
Traversable Statement Source # | |
HasAnnotation Statement Source # | |
Eq a => Eq (Statement a) Source # | |
Data a => Data (Statement a) Source # | |
Ord a => Ord (Statement a) Source # | |
Show a => Show (Statement a) Source # | |
Data a => Fixable (Statement a) Source # | |
Pretty [Statement a] Source # | |
Pretty (Statement a) Source # | |
isIterationStmt :: Statement a -> Bool Source #
Returns True
if the statement is an IterationStatement
according to spec 12.6.
data CaseClause a Source #
Case clauses, spec 12.11
Constructors
CaseClause a (Expression a) [Statement a] | case e: stmts; |
CaseDefault a [Statement a] | default: stmts; |
Instances
Functor CaseClause Source # | |
Foldable CaseClause Source # | |
Traversable CaseClause Source # | |
HasAnnotation CaseClause Source # | |
Eq a => Eq (CaseClause a) Source # | |
Data a => Data (CaseClause a) Source # | |
Ord a => Ord (CaseClause a) Source # | |
Show a => Show (CaseClause a) Source # | |
Data a => Fixable (CaseClause a) Source # | |
Pretty (CaseClause a) Source # | |
data CatchClause a Source #
Catch clause, spec 12.14
Constructors
CatchClause a (Id a) (Statement a) | catch (x) {...} |
Instances
Functor CatchClause Source # | |
Foldable CatchClause Source # | |
Traversable CatchClause Source # | |
HasAnnotation CatchClause Source # | |
Eq a => Eq (CatchClause a) Source # | |
Data a => Data (CatchClause a) Source # | |
Ord a => Ord (CatchClause a) Source # | |
Show a => Show (CatchClause a) Source # | |
Data a => Fixable (CatchClause a) Source # | |
Pretty (CatchClause a) Source # | |
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
Instances
Functor ForInInit Source # | |
Foldable ForInInit Source # | |
Traversable ForInInit Source # | |
Eq a => Eq (ForInInit a) Source # | |
Data a => Data (ForInInit a) Source # | |
Ord a => Ord (ForInInit a) Source # | |
Show a => Show (ForInInit a) Source # | |
Data a => Fixable (ForInInit a) Source # | |
Pretty (ForInInit a) Source # | |
A variable declaration, spec 12.2
Constructors
VarDecl a (Id a) (Maybe (Expression a)) | var x = e; |
Instances
Functor VarDecl Source # | |
Foldable VarDecl Source # | |
Traversable VarDecl Source # | |
HasAnnotation VarDecl Source # | |
Eq a => Eq (VarDecl a) Source # | |
Data a => Data (VarDecl a) Source # | |
Ord a => Ord (VarDecl a) Source # | |
Show a => Show (VarDecl a) Source # | |
Data a => Fixable (VarDecl a) Source # | |
Pretty (VarDecl a) Source # | |
data Expression a Source #
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 Source # | |
Foldable Expression Source # | |
Traversable Expression Source # | |
HasAnnotation Expression Source # | |
Eq a => Eq (Expression a) Source # | |
Data a => Data (Expression a) Source # | |
Ord a => Ord (Expression a) Source # | |
Show a => Show (Expression a) Source # | |
Data a => Fixable (Expression a) Source # | |
Pretty (Expression a) Source # | |
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 Source #
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] |
Instances
Functor LValue Source # | |
Foldable LValue Source # | |
Traversable LValue Source # | |
HasAnnotation LValue Source # | |
Eq a => Eq (LValue a) Source # | |
Data a => Data (LValue a) Source # | |
Ord a => Ord (LValue a) Source # | |
Show a => Show (LValue a) Source # | |
Data a => Fixable (LValue a) Source # | |
Pretty (LValue a) Source # | |
isValid :: forall a. (Data a, Typeable a) => JavaScript a -> Bool Source #
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 Source #
Checks if an identifier name is valid according to the spec
isValidIdentifierName :: String -> Bool Source #
Checks if the String
represents a valid identifier name
isReservedWord :: String -> Bool Source #
Checks if a string is in the list of reserved ECMAScript words
isValidIdStart :: Char -> Bool Source #
Checks if a character is valid at the start of an identifier
isValidIdPart :: Char -> Bool Source #
Checks if a character is valid in an identifier part
data EnclosingStatement Source #
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 Source #
pushEnclosing :: Monad m => ([Label] -> EnclosingStatement) -> StateT ([Label], [EnclosingStatement]) m a -> StateT ([Label], [EnclosingStatement]) m a Source #
isIter :: EnclosingStatement -> Bool Source #