@@ -89,6 +89,7 @@ SHARE return 'SHARE'
89
89
MODE return ' MODE'
90
90
OJ return ' OJ'
91
91
LIMIT return ' LIMIT'
92
+ UNION return ' UNION'
92
93
93
94
"," return ' ,'
94
95
"=" return ' ='
@@ -159,8 +160,32 @@ LIMIT return 'LIMIT'
159
160
%% /* language grammar */
160
161
161
162
main
162
- : selectClause EOF { return {nodeType: ' Main' , value: $1 }; }
163
- | selectClause ';' EOF { return {nodeType: ' Main' , value: $1 , hasSemicolon: true }; }
163
+ : selectClause semicolonOpt EOF { return {nodeType: ' Main' , value: $1 , hasSemicolon: $2 }; }
164
+ | unionClause semicolonOpt EOF { return {nodeType: ' Main' , value: $1 , hasSemicolon: $2 }; }
165
+ ;
166
+
167
+ semicolonOpt
168
+ : ';' { $$ = true }
169
+ | { $$ = false }
170
+ ;
171
+
172
+ unionClause
173
+ : unionClauseNotParenthesized { $$ = $1 }
174
+ | unionClauseParenthesized { $$ = $1 }
175
+ ;
176
+
177
+ unionClauseParenthesized
178
+ : selectClauseParenthesized UNION distinctOpt selectClauseParenthesized order_by_opt limit_opt { $$ = { type: ' Union' , left: $1 , distinctOpt: $3 , right: $4 , orderBy: $5 , limit: $6 }; }
179
+ | selectClauseParenthesized UNION distinctOpt unionClauseParenthesized order_by_opt limit_opt { $$ = { type: ' Union' , left: $1 , distinctOpt: $3 , right: $4 , orderBy: $5 , limit: $6 } }
180
+ ;
181
+
182
+ selectClauseParenthesized
183
+ : '(' selectClause ')' { $$ = { type: ' SelectParenthesized' , value: $2 } }
184
+ ;
185
+
186
+ unionClauseNotParenthesized
187
+ : selectClause UNION distinctOpt selectClause { $$ = { type: ' Union' , left: $1 , distinctOpt: $3 , right: $4 } }
188
+ | selectClause UNION distinctOpt unionClauseNotParenthesized { $$ = { type: ' Union' , left: $1 , distinctOpt: $3 , right: $4 } }
164
189
;
165
190
166
191
selectClause
0 commit comments