Safe Haskell | None |
---|---|
Language | Haskell2010 |
Language.ECMAScript3.Syntax
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
- getLabelSet :: a -> [Label]
- setLabelSet :: [Label] -> a -> a
- isIter :: EnclosingStatement -> Bool
- isIterSwitch :: EnclosingStatement -> Bool
Documentation
data JavaScript a Source
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) | |
(Data a, Arbitrary a, Enumerable a) => Arbitrary (JavaScript a) | |
Default a => Default (JavaScript a) | |
Enumerable a0 => Enumerable (JavaScript a) | |
Pretty (JavaScript a) | |
Data a => Fixable (JavaScript a) | |
Typeable (* -> *) JavaScript |
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 | |
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 a) | |
Pretty [Statement a] | |
Pretty (Statement a) | |
Data a => Fixable (Statement a) | |
Typeable (* -> *) Statement |
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 | |
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 a) | |
Pretty (CaseClause a) | |
Data a => Fixable (CaseClause a) | |
Typeable (* -> *) CaseClause |
data CatchClause a Source
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) | |
(Enumerable a, Arbitrary a, Data a) => Arbitrary (CatchClause a) | |
Enumerable a0 => Enumerable (CatchClause a) | |
Pretty (CatchClause a) | |
Data a => Fixable (CatchClause a) | |
Typeable (* -> *) CatchClause |
for initializer, spec 12.6
Constructors
NoInit | empty |
VarInit [VarDecl a] | var x, y=42 |
ExprInit (Expression a) | expr |
Instances
Functor 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 a) | |
Pretty (ForInit a) | |
Data a => Fixable (ForInit a) | |
Typeable (* -> *) ForInit |
for..in initializer, spec 12.6
Instances
Functor 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 a) | |
Pretty (ForInInit a) | |
Data a => Fixable (ForInInit a) | |
Typeable (* -> *) ForInInit |
A variable declaration, spec 12.2
Constructors
VarDecl a (Id a) (Maybe (Expression a)) | var x = e; |
Instances
Functor 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 a) | |
Pretty (VarDecl a) | |
Data a => Fixable (VarDecl a) | |
Typeable (* -> *) VarDecl |
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 | |
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) | |
Default a => IsString (Expression a) | |
(Enumerable a, Arbitrary a, Data a) => Arbitrary (Expression a) | |
Enumerable a0 => Enumerable (Expression a) | |
Pretty (Expression a) | |
Data a => Fixable (Expression a) | |
Typeable (* -> *) Expression |
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 | |= |
Instances
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
Constructors
PropId a (Id a) | property name is an identifier, |
PropString a String | property name is a string, |
PropNum a Integer | property name is an integer, |
Instances
Functor Prop | |
Foldable Prop | |
Traversable Prop | |
HasAnnotation Prop | |
Eq a => Eq (Prop a) | |
Data a => Data (Prop a) | |
Ord a => Ord (Prop a) | |
Show a => Show (Prop a) | |
Default a => IsString (Prop a) | |
(Enumerable a, Arbitrary a) => Arbitrary (Prop a) | |
Enumerable a0 => Enumerable (Prop a) | |
Pretty (Prop a) | |
Data a => Fixable (Prop a) | |
Typeable (* -> *) Prop |
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-- |
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 | |
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) | |
Default a => IsString (LValue a) | |
(Data a, Enumerable a, Arbitrary a) => Arbitrary (LValue a) | |
Enumerable a0 => Enumerable (LValue a) | |
Pretty (LValue a) | |
Data a => Fixable (LValue a) | |
Typeable (* -> *) LValue |
data SourcePos :: *
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, |
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
class HasLabelSet a where Source
Instances
isIter :: EnclosingStatement -> Bool Source