-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | JavaScript analysis tools -- -- Some tools for working with ECMAScript 3 (popularly known as -- JavaScript). Includes a parser, pretty-printer, and basic building -- blocks for more sophisticated tools. This package supercedes package -- WebBits. @package language-ecmascript @version 0.13 module Language.ECMAScript3.Parser.State type ParserState = [String] module Language.ECMAScript3.Parser.Type type Parser s a = ParsecT s ParserState Identity a -- | This isn't a lexer in the sense that it provides a JavaScript -- token-stream. This module provides character-parsers for various -- JavaScript tokens. module Language.ECMAScript3.Lexer lexeme :: Stream s Identity Char => Parser s a -> Parser s a identifier :: Stream s Identity Char => Parser s String reserved :: Stream s Identity Char => String -> Parser s () operator :: Stream s Identity Char => Parser s String reservedOp :: Stream s Identity Char => String -> Parser s () charLiteral :: Stream s Identity Char => Parser s Char stringLiteral :: Stream s Identity Char => Parser s String natural :: Stream s Identity Char => Parser s Integer integer :: Stream s Identity Char => Parser s Integer float :: Stream s Identity Char => Parser s Double naturalOrFloat :: Stream s Identity Char => Parser s (Either Integer Double) decimal :: Stream s Identity Char => Parser s Integer hexadecimal :: Stream s Identity Char => Parser s Integer octal :: Stream s Identity Char => Parser s Integer symbol :: Stream s Identity Char => String -> Parser s String whiteSpace :: Stream s Identity Char => Parser s () parens :: Stream s Identity Char => Parser s a -> Parser s a braces :: Stream s Identity Char => Parser s a -> Parser s a brackets :: Stream s Identity Char => Parser s a -> Parser s a squares :: Stream s Identity Char => Parser s a -> Parser s a semi :: Stream s Identity Char => Parser s String comma :: Stream s Identity Char => Parser s String colon :: Stream s Identity Char => Parser s String dot :: Stream s Identity Char => Parser s String identifierStart :: Stream s Identity Char => Parser s Char -- | ECMAScript 3 syntax. Spec refers to the ECMA-262 specification, -- 3rd edition. module Language.ECMAScript3.Syntax data JavaScript a -- | A script in <script> ... </script> tags. Script :: a -> [Statement a] -> JavaScript a -- | extracts statements from a JavaScript type unJavaScript :: JavaScript a -> [Statement a] -- | Statements, spec 12. data Statement a -- | {stmts}, spec 12.1 BlockStmt :: a -> [Statement a] -> Statement a -- | ;, spec 12.3 EmptyStmt :: a -> Statement a -- | expr;, spec 12.4 ExprStmt :: a -> (Expression a) -> Statement a -- | if (e) stmt, spec 12.5 IfStmt :: a -> (Expression a) -> (Statement a) -> (Statement a) -> Statement a -- | if (e) stmt1 else stmt2, spec 12.5 IfSingleStmt :: a -> (Expression a) -> (Statement a) -> Statement a -- | switch (e) clauses, spec 12.11 SwitchStmt :: a -> (Expression a) -> [CaseClause a] -> Statement a -- | while (e) do stmt, spec 12.6 WhileStmt :: a -> (Expression a) -> (Statement a) -> Statement a -- | do stmt while (e);, spec 12.6 DoWhileStmt :: a -> (Statement a) -> (Expression a) -> Statement a -- | break lab;, spec 12.8 BreakStmt :: a -> (Maybe (Id a)) -> Statement a -- | continue lab;, spec 12.7 ContinueStmt :: a -> (Maybe (Id a)) -> Statement a -- | lab: stmt, spec 12.12 LabelledStmt :: a -> (Id a) -> (Statement a) -> Statement a -- | for (x in o) stmt, spec 12.6 ForInStmt :: a -> (ForInInit a) -> (Expression a) -> (Statement a) -> Statement a -- | ForStmt a init test increment body, for (init; test, -- increment) body, spec 12.6 ForStmt :: a -> (ForInit a) -> (Maybe (Expression a)) -> (Maybe (Expression a)) -> (Statement a) -> Statement a -- | try stmt catch(x) stmt finally stmt, spec 12.14 TryStmt :: a -> (Statement a) -> (Maybe (CatchClause a)) -> (Maybe (Statement a)) -> Statement a -- | throw expr;, spec 12.13 ThrowStmt :: a -> (Expression a) -> Statement a -- | return expr;, spec 12.9 ReturnStmt :: a -> (Maybe (Expression a)) -> Statement a -- | with (o) stmt, spec 12.10 WithStmt :: a -> (Expression a) -> (Statement a) -> Statement a -- | var x, y=42;, spec 12.2 VarDeclStmt :: a -> [VarDecl a] -> Statement a -- | function f(x, y, z) {...}, spec 13 FunctionStmt :: a -> (Id a) -> [Id a] -> [Statement a] -> Statement a -- | Returns True if the statement is an IterationStatement -- according to spec 12.6. isIterationStmt :: Statement a -> Bool -- | Case clauses, spec 12.11 data CaseClause a -- |
--   case e: stmts;
--   
CaseClause :: a -> (Expression a) -> [Statement a] -> CaseClause a -- |
--   default: stmts;
--   
CaseDefault :: a -> [Statement a] -> CaseClause a -- | Catch clause, spec 12.14 data CatchClause a -- |
--   catch (x) {...}
--   
CatchClause :: a -> (Id a) -> (Statement a) -> CatchClause a -- | for initializer, spec 12.6 data ForInit a -- | empty NoInit :: ForInit a -- |
--   var x, y=42
--   
VarInit :: [VarDecl a] -> ForInit a -- |
--   expr
--   
ExprInit :: (Expression a) -> ForInit a -- | for..in initializer, spec 12.6 data ForInInit a -- |
--   var x
--   
ForInVar :: (Id a) -> ForInInit a -- | foo.baz, foo[bar], z ForInLVal :: (LValue a) -> ForInInit a -- | A variable declaration, spec 12.2 data VarDecl a -- |
--   var x = e;
--   
VarDecl :: a -> (Id a) -> (Maybe (Expression a)) -> VarDecl a -- | Expressions, see spec 11 data Expression a -- | "foo", spec 11.1.3, 7.8 StringLit :: a -> String -> Expression a -- | RegexpLit a regexp global? case_insensitive? -- regular -- expression, see spec 11.1.3, 7.8 RegexpLit :: a -> String -> Bool -> Bool -> Expression a -- | 41.99999, spec 11.1.3, 7.8 NumLit :: a -> Double -> Expression a -- | 42, spec 11.1.3, 7.8 IntLit :: a -> Int -> Expression a -- | true, spec 11.1.3, 7.8 BoolLit :: a -> Bool -> Expression a -- | null, spec 11.1.3, 7.8 NullLit :: a -> Expression a -- | [1,2,3], spec 11.1.4 ArrayLit :: a -> [Expression a] -> Expression a -- | {foo:"bar", baz: 42}, spec 11.1.5 ObjectLit :: a -> [(Prop a, Expression a)] -> Expression a -- | this, spec 11.1.1 ThisRef :: a -> Expression a -- | foo, spec 11.1.2 VarRef :: a -> (Id a) -> Expression a -- | foo.bar, spec 11.2.1 DotRef :: a -> (Expression a) -> (Id a) -> Expression a -- | foo[bar, spec 11.2.1 BracketRef :: a -> (Expression a) -> (Expression a) -> Expression a -- | new foo(bar), spec 11.2.2 NewExpr :: a -> (Expression a) -> [Expression a] -> Expression a -- | @e, spec 11.4 (excluding 11.4.4, 111.4.5) PrefixExpr :: a -> PrefixOp -> (Expression a) -> Expression a -- | ++x, x-- etc., spec 11.3, 11.4.4, 11.4.5 UnaryAssignExpr :: a -> UnaryAssignOp -> (LValue a) -> Expression a -- | e1@e2, spec 11.5, 11.6, 11.7, 11.8, 11.9, 11.10, 11.11 InfixExpr :: a -> InfixOp -> (Expression a) -> (Expression a) -> Expression a -- | e1 ? e2 : e3, spec 11.12 CondExpr :: a -> (Expression a) -> (Expression a) -> (Expression a) -> Expression a -- | e1 @=e2, spec 11.13 AssignExpr :: a -> AssignOp -> (LValue a) -> (Expression a) -> Expression a -- | e1, e2, spec 11.14 ListExpr :: a -> [Expression a] -> Expression a -- | f(x,y,z), spec 11.2.3 funcexprs are optionally named CallExpr :: a -> (Expression a) -> [Expression a] -> Expression a -- | function f (x,y,z) {...}, spec 11.2.5, 13 FuncExpr :: a -> (Maybe (Id a)) -> [Id a] -> [Statement a] -> Expression a -- | Infix operators: see spec 11.5-11.11 data InfixOp -- |
--   <
--   
OpLT :: InfixOp -- |
--   <=
--   
OpLEq :: InfixOp -- |
--   >
--   
OpGT :: InfixOp -- |
--   >=
--   
OpGEq :: InfixOp -- |
--   in
--   
OpIn :: InfixOp -- |
--   instanceof
--   
OpInstanceof :: InfixOp -- |
--   ==
--   
OpEq :: InfixOp -- |
--   !=
--   
OpNEq :: InfixOp -- |
--   ===
--   
OpStrictEq :: InfixOp -- |
--   !===
--   
OpStrictNEq :: InfixOp -- |
--   &&
--   
OpLAnd :: InfixOp -- |
--   ||
--   
OpLOr :: InfixOp -- |
--   *
--   
OpMul :: InfixOp -- |
--   /
--   
OpDiv :: InfixOp -- |
--   %
--   
OpMod :: InfixOp -- |
--   -
--   
OpSub :: InfixOp -- |
--   <<
--   
OpLShift :: InfixOp -- |
--   >>
--   
OpSpRShift :: InfixOp -- |
--   >>>
--   
OpZfRShift :: InfixOp -- |
--   &
--   
OpBAnd :: InfixOp -- |
--   ^
--   
OpBXor :: InfixOp -- |
--   |
--   
OpBOr :: InfixOp -- |
--   +
--   
OpAdd :: InfixOp -- | Assignment operators: see spec 11.13 data AssignOp -- | simple assignment, = OpAssign :: AssignOp -- |
--   +=
--   
OpAssignAdd :: AssignOp -- |
--   -=
--   
OpAssignSub :: AssignOp -- |
--   *=
--   
OpAssignMul :: AssignOp -- |
--   /=
--   
OpAssignDiv :: AssignOp -- |
--   %=
--   
OpAssignMod :: AssignOp -- |
--   <<=
--   
OpAssignLShift :: AssignOp -- |
--   >>=
--   
OpAssignSpRShift :: AssignOp -- |
--   >>>=
--   
OpAssignZfRShift :: AssignOp -- |
--   &=
--   
OpAssignBAnd :: AssignOp -- |
--   ^=
--   
OpAssignBXor :: AssignOp -- |
--   |=
--   
OpAssignBOr :: AssignOp data Id a Id :: a -> String -> Id a unId :: Id a -> String -- | Prefix operators: see spec 11.4 (excluding 11.4.4, 11.4.5) data PrefixOp -- |
--   !
--   
PrefixLNot :: PrefixOp -- |
--   ~
--   
PrefixBNot :: PrefixOp -- |
--   +
--   
PrefixPlus :: PrefixOp -- |
--   -
--   
PrefixMinus :: PrefixOp -- |
--   typeof
--   
PrefixTypeof :: PrefixOp -- |
--   void
--   
PrefixVoid :: PrefixOp -- |
--   delete
--   
PrefixDelete :: PrefixOp -- | Property names in an object initializer: see spec 11.1.5 data Prop a -- | property name is an identifier, foo PropId :: a -> (Id a) -> Prop a -- | property name is a string, "foo" PropString :: a -> String -> Prop a -- | property name is an integer, 42 PropNum :: a -> Integer -> Prop a -- | Unary assignment operators: see spec 11.3, 11.4.4, 11.4.5 data UnaryAssignOp -- |
--   ++x
--   
PrefixInc :: UnaryAssignOp -- |
--   --x
--   
PrefixDec :: UnaryAssignOp -- |
--   x++
--   
PostfixInc :: UnaryAssignOp -- |
--   x--
--   
PostfixDec :: UnaryAssignOp -- | Left-hand side expressions: see spec 11.2 data LValue a -- | variable reference, foo LVar :: a -> String -> LValue a -- |
--   foo.bar
--   
LDot :: a -> (Expression a) -> String -> LValue a -- |
--   foo[bar]
--   
LBracket :: a -> (Expression a) -> (Expression a) -> LValue a -- | 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. data SourcePos :: * instance Typeable1 Id instance Typeable InfixOp instance Typeable AssignOp instance Typeable UnaryAssignOp instance Typeable PrefixOp instance Typeable1 Prop instance Typeable1 Statement instance Typeable1 ForInInit instance Typeable1 LValue instance Typeable1 Expression instance Typeable1 ForInit instance Typeable1 VarDecl instance Typeable1 CatchClause instance Typeable1 CaseClause instance Typeable1 JavaScript instance Show a => Show (Id a) instance Eq a => Eq (Id a) instance Ord a => Ord (Id a) instance Data a => Data (Id a) instance Functor Id instance Foldable Id instance Traversable Id instance Show InfixOp instance Data InfixOp instance Eq InfixOp instance Ord InfixOp instance Enum InfixOp instance Show AssignOp instance Data AssignOp instance Eq AssignOp instance Ord AssignOp instance Show UnaryAssignOp instance Data UnaryAssignOp instance Eq UnaryAssignOp instance Ord UnaryAssignOp instance Show PrefixOp instance Data PrefixOp instance Eq PrefixOp instance Ord PrefixOp instance Show a => Show (Prop a) instance Data a => Data (Prop a) instance Eq a => Eq (Prop a) instance Ord a => Ord (Prop a) instance Functor Prop instance Foldable Prop instance Traversable Prop instance Show a => Show (Statement a) instance Data a => Data (Statement a) instance Eq a => Eq (Statement a) instance Ord a => Ord (Statement a) instance Functor Statement instance Foldable Statement instance Traversable Statement instance Show a => Show (ForInInit a) instance Data a => Data (ForInInit a) instance Eq a => Eq (ForInInit a) instance Ord a => Ord (ForInInit a) instance Functor ForInInit instance Foldable ForInInit instance Traversable ForInInit instance Show a => Show (LValue a) instance Eq a => Eq (LValue a) instance Ord a => Ord (LValue a) instance Data a => Data (LValue a) instance Functor LValue instance Foldable LValue instance Traversable LValue instance Show a => Show (Expression a) instance Data a => Data (Expression a) instance Eq a => Eq (Expression a) instance Ord a => Ord (Expression a) instance Functor Expression instance Foldable Expression instance Traversable Expression instance Show a => Show (ForInit a) instance Data a => Data (ForInit a) instance Eq a => Eq (ForInit a) instance Ord a => Ord (ForInit a) instance Functor ForInit instance Foldable ForInit instance Traversable ForInit instance Show a => Show (VarDecl a) instance Data a => Data (VarDecl a) instance Eq a => Eq (VarDecl a) instance Ord a => Ord (VarDecl a) instance Functor VarDecl instance Foldable VarDecl instance Traversable VarDecl instance Show a => Show (CatchClause a) instance Data a => Data (CatchClause a) instance Eq a => Eq (CatchClause a) instance Ord a => Ord (CatchClause a) instance Functor CatchClause instance Foldable CatchClause instance Traversable CatchClause instance Show a => Show (CaseClause a) instance Data a => Data (CaseClause a) instance Eq a => Eq (CaseClause a) instance Ord a => Ord (CaseClause a) instance Functor CaseClause instance Foldable CaseClause instance Traversable CaseClause instance Show a => Show (JavaScript a) instance Data a => Data (JavaScript a) instance Eq a => Eq (JavaScript a) instance Ord a => Ord (JavaScript a) instance Functor JavaScript instance Foldable JavaScript instance Traversable JavaScript instance Default SourcePos instance Default a => Default (JavaScript a) -- | Pretty-printing JavaScript. module Language.ECMAScript3.PrettyPrint -- | Renders a JavaScript program as a document, the show instance of -- Doc will pretty-print it automatically javaScript :: JavaScript a -> Doc -- | Renders a list of statements as a String renderStatements :: [Statement a] -> String -- | Renders a list of statements as a String renderExpression :: Expression a -> String class PP a pp :: PP a => a -> Doc instance PP PrefixOp instance PP AssignOp instance PP InfixOp instance PP (LValue a) instance PP (ForInit a) instance PP (Statement a) instance PP (Expression a) instance PP [Statement a] -- | A few helpers to work with the AST annotations module Language.ECMAScript3.Syntax.Annotations -- | Removes annotations from a tree removeAnnotations :: Traversable t => t a -> t () -- | Changes all the labels in the tree to another one, given by a -- function. reannotate :: Traversable t => (a -> b) -> t a -> t b -- | add an extra field to the AST labels (the label would look like -- (a, b) ) addExtraAnnotationField :: Traversable t => b -> t a -> t (a, b) -- | remove an extra field removeExtraAnnotationField :: Traversable t => t (a, b) -> t a -- | Assigns unique numeric (Int) ids to each node in the AST. Returns a -- pair: the tree annotated with UID's and the last ID that was assigned. assignUniqueIds :: Traversable t => Int -> t a -> (t (a, Int), Int) -- | Things that have annotations -- for example, nodes in a syntax tree class HasAnnotation a getAnnotation :: HasAnnotation a => a b -> b setAnnotation :: HasAnnotation a => b -> a b -> a b -- | Modify the annotation of the root node of the syntax tree withAnnotation :: HasAnnotation a => (b -> b) -> a b -> a b instance HasAnnotation Id instance HasAnnotation CatchClause instance HasAnnotation CaseClause instance HasAnnotation Prop instance HasAnnotation VarDecl instance HasAnnotation LValue instance HasAnnotation Statement instance HasAnnotation Expression -- | Parser for ECMAScript 3. module Language.ECMAScript3.Parser -- | Parse from a stream; same as parse parse :: Stream s Identity Char => Parser s a -> SourceName -> s -> Either ParseError a -- | Parse a JavaScript program from a string parseScriptFromString :: String -> String -> Either ParseError (JavaScript SourcePos) -- | Read a JavaScript program from file an parse it into a list of -- statements parseJavaScriptFromFile :: MonadIO m => String -> m [Statement SourcePos] parseScript :: Stream s Identity Char => Parser s (JavaScript SourcePos) parseExpression :: Stream s Identity Char => ExpressionParser s -- | Parse a JavaScript source string into a list of statements parseString :: String -> [Statement SourcePos] type ParsedStatement = Statement SourcePos type ParsedExpression = Expression SourcePos parseSimpleExpr' :: Stream s Identity Char => ExpressionParser s parseBlockStmt :: Stream s Identity Char => StatementParser s parseStatement :: Stream s Identity Char => StatementParser s type StatementParser s = Parser s ParsedStatement type ExpressionParser s = Parser s ParsedExpression assignExpr :: Stream s Identity Char => ExpressionParser s -- | Creates a decimal value from a whole, fractional and exponent part. mkDecimal :: Integer -> Integer -> Integer -> Integer -> Double intLen :: (Integral a, Num a1) => a -> a1 parseObjectLit :: Stream s Identity Char => ExpressionParser s type Parser s a = ParsecT s ParserState Identity a -- | QuickCheck $Arbitrary$ instances for ECMAScript 3 abstract syntax. module Language.ECMAScript3.Syntax.Arbitrary cshrink :: Arbitrary a => [a] -> [a] identifier :: Gen String type MSGen a = (Int, Gen a) sGen :: [MSGen a] -> Gen a recursive :: Gen a -> Gen a rarbitrary :: Arbitrary a => Gen a rrarbitrary :: Arbitrary a => Gen a atLeastOfSize :: Arbitrary a => Int -> Gen a -> Gen a nonEmptyString :: Gen String regexpBody :: Gen String nonNegative :: (Arbitrary a, Num a) => Gen a stringOfLength :: Int -> Gen String emptyStmtShrink :: Arbitrary a => a -> [Statement a] type LabelSubst = Map (Id ()) (Id ()) emptyConstantPool :: Map k a -- | Fixes labels so that labeled breaks and continues refer to existing -- labeled statements, enclosing them; also, reduces the size of the -- label set. Assumes that the program has a proper syntactic structure, -- i.e. isProgramFixable s = True. fixLabels :: Data a => JavaScript a -> Gen (JavaScript a) -- | choose n elements from a list randomly rChooseElem :: [a] -> Int -> Gen [a] -- | A predicate that tells us whether a program has a fixable/correct -- label-break/continue structure. The predicate imposes syntactic -- restrictions on the break, continue and labeled statements as in the -- ECMA spec isProgramFixable :: Data a => JavaScript a -> Bool -- | Imposes relaxed restrictions on break and continue per ECMAScript 5 -- spec (page 92): any continue without a label should be nested within -- an iteration stmt, any continue with a label should be nested in a -- labeled statement (not necessarily with the same label); any break -- statement without a label should be nested in an iteration or switch -- stmt, any break statement with a label should be nested in a labeled -- statement (not necessarily with the same label). isBreakContinueFixable :: Data a => Statement a -> Bool -> Bool -> Bool -> Bool -- | Removes duplicate labels from nested labeled statements in order to -- impose restrictions on labeled statements as per ECMAScript 5 spec -- (page 95): nested labeled statements cannot have duplicating labels. removeDuplicateLabels :: Data a => JavaScript a -> Gen (JavaScript a) -- | Selects a random element of the list selectRandomElement :: [a] -> Gen a -- | Changes labels of break/continue so that they refer to one of the -- enclosing labels fixBreakContinueLabels :: Data a => JavaScript a -> Gen (JavaScript a) isSwitchStmt :: Statement a -> Bool instance (Data a, Arbitrary a) => Arbitrary (JavaScript a) instance Arbitrary a => Arbitrary (Statement a) instance Arbitrary a => Arbitrary (VarDecl a) instance Arbitrary a => Arbitrary (CatchClause a) instance Arbitrary a => Arbitrary (ForInit a) instance Arbitrary a => Arbitrary (ForInInit a) instance Arbitrary a => Arbitrary (Expression a) instance Arbitrary a => Arbitrary (LValue a) instance Arbitrary a => Arbitrary (Prop a) instance Arbitrary a => Arbitrary (CaseClause a) instance Arbitrary a => Arbitrary (Id a) instance Arbitrary PrefixOp instance Arbitrary UnaryAssignOp instance Arbitrary InfixOp instance Arbitrary AssignOp -- | Experimental and very simple quasi-quotation of ECMAScript in Haskell. -- Doesn't support anti-quotation as of now. module Language.ECMAScript3.Syntax.QuasiQuote js :: QuasiQuoter jsexpr :: QuasiQuoter jsstmt :: QuasiQuoter -- | A lexical environment analysis of ECMAScript programs module Language.ECMAScript3.Analysis.Environment env :: Map String SourcePos -> [Statement SourcePos] -> (EnvTree, Map String SourcePos) localVars :: [Statement SourcePos] -> [(String, SourcePos)] -- | The statically-determinate lexical structure of a JavaScript program. data EnvTree EnvTree :: (Map String SourcePos) -> [EnvTree] -> EnvTree -- | Label-set analysis which annotates all the statements in the script -- with their label sets according to ECMAScript specification, section -- 12.12. The result of this analysis are useful for building -- control-flow graphs. module Language.ECMAScript3.Analysis.LabelSets -- | Annotates statements with their label sets; example use: -- --
--   >>> let jsa = reannotate (\a -> (a, Set.empty))
--   
--   >>> in  annotateLabelSets jsa snd (\labs (a, ls) -> (a, labs `Set.union` ls))
--   
annotateLabelSets :: Data a => (a -> Set Label) -> (Set Label -> a -> a) -> JavaScript a -> JavaScript a -- | Labels are either strings (identifiers) or empty (see 12.12 of -- the spec) data Label Label :: String -> Label EmptyLabel :: Label instance Typeable Label instance Ord Label instance Eq Label instance Show Label instance Data Label -- | Re-exports commonly used modules. module Language.ECMAScript3 -- | Renders a list of statements as a String renderStatements :: [Statement a] -> String -- | Renders a list of statements as a String renderExpression :: Expression a -> String