module Language.JavaScript.Parser.AST
(
Node (..)
, JSNode(..)
, showStripped
) where
import Data.Data
import Data.List
import Language.JavaScript.Parser.SrcLocation (TokenPosn(..))
import Language.JavaScript.Parser.Token
data JSNode = NN Node
| NT Node TokenPosn [CommentAnnotation]
deriving (Show, Eq, Read, Data, Typeable)
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]
deriving (Show, Eq, Read, Data, Typeable)
showStripped :: JSNode -> String
showStripped = ss
ss :: JSNode -> String
ss (NN node ) = showStrippedNode node
ss (NT node _ _) = showStrippedNode node
sss :: [JSNode] -> String
sss xs = "[" ++ (concat (intersperse "," $ map ss xs)) ++ "]"
showStrippedNode :: Node -> String
showStrippedNode (JSArguments _lb xs _rb) = "JSArguments " ++ sss xs
showStrippedNode (JSArrayLiteral _lb xs _rb) = "JSArrayLiteral " ++ sss xs
showStrippedNode (JSBlock _lb xs _rb) = "JSBlock (" ++ sss xs ++ ")"
showStrippedNode (JSBreak _b x1s as) = "JSBreak " ++ sss x1s ++ " " ++ ss as
showStrippedNode (JSCallExpression s _os xs _cs) = "JSCallExpression " ++ show s ++ " " ++ sss xs
showStrippedNode (JSCase _ca x1 _c x2s) = "JSCase (" ++ ss x1 ++ ") (" ++ sss x2s ++ ")"
showStrippedNode (JSCatch _c _lb x1 x2s _rb x3) = "JSCatch (" ++ ss x1 ++ ") " ++ sss x2s ++ " (" ++ ss x3 ++ ")"
showStrippedNode (JSContinue _c xs as) = "JSContinue " ++ sss xs ++ " " ++ ss as
showStrippedNode (JSDecimal s) = "JSDecimal " ++ show s
showStrippedNode (JSDefault _d _c xs) = "JSDefault (" ++ sss xs ++ ")"
showStrippedNode (JSDoWhile _d x1 _w _lb x2 _rb x3) = "JSDoWhile (" ++ ss x1 ++ ") (" ++ ss x2 ++ ") (" ++ ss x3 ++ ")"
showStrippedNode (JSElision c) = "JSElision " ++ ss c
showStrippedNode (JSExpression xs) = "JSExpression " ++ sss xs
showStrippedNode (JSExpressionBinary s x2s _op x3s) = "JSExpressionBinary " ++ show s ++ " " ++ sss x2s ++ " " ++ sss x3s
showStrippedNode (JSExpressionParen _lp x _rp) = "JSExpressionParen (" ++ ss x ++ ")"
showStrippedNode (JSExpressionPostfix s xs _op) = "JSExpressionPostfix " ++ show s ++ " " ++ sss xs
showStrippedNode (JSExpressionTernary x1s _q x2s _c x3s) = "JSExpressionTernary " ++ sss x1s ++ " " ++ sss x2s ++ " " ++ sss x3s
showStrippedNode (JSFinally _f x) = "JSFinally (" ++ ss x ++ ")"
showStrippedNode (JSFor _f _lb x1s _s1 x2s _s2 x3s _rb x4) = "JSFor " ++ sss x1s ++ " " ++ sss x2s ++ " " ++ sss x3s ++ " (" ++ ss x4 ++ ")"
showStrippedNode (JSForIn _f _lb x1s _i x2 _rb x3) = "JSForIn " ++ sss x1s ++ " (" ++ ss x2 ++ ") (" ++ ss x3 ++ ")"
showStrippedNode (JSForVar _f _lb _v x1s _s1 x2s _s2 x3s _rb x4) = "JSForVar " ++ sss x1s ++ " " ++ sss x2s ++ " " ++ sss x3s ++ " (" ++ ss x4 ++ ")"
showStrippedNode (JSForVarIn _f _lb _v x1 _i x2 _rb x3) = "JSForVarIn (" ++ ss x1 ++ ") (" ++ ss x2 ++ ") (" ++ ss x3 ++ ")"
showStrippedNode (JSFunction _f x1 _lb x2s _rb x3) = "JSFunction (" ++ ss x1 ++ ") " ++ sss x2s ++ " (" ++ ss x3 ++ ")"
showStrippedNode (JSFunctionExpression _f x1s _lb x2s _rb x3) = "JSFunctionExpression " ++ sss x1s ++ " " ++ sss x2s ++ " (" ++ ss x3 ++ ")"
showStrippedNode (JSHexInteger s) = "JSHexInteger " ++ show s
showStrippedNode (JSOctal s) = "JSOctal " ++ show s
showStrippedNode (JSIdentifier s) = "JSIdentifier " ++ show s
showStrippedNode (JSIf _i _lb x1 _rb x2s x3s) = "JSIf (" ++ ss x1 ++ ") (" ++ sss x2s ++ ") (" ++ sss x3s ++ ")"
showStrippedNode (JSLabelled x1 _c x2) = "JSLabelled (" ++ ss x1 ++ ") (" ++ ss x2 ++ ")"
showStrippedNode (JSLiteral s) = "JSLiteral " ++ show s
showStrippedNode (JSMemberDot x1s _d x2 ) = "JSMemberDot " ++ sss x1s ++ " (" ++ ss x2 ++ ")"
showStrippedNode (JSMemberSquare x1s _lb x2 _rb) = "JSMemberSquare " ++ sss x1s ++ " (" ++ ss x2 ++ ")"
showStrippedNode (JSObjectLiteral _lb xs _rb) = "JSObjectLiteral " ++ sss xs
showStrippedNode (JSOperator n) = "JSOperator " ++ ss n
showStrippedNode (JSPropertyNameandValue x1 _colon x2s) = "JSPropertyNameandValue (" ++ ss x1 ++ ") " ++ sss x2s
showStrippedNode (JSPropertyAccessor s x1 _lb1 x2s _rb1 x3) = "JSPropertyAccessor " ++ show s ++ " (" ++ ss x1 ++ ") " ++ sss x2s ++ " (" ++ ss x3 ++ ")"
showStrippedNode (JSRegEx s) = "JSRegEx " ++ show s
showStrippedNode (JSReturn _r xs as) = "JSReturn " ++ sss xs ++ " " ++ ss as
showStrippedNode (JSSourceElementsTop xs) = "JSSourceElementsTop " ++ sss xs
showStrippedNode (JSStringLiteral c s) = "JSStringLiteral " ++ show c ++ " " ++ show s
showStrippedNode (JSSwitch _s _lb x _rb x2) = "JSSwitch (" ++ ss x ++ ") " ++ ss x2
showStrippedNode (JSThrow _t x) = "JSThrow (" ++ ss x ++ ")"
showStrippedNode (JSTry _t x1 x2s) = "JSTry (" ++ ss x1 ++ ") " ++ sss x2s
showStrippedNode (JSUnary s _x) = "JSUnary " ++ show s
showStrippedNode (JSVarDecl x1 x2s) = "JSVarDecl (" ++ ss x1 ++ ") " ++ sss x2s
showStrippedNode (JSVariables n xs _as) = "JSVariables " ++ ss n ++ " " ++ sss xs
showStrippedNode (JSWhile _w _lb x1 _rb x2) = "JSWhile (" ++ ss x1 ++ ") (" ++ ss x2 ++ ")"
showStrippedNode (JSWith _w _lb x1 _rb x2s) = "JSWith (" ++ ss x1 ++ ") " ++ sss x2s