Safe Haskell | None |
---|---|
Language | Haskell98 |
- parse :: String -> String -> Either String JSNode
- readJs :: String -> JSNode
- parseFile :: FilePath -> IO JSNode
- parseFileUtf8 :: FilePath -> IO JSNode
- showStripped :: JSNode -> String
- showStrippedMaybe :: Show a => Either a JSNode -> String
- data JSNode
- data Node
- = JSIdentifier String
- | JSDecimal String
- | JSLiteral String
- | JSHexInteger String
- | JSOctal String
- | JSStringLiteral Char [Char]
- | JSRegEx String
- | JSArguments JSNode [JSNode] JSNode
- | JSArrayLiteral JSNode [JSNode] JSNode
- | JSBlock [JSNode] [JSNode] [JSNode]
- | JSBreak JSNode [JSNode] JSNode
- | JSCallExpression String [JSNode] [JSNode] [JSNode]
- | JSCase JSNode JSNode JSNode [JSNode]
- | JSCatch JSNode JSNode JSNode [JSNode] JSNode JSNode
- | JSContinue JSNode [JSNode] JSNode
- | JSDefault JSNode JSNode [JSNode]
- | JSDoWhile JSNode JSNode JSNode JSNode JSNode JSNode JSNode
- | JSElision JSNode
- | JSExpression [JSNode]
- | JSExpressionBinary String [JSNode] JSNode [JSNode]
- | JSExpressionParen JSNode JSNode JSNode
- | JSExpressionPostfix String [JSNode] JSNode
- | JSExpressionTernary [JSNode] JSNode [JSNode] JSNode [JSNode]
- | JSFinally JSNode JSNode
- | JSFor JSNode JSNode [JSNode] JSNode [JSNode] JSNode [JSNode] JSNode JSNode
- | JSForIn JSNode JSNode [JSNode] JSNode JSNode JSNode JSNode
- | JSForVar JSNode JSNode JSNode [JSNode] JSNode [JSNode] JSNode [JSNode] JSNode JSNode
- | JSForVarIn JSNode JSNode JSNode JSNode JSNode JSNode JSNode JSNode
- | JSFunction JSNode JSNode JSNode [JSNode] JSNode JSNode
- | JSFunctionExpression JSNode [JSNode] JSNode [JSNode] JSNode JSNode
- | JSIf JSNode JSNode JSNode JSNode [JSNode] [JSNode]
- | JSLabelled JSNode JSNode JSNode
- | JSMemberDot [JSNode] JSNode JSNode
- | JSMemberSquare [JSNode] JSNode JSNode JSNode
- | JSObjectLiteral JSNode [JSNode] JSNode
- | JSOperator JSNode
- | JSPropertyAccessor JSNode JSNode JSNode [JSNode] JSNode JSNode
- | JSPropertyNameandValue JSNode JSNode [JSNode]
- | JSReturn JSNode [JSNode] JSNode
- | JSSourceElementsTop [JSNode]
- | JSSwitch JSNode JSNode JSNode JSNode JSNode
- | JSThrow JSNode JSNode
- | JSTry JSNode JSNode [JSNode]
- | JSUnary String JSNode
- | JSVarDecl JSNode [JSNode]
- | JSVariables JSNode [JSNode] JSNode
- | JSWhile JSNode JSNode JSNode JSNode JSNode
- | JSWith JSNode JSNode JSNode JSNode [JSNode]
- data CommentAnnotation
- data TokenPosn = TokenPn !Int !Int !Int
- tokenPosnEmpty :: TokenPosn
- renderJS :: JSNode -> Builder
- renderToString :: JSNode -> String
Documentation
:: String | The input stream (Javascript source code). |
-> String | The name of the Javascript source (filename or input device). |
-> Either String JSNode | An error or maybe the abstract syntax tree (AST) of zero or more Javascript statements, plus comments. |
Parse one compound statement, or a sequence of simple statements. Generally used for interactive input, such as from the command line of an interpreter. Return comments in addition to the parsed statements.
parseFile :: FilePath -> IO JSNode Source
Parse the given file. For UTF-8 support, make sure your locale is set such that "System.IO.localeEncoding" returns "utf8"
parseFileUtf8 :: FilePath -> IO JSNode Source
Parse the given file, explicitly setting the encoding to UTF8 when reading it
showStripped :: JSNode -> String Source
The JSNode is the building block of the AST.
Each has a syntactic part Node
. In addition, the leaf elements
(terminals) have a position TokenPosn
, as well as an array of comments
and/or whitespace that was collected while parsing.
data CommentAnnotation Source
TokenPosn
records the location of a token in the input text. It has three
fields: the address (number of characters preceding the token), line number
and column of a token within the file.
Note: The lexer assumes the usual eight character tab stops.
Pretty Printing
renderToString :: JSNode -> String Source