-- 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.9 -- | 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 :: ParsecT String u Identity a -> ParsecT String u Identity a identifier :: ParsecT String u Identity String reserved :: String -> ParsecT String u Identity () operator :: ParsecT String u Identity String reservedOp :: String -> ParsecT String u Identity () charLiteral :: ParsecT String u Identity Char stringLiteral :: ParsecT String u Identity String natural :: ParsecT String u Identity Integer integer :: ParsecT String u Identity Integer float :: ParsecT String u Identity Double naturalOrFloat :: ParsecT String u Identity (Either Integer Double) decimal :: ParsecT String u Identity Integer hexadecimal :: ParsecT String u Identity Integer octal :: ParsecT String u Identity Integer symbol :: String -> ParsecT String u Identity String whiteSpace :: ParsecT String u Identity () parens :: ParsecT String u Identity a -> ParsecT String u Identity a braces :: ParsecT String u Identity a -> ParsecT String u Identity a brackets :: ParsecT String u Identity a -> ParsecT String u Identity a squares :: ParsecT String u Identity a -> ParsecT String u Identity a semi :: ParsecT String u Identity String comma :: ParsecT String u Identity String colon :: ParsecT String u Identity String dot :: ParsecT String u Identity String identifierStart :: ParsecT [Char] u Identity 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 -- | (e), spec 11.1.6 ParenExpr :: 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 -- | 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) class HasAnnotation a getAnnotation :: HasAnnotation a => a b -> b 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 t => Parsec s [String] 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 :: CharParser (JavaScript SourcePos) parseExpression :: ExpressionParser -- | Parse a JavaScript source string into a list of statements parseString :: String -> [Statement SourcePos] type ParsedStatement = Statement SourcePos type ParsedExpression = Expression SourcePos parseSimpleExpr' :: ParsecT String ParserState Identity ParsedExpression parseBlockStmt :: StatementParser parseStatement :: StatementParser type StatementParser = CharParser ParsedStatement type ExpressionParser = CharParser ParsedExpression assignExpr :: ExpressionParser -- | 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