11module Language.JavaScript.Parser.AST
2- ( JSNode (.. )
2+ ( JSExpression (.. )
33 , JSAnnot (.. )
44 , JSBinOp (.. )
55 , JSUnaryOp (.. )
@@ -95,8 +95,8 @@ data JSAssignOp
9595 deriving (Show , Eq )
9696
9797data JSTryCatch
98- = JSCatch JSAnnot JSAnnot JSNode JSAnnot JSBlock -- ^ catch,lb,ident,rb,block
99- | JSCatchIf JSAnnot JSAnnot JSNode JSAnnot JSNode JSAnnot JSBlock -- ^ catch,lb,ident,if,expr,rb,block
98+ = JSCatch JSAnnot JSAnnot JSExpression JSAnnot JSBlock -- ^ catch,lb,ident,rb,block
99+ | JSCatchIf JSAnnot JSAnnot JSExpression JSAnnot JSExpression JSAnnot JSBlock -- ^ catch,lb,ident,if,expr,rb,block
100100 deriving (Show , Eq )
101101
102102data JSTryFinally
@@ -109,7 +109,7 @@ data JSBlock
109109 deriving (Show , Eq )
110110
111111data JSSwitchParts
112- = JSCase JSAnnot JSNode JSAnnot [JSStatement ] -- ^ expr,colon,stmtlist
112+ = JSCase JSAnnot JSExpression JSAnnot [JSStatement ] -- ^ expr,colon,stmtlist
113113 | JSDefault JSAnnot JSAnnot [JSStatement ] -- ^ colon,stmtlist
114114 deriving (Show , Eq )
115115
@@ -118,42 +118,42 @@ data JSStatement
118118 | JSBreak JSAnnot JSIdent JSSemi -- ^ break,optional identifier, autosemi
119119 | JSConstant JSAnnot [JSStatement ] JSSemi -- ^ const, decl, autosemi
120120 | JSContinue JSAnnot JSIdent JSSemi -- ^ continue, optional identifier,autosemi
121- | JSDoWhile JSAnnot JSStatement JSAnnot JSAnnot JSNode JSAnnot JSSemi -- ^ do,stmt,while,lb,expr,rb,autosemi
122- | JSFor JSAnnot JSAnnot [JSNode ] JSAnnot [JSNode ] JSAnnot [JSNode ] JSAnnot JSStatement -- ^ for,lb,expr,semi,expr,semi,expr,rb.stmt
123- | JSForIn JSAnnot JSAnnot JSNode JSBinOp JSNode JSAnnot JSStatement -- ^ for,lb,expr,in,expr,rb,stmt
124- | JSForVar JSAnnot JSAnnot JSAnnot [JSStatement ] JSAnnot [JSNode ] JSAnnot [JSNode ] JSAnnot JSStatement -- ^ for,lb,var,vardecl,semi,expr,semi,expr,rb,stmt
125- | JSForVarIn JSAnnot JSAnnot JSAnnot JSStatement JSBinOp JSNode JSAnnot JSStatement -- ^ for,lb,var,vardecl,in,expr,rb,stmt
126- | JSFunction JSAnnot JSNode JSAnnot (JSList JSIdent ) JSAnnot JSBlock -- ^ fn,name, lb,parameter list,rb,block
127- | JSIf JSAnnot JSAnnot JSNode JSAnnot JSStatement -- ^ if,(,expr,),stmt
128- | JSIfElse JSAnnot JSAnnot JSNode JSAnnot JSStatement JSAnnot JSStatement -- ^ if,(,expr,),stmt,else,rest
129- | JSLabelled JSNode JSAnnot JSStatement -- ^ identifier,colon,stmt
121+ | JSDoWhile JSAnnot JSStatement JSAnnot JSAnnot JSExpression JSAnnot JSSemi -- ^ do,stmt,while,lb,expr,rb,autosemi
122+ | JSFor JSAnnot JSAnnot [JSExpression ] JSAnnot [JSExpression ] JSAnnot [JSExpression ] JSAnnot JSStatement -- ^ for,lb,expr,semi,expr,semi,expr,rb.stmt
123+ | JSForIn JSAnnot JSAnnot JSExpression JSBinOp JSExpression JSAnnot JSStatement -- ^ for,lb,expr,in,expr,rb,stmt
124+ | JSForVar JSAnnot JSAnnot JSAnnot [JSStatement ] JSAnnot [JSExpression ] JSAnnot [JSExpression ] JSAnnot JSStatement -- ^ for,lb,var,vardecl,semi,expr,semi,expr,rb,stmt
125+ | JSForVarIn JSAnnot JSAnnot JSAnnot JSStatement JSBinOp JSExpression JSAnnot JSStatement -- ^ for,lb,var,vardecl,in,expr,rb,stmt
126+ | JSFunction JSAnnot JSExpression JSAnnot (JSList JSIdent ) JSAnnot JSBlock -- ^ fn,name, lb,parameter list,rb,block
127+ | JSIf JSAnnot JSAnnot JSExpression JSAnnot JSStatement -- ^ if,(,expr,),stmt
128+ | JSIfElse JSAnnot JSAnnot JSExpression JSAnnot JSStatement JSAnnot JSStatement -- ^ if,(,expr,),stmt,else,rest
129+ | JSLabelled JSExpression JSAnnot JSStatement -- ^ identifier,colon,stmt
130130 | JSEmptyStatement JSAnnot
131- | JSExpressionStatement JSNode JSSemi
132- | JSReturn JSAnnot (Maybe JSNode ) JSSemi -- ^ optional expression,autosemi
133- | JSSwitch JSAnnot JSAnnot JSNode JSAnnot JSAnnot [JSSwitchParts ] JSAnnot -- ^ switch,lb,expr,rb,caseblock
134- | JSThrow JSAnnot JSNode -- ^ throw val
131+ | JSExpressionStatement JSExpression JSSemi
132+ | JSReturn JSAnnot (Maybe JSExpression ) JSSemi -- ^ optional expression,autosemi
133+ | JSSwitch JSAnnot JSAnnot JSExpression JSAnnot JSAnnot [JSSwitchParts ] JSAnnot -- ^ switch,lb,expr,rb,caseblock
134+ | JSThrow JSAnnot JSExpression -- ^ throw val
135135 | JSTry JSAnnot JSBlock [JSTryCatch ] JSTryFinally -- ^ try,block,catches,finally
136- | JSVarDecl JSNode JSVarInit -- ^ identifier, initializer
136+ | JSVarDecl JSExpression JSVarInit -- ^ identifier, initializer
137137 | JSVariable JSAnnot [JSStatement ] JSSemi -- ^ var|const, decl, autosemi
138- | JSWhile JSAnnot JSAnnot JSNode JSAnnot JSStatement -- ^ while,lb,expr,rb,stmt
139- | JSWith JSAnnot JSAnnot JSNode JSAnnot JSStatement JSSemi -- ^ with,lb,expr,rb,stmt list
138+ | JSWhile JSAnnot JSAnnot JSExpression JSAnnot JSStatement -- ^ while,lb,expr,rb,stmt
139+ | JSWith JSAnnot JSAnnot JSExpression JSAnnot JSStatement JSSemi -- ^ with,lb,expr,rb,stmt list
140140 deriving (Show , Eq )
141141
142142data JSAST
143143 = JSSourceElementsTop [JSStatement ] -- ^ source elements
144144 deriving (Show , Eq )
145145
146146data JSVarInit
147- = JSVarInit JSAnnot JSNode -- ^ assignop, initializer
147+ = JSVarInit JSAnnot JSExpression -- ^ assignop, initializer
148148 | JSVarInitNone
149149 deriving (Show , Eq )
150150
151- -- | The JSNode is the building block of the AST.
151+ -- | The JSExpression is the building block of the AST.
152152-- Each has a syntactic part 'Node'. In addition, the leaf elements
153153-- (terminals) have a position 'TokenPosn', as well as an array of comments
154154-- and/or whitespace that was collected while parsing.
155155
156- data JSNode
156+ data JSExpression
157157 -- | Terminals
158158 = JSIdentifier JSAnnot String
159159 | JSDecimal JSAnnot String
@@ -164,27 +164,27 @@ data JSNode
164164 | JSRegEx JSAnnot String
165165
166166 -- | Non Terminals
167- | JSArrayLiteral JSAnnot [JSNode ] JSAnnot -- ^ lb, contents, rb
168- | JSAssignExpression JSNode JSAssignOp JSNode -- ^ lhs, assignop, rhs
169- | JSCallExpression JSNode JSArguments -- ^ expr, args
170- | JSCallExpressionDot JSNode JSAnnot JSNode -- ^ expr, dot, expr
171- | JSCallExpressionSquare JSNode JSAnnot JSNode JSAnnot -- ^ expr, [, expr, ]
167+ | JSArrayLiteral JSAnnot [JSExpression ] JSAnnot -- ^ lb, contents, rb
168+ | JSAssignExpression JSExpression JSAssignOp JSExpression -- ^ lhs, assignop, rhs
169+ | JSCallExpression JSExpression JSArguments -- ^ expr, args
170+ | JSCallExpressionDot JSExpression JSAnnot JSExpression -- ^ expr, dot, expr
171+ | JSCallExpressionSquare JSExpression JSAnnot JSExpression JSAnnot -- ^ expr, [, expr, ]
172172 | JSComma JSAnnot -- ^ comma
173- | JSCommaExpression JSNode JSAnnot JSNode -- ^ expression components
174- | JSExpressionBinary JSNode JSBinOp JSNode -- ^ lhs, op, rhs
175- | JSExpressionParen JSAnnot JSNode JSAnnot -- ^ lb,expression,rb
176- | JSExpressionPostfix JSNode JSUnaryOp -- ^ expression, operator
177- | JSExpressionTernary JSNode JSAnnot JSNode JSAnnot JSNode -- ^ cond, ?, trueval, :, falseval
173+ | JSCommaExpression JSExpression JSAnnot JSExpression -- ^ expression components
174+ | JSExpressionBinary JSExpression JSBinOp JSExpression -- ^ lhs, op, rhs
175+ | JSExpressionParen JSAnnot JSExpression JSAnnot -- ^ lb,expression,rb
176+ | JSExpressionPostfix JSExpression JSUnaryOp -- ^ expression, operator
177+ | JSExpressionTernary JSExpression JSAnnot JSExpression JSAnnot JSExpression -- ^ cond, ?, trueval, :, falseval
178178 | JSFunctionExpression JSAnnot JSIdent JSAnnot (JSList JSIdent ) JSAnnot JSBlock -- ^ fn,name,lb, parameter list,rb,block`
179- | JSMemberDot JSNode JSAnnot JSNode -- ^ firstpart, dot, name
180- | JSMemberExpression JSNode JSArguments -- expr, args
181- | JSMemberNew JSAnnot JSNode JSArguments -- ^ new, name, args
182- | JSMemberSquare JSNode JSAnnot JSNode JSAnnot -- ^ firstpart, lb, expr, rb
183- | JSNewExpression JSAnnot JSNode -- ^ new, expr
184- | JSObjectLiteral JSAnnot [JSNode ] JSAnnot -- ^ lbrace contents rbrace
185- | JSPropertyAccessor JSAccessor JSIdent JSAnnot [JSNode ] JSAnnot JSBlock -- ^ (get|set), name, lb, params, rb, block
186- | JSPropertyNameandValue JSIdent JSAnnot [JSNode ] -- ^ name, colon, value
187- | JSUnaryExpression JSUnaryOp JSNode
179+ | JSMemberDot JSExpression JSAnnot JSExpression -- ^ firstpart, dot, name
180+ | JSMemberExpression JSExpression JSArguments -- expr, args
181+ | JSMemberNew JSAnnot JSExpression JSArguments -- ^ new, name, args
182+ | JSMemberSquare JSExpression JSAnnot JSExpression JSAnnot -- ^ firstpart, lb, expr, rb
183+ | JSNewExpression JSAnnot JSExpression -- ^ new, expr
184+ | JSObjectLiteral JSAnnot [JSExpression ] JSAnnot -- ^ lbrace contents rbrace
185+ | JSPropertyAccessor JSAccessor JSIdent JSAnnot [JSExpression ] JSAnnot JSBlock -- ^ (get|set), name, lb, params, rb, block
186+ | JSPropertyNameandValue JSIdent JSAnnot [JSExpression ] -- ^ name, colon, value
187+ | JSUnaryExpression JSUnaryOp JSExpression
188188 deriving (Show , Eq )
189189
190190-- | Accessors for JSPropertyAccessor is either 'get' or 'set'.
@@ -209,15 +209,15 @@ data JSNonEmptyList a
209209 deriving Eq
210210
211211data JSArguments
212- = JSArguments JSAnnot (JSList JSNode ) JSAnnot -- ^ lb, args, rb
212+ = JSArguments JSAnnot (JSList JSExpression ) JSAnnot -- ^ lb, args, rb
213213 deriving (Show , Eq )
214214
215- -- Strip out the location info, leaving the original JSNode text representation
215+ -- Strip out the location info, leaving the original JSExpression text representation
216216showStripped :: JSAST -> String
217217showStripped (JSSourceElementsTop xs) = " JSSourceElementsTop " ++ ssts xs
218218
219219
220- ss :: JSNode -> String
220+ ss :: JSExpression -> String
221221ss (JSArrayLiteral _lb xs _rb) = " JSArrayLiteral " ++ sss xs
222222ss (JSAssignExpression lhs op rhs) = " JSExpression " ++ ss lhs ++ " " ++ sopa op ++ " " ++ ss rhs
223223ss (JSCallExpression ex xs) = " JSExpression " ++ ss ex ++ " JSCallExpression \" ()\" " ++ ssa xs
@@ -248,7 +248,7 @@ ss (JSRegEx _ s) = "JSRegEx " ++ show s
248248ss (JSStringLiteral _ c s) = " JSStringLiteral " ++ show c ++ " " ++ show s
249249ss (JSUnaryExpression op x) = " JSUnaryExpression " ++ suop op ++ ss x
250250
251- sss :: [JSNode ] -> String
251+ sss :: [JSExpression ] -> String
252252sss xs = " [" ++ commaJoin (map ss xs) ++ " ]"
253253
254254-- The test suite expects operators to be double quoted.
@@ -382,7 +382,7 @@ instance Show JSIdent where
382382 show (JSIdentName _ s) = " JSIdentifier " ++ show s
383383 show JSIdentNone = " "
384384
385- ssme :: Maybe JSNode -> String
385+ ssme :: Maybe JSExpression -> String
386386ssme Nothing = " "
387387ssme (Just e) = ss e
388388
0 commit comments