language-ecmascript-0.17.0.1: JavaScript parser and pretty-printer library

Safe HaskellNone
LanguageHaskell2010

Language.ECMAScript3.Syntax

Description

ECMAScript 3 syntax. Spec refers to the ECMA-262 specification, 3rd edition.

Synopsis

Documentation

data JavaScript a Source

Constructors

Script a [Statement a]

A script in <script> ... </script> tags.

unJavaScript :: JavaScript a -> [Statement a] Source

extracts statements from a JavaScript type

data Statement a Source

Statements, spec 12.

Constructors

BlockStmt a [Statement a]

{stmts}, spec 12.1

EmptyStmt a

;, spec 12.3

ExprStmt a (Expression a)

expr;, spec 12.4

IfStmt a (Expression a) (Statement a) (Statement a)

if (e) stmt, spec 12.5

IfSingleStmt a (Expression a) (Statement a)

if (e) stmt1 else stmt2, spec 12.5

SwitchStmt a (Expression a) [CaseClause a]

switch (e) clauses, spec 12.11

WhileStmt a (Expression a) (Statement a)

while (e) do stmt, spec 12.6

DoWhileStmt a (Statement a) (Expression a)

do stmt while (e);, spec 12.6

BreakStmt a (Maybe (Id a))

break lab;, spec 12.8

ContinueStmt a (Maybe (Id a))

continue lab;, spec 12.7

LabelledStmt a (Id a) (Statement a)

lab: stmt, spec 12.12

ForInStmt a (ForInInit a) (Expression a) (Statement a)

for (x in o) stmt, spec 12.6

ForStmt a (ForInit a) (Maybe (Expression a)) (Maybe (Expression a)) (Statement a)

ForStmt a init test increment body, for (init; test, increment) body, spec 12.6

TryStmt a (Statement a) (Maybe (CatchClause a)) (Maybe (Statement a))

try stmt catch(x) stmt finally stmt, spec 12.14

ThrowStmt a (Expression a)

throw expr;, spec 12.13

ReturnStmt a (Maybe (Expression a))

return expr;, spec 12.9

WithStmt a (Expression a) (Statement a)

with (o) stmt, spec 12.10

VarDeclStmt a [VarDecl a]

var x, y=42;, spec 12.2

FunctionStmt a (Id a) [Id a] [Statement a]

function f(x, y, z) {...}, spec 13

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;

data ForInit a Source

for initializer, spec 12.6

Constructors

NoInit

empty

VarInit [VarDecl a]
var x, y=42
ExprInit (Expression a)
expr

data ForInInit a Source

for..in initializer, spec 12.6

Constructors

ForInVar (Id a)
var x
ForInLVal (LValue a)

foo.baz, foo[bar], z

data VarDecl a Source

A variable declaration, spec 12.2

Constructors

VarDecl a (Id a) (Maybe (Expression a))
var x = e;

data Expression a Source

Expressions, see spec 11

Constructors

StringLit a String

"foo", spec 11.1.3, 7.8

RegexpLit a String Bool Bool

RegexpLit a regexp global? case_insensitive? -- regular expression, see spec 11.1.3, 7.8

NumLit a Double

41.99999, spec 11.1.3, 7.8

IntLit a Int

42, spec 11.1.3, 7.8

BoolLit a Bool

true, spec 11.1.3, 7.8

NullLit a

null, spec 11.1.3, 7.8

ArrayLit a [Expression a]

[1,2,3], spec 11.1.4

ObjectLit a [(Prop a, Expression a)]

{foo:"bar", baz: 42}, spec 11.1.5

ThisRef a

this, spec 11.1.1

VarRef a (Id a)

foo, spec 11.1.2

DotRef a (Expression a) (Id a)

foo.bar, spec 11.2.1

BracketRef a (Expression a) (Expression a)

foo[bar, spec 11.2.1

NewExpr a (Expression a) [Expression a]

new foo(bar), spec 11.2.2

PrefixExpr a PrefixOp (Expression a)

@e, spec 11.4 (excluding 11.4.4, 111.4.5)

UnaryAssignExpr a UnaryAssignOp (LValue a)

++x, x-- etc., spec 11.3, 11.4.4, 11.4.5

InfixExpr a InfixOp (Expression a) (Expression a)

e1@e2, spec 11.5, 11.6, 11.7, 11.8, 11.9, 11.10, 11.11

CondExpr a (Expression a) (Expression a) (Expression a)

e1 ? e2 : e3, spec 11.12

AssignExpr a AssignOp (LValue a) (Expression a)

e1 @=e2, spec 11.13

ListExpr a [Expression a]

e1, e2, spec 11.14

CallExpr a (Expression a) [Expression a]

f(x,y,z), spec 11.2.3 funcexprs are optionally named

FuncExpr a (Maybe (Id a)) [Id a] [Statement a]

function f (x,y,z) {...}, spec 11.2.5, 13

data Id a Source

Constructors

Id a String 

Instances

Functor Id 
Foldable Id 
Traversable Id 
HasAnnotation Id 
Eq a => Eq (Id a) 
Data a => Data (Id a) 
Ord a => Ord (Id a) 
Show a => Show (Id a) 
Default a => IsString (Id a) 
(Enumerable a, Arbitrary a) => Arbitrary (Id a) 
Enumerable a0 => Enumerable (Id a) 
Pretty (Id a) 
Fixable (Id a) 
Typeable (* -> *) Id 

data Prop a Source

Property names in an object initializer: see spec 11.1.5

Constructors

PropId a (Id a)

property name is an identifier, foo

PropString a String

property name is a string, "foo"

PropNum a Integer

property name is an integer, 42

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 LValue a Source

Left-hand side expressions: see spec 11.2

Constructors

LVar a String

variable reference, foo

LDot a (Expression a) String
foo.bar
LBracket a (Expression a) (Expression a)
foo[bar]

data SourcePos :: *

The abstract data type SourcePos represents source positions. It contains the name of the source (i.e. file name), a line number and a column number. SourcePos is an instance of the Show, Eq and Ord class.

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, EnclosingOther is never pushed if the current labelSet is empty, so the list of labels in this constructor should always be non-empty

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

Methods

getLabelSet :: a -> [Label] Source

setLabelSet :: [Label] -> a -> a Source