@@ -89,6 +89,7 @@ SHARE return 'SHARE'
8989MODE return ' MODE'
9090OJ return ' OJ'
9191LIMIT return ' LIMIT'
92+ UNION return ' UNION'
9293
9394"," return ' ,'
9495"=" return ' ='
@@ -159,8 +160,32 @@ LIMIT return 'LIMIT'
159160%% /* language grammar */
160161
161162main
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 } }
164189 ;
165190
166191selectClause
0 commit comments