Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
2,026 changes: 1,052 additions & 974 deletions src/parser/bison_parser.cpp

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions src/parser/bison_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
extern int hsql_debug;
#endif
/* "%code requires" blocks. */
#line 35 "bison_parser.y" /* yacc.c:1915 */
#line 35 "bison_parser.y" /* yacc.c:1909 */

// %code requires block

Expand All @@ -72,7 +72,7 @@ extern int hsql_debug;
} \
}

#line 76 "bison_parser.h" /* yacc.c:1915 */
#line 76 "bison_parser.h" /* yacc.c:1909 */

/* Token type. */
#ifndef HSQL_TOKENTYPE
Expand Down Expand Up @@ -218,7 +218,7 @@ extern int hsql_debug;

union HSQL_STYPE
{
#line 95 "bison_parser.y" /* yacc.c:1915 */
#line 95 "bison_parser.y" /* yacc.c:1909 */

double fval;
int64_t ival;
Expand All @@ -241,6 +241,8 @@ union HSQL_STYPE
hsql::TableName table_name;
hsql::TableRef* table;
hsql::Expr* expr;
hsql::SelectStatement* setStatement;
hsql::SetDescription* setType;
hsql::OrderDescription* order;
hsql::OrderType order_type;
hsql::LimitDescription* limit;
Expand All @@ -257,7 +259,7 @@ union HSQL_STYPE
std::vector<hsql::Expr*>* expr_vec;
std::vector<hsql::OrderDescription*>* order_vec;

#line 261 "bison_parser.h" /* yacc.c:1915 */
#line 263 "bison_parser.h" /* yacc.c:1909 */
};

typedef union HSQL_STYPE HSQL_STYPE;
Expand Down
58 changes: 25 additions & 33 deletions src/parser/bison_parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ int yyerror(YYLTYPE* llocp, SQLParserResult* result, yyscan_t scanner, const cha
hsql::TableName table_name;
hsql::TableRef* table;
hsql::Expr* expr;
hsql::SelectStatement* setStatement;
hsql::SetDescription* setType;
hsql::OrderDescription* order;
hsql::OrderType order_type;
hsql::LimitDescription* limit;
Expand Down Expand Up @@ -180,7 +182,7 @@ int yyerror(YYLTYPE* llocp, SQLParserResult* result, yyscan_t scanner, const cha
%type <statement> statement preparable_statement
%type <exec_stmt> execute_statement
%type <prep_stmt> prepare_statement
%type <select_stmt> select_statement select_with_paren select_no_paren select_clause select_paren_or_clause
%type <select_stmt> select_statement select_with_paren select_no_paren select_clause select_paren_or_clause select_set
%type <import_stmt> import_statement
%type <create_stmt> create_statement
%type <insert_stmt> insert_statement
Expand All @@ -200,6 +202,7 @@ int yyerror(YYLTYPE* llocp, SQLParserResult* result, yyscan_t scanner, const cha
%type <expr> comp_expr opt_where join_condition opt_having case_expr case_list in_expr hint
%type <expr> array_expr array_index null_literal
%type <limit> opt_limit opt_top
%type <setType> set_operator
%type <order> order_desc
%type <order_type> opt_order_type
%type <column_t> column_def
Expand Down Expand Up @@ -569,14 +572,11 @@ update_clause:
select_statement:
select_with_paren
| select_no_paren
| select_with_paren set_operator select_paren_or_clause opt_order opt_limit {
// TODO: allow multiple unions (through linked list)
// TODO: capture type of set_operator
| select_set set_operator select_paren_or_clause opt_order opt_limit {
// TODO: might overwrite order and limit of first select here
$$ = $1;
$$->unionSelect = $3;
$$->order = $4;

$$ = MakeOrAppendSetList($1, $2, $3);
$$->order = $4;

// Limit could have been set by TOP.
if ($5 != nullptr) {
delete $$->limit;
Expand All @@ -585,9 +585,20 @@ select_statement:
}
;

select_set:
select_paren_or_clause
| select_set set_operator select_paren_or_clause {
$$ = MakeOrAppendSetList($1, $2, $3);
}

;

select_with_paren:
'(' select_no_paren ')' { $$ = $2; }
| '(' select_with_paren ')' { $$ = $2; }
| '(' select_set set_operator select_paren_or_clause ')' {
$$ = MakeOrAppendSetList($2, $3, $4);
}
;

select_paren_or_clause:
Expand All @@ -606,36 +617,17 @@ select_no_paren:
$$->limit = $3;
}
}
| select_clause set_operator select_paren_or_clause opt_order opt_limit {
// TODO: allow multiple unions (through linked list)
// TODO: capture type of set_operator
// TODO: might overwrite order and limit of first select here
$$ = $1;
$$->unionSelect = $3;
$$->order = $4;

// Limit could have been set by TOP.
if ($5 != nullptr) {
delete $$->limit;
$$->limit = $5;
}
}
;

set_operator:
set_type opt_all
UNION ALL { $$ = new SetDescription(kSetUnion, true); }
| INTERSECT ALL { $$ = new SetDescription(kSetIntersect, true); }
| EXCEPT ALL { $$ = new SetDescription(kSetExcept, true); }
| UNION { $$ = new SetDescription(kSetUnion, false); }
| INTERSECT { $$ = new SetDescription(kSetIntersect, false); }
| EXCEPT { $$ = new SetDescription(kSetExcept, false); }
;

set_type:
UNION
| INTERSECT
| EXCEPT
;

opt_all:
ALL
| /* empty */
;

select_clause:
SELECT opt_top opt_distinct select_list from_clause opt_where opt_group {
Expand Down
Loading