Skip to content

Commit 4724fab

Browse files
committed
feat: union grammar, to resolve grammar conflicts. #2
1 parent c2decc0 commit 4724fab

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

src/sqlParser.jison

+27-2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ SHARE return 'SHARE'
8989
MODE return 'MODE'
9090
OJ return 'OJ'
9191
LIMIT return 'LIMIT'
92+
UNION return 'UNION'
9293

9394
"," return ','
9495
"=" return '='
@@ -159,8 +160,32 @@ LIMIT return 'LIMIT'
159160
%% /* language grammar */
160161

161162
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 } }
164189
;
165190

166191
selectClause

0 commit comments

Comments
 (0)