Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: union grammar, to resolve grammar conflicts. #2
  • Loading branch information
albin3 committed Jul 9, 2019
commit 4724fab294d2277322306ed9df2957da1397d97c
29 changes: 27 additions & 2 deletions src/sqlParser.jison
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ SHARE return 'SHARE'
MODE return 'MODE'
OJ return 'OJ'
LIMIT return 'LIMIT'
UNION return 'UNION'

"," return ','
"=" return '='
Expand Down Expand Up @@ -159,8 +160,32 @@ LIMIT return 'LIMIT'
%% /* language grammar */

main
: selectClause EOF { return {nodeType: 'Main', value: $1}; }
| selectClause ';' EOF { return {nodeType: 'Main', value: $1, hasSemicolon: true}; }
: selectClause semicolonOpt EOF { return {nodeType: 'Main', value: $1, hasSemicolon: $2}; }
| unionClause semicolonOpt EOF { return {nodeType: 'Main', value: $1, hasSemicolon: $2}; }
;

semicolonOpt
: ';' { $$ = true }
| { $$ = false }
;

unionClause
: unionClauseNotParenthesized { $$ = $1 }
| unionClauseParenthesized { $$ = $1 }
;

unionClauseParenthesized
: selectClauseParenthesized UNION distinctOpt selectClauseParenthesized order_by_opt limit_opt { $$ = { type: 'Union', left: $1, distinctOpt: $3, right: $4, orderBy: $5, limit: $6 }; }
| selectClauseParenthesized UNION distinctOpt unionClauseParenthesized order_by_opt limit_opt { $$ = { type: 'Union', left: $1, distinctOpt: $3, right: $4, orderBy: $5, limit: $6 } }
;

selectClauseParenthesized
: '(' selectClause ')' { $$ = { type: 'SelectParenthesized', value: $2 } }
;

unionClauseNotParenthesized
: selectClause UNION distinctOpt selectClause { $$ = { type: 'Union', left: $1, distinctOpt: $3, right: $4 } }
| selectClause UNION distinctOpt unionClauseNotParenthesized { $$ = { type: 'Union', left: $1, distinctOpt: $3, right: $4 } }
;

selectClause
Expand Down