@@ -12,10 +12,6 @@ namespace sqltoast {
12
12
// <query expression> ::=
13
13
// <non-join query expression>
14
14
// | <joined table>
15
- //
16
- // <query primary> ::=
17
- // <non-join query primary>
18
- // | <joined table>
19
15
bool parse_query_expression (
20
16
parse_context_t & ctx,
21
17
token_t & cur_tok,
@@ -107,14 +103,51 @@ bool parse_non_join_query_term(
107
103
parse_context_t & ctx,
108
104
token_t & cur_tok,
109
105
std::unique_ptr<query_term_t >& out) {
110
- std::unique_ptr<non_join_query_primary_t > njqp ;
106
+ std::unique_ptr<query_primary_t > query_primary ;
111
107
112
- if (! parse_non_join_query_primary (ctx, cur_tok, njqp ))
108
+ if (! parse_non_join_query_primary (ctx, cur_tok, query_primary ))
113
109
return false ;
114
110
// TODO(jaypipes): Handle INTERSECT
115
111
if (ctx.opts .disable_statement_construction )
116
112
return true ;
117
- out = std::make_unique<non_join_query_term_t >(njqp);
113
+ out = std::make_unique<non_join_query_term_t >(query_primary);
114
+ return true ;
115
+ }
116
+
117
+ // <query primary> ::=
118
+ // <non-join query primary>
119
+ // | <joined table>
120
+ bool parse_query_primary (
121
+ parse_context_t & ctx,
122
+ token_t & cur_tok,
123
+ std::unique_ptr<query_primary_t >& out) {
124
+ lexer_t & lex = ctx.lexer ;
125
+ parse_position_t start = lex.cursor ;
126
+ token_t start_tok = lex.current_token ;
127
+ std::unique_ptr<joined_table_t > joined_table;
128
+ if (parse_non_join_query_primary (ctx, cur_tok, out))
129
+ return true ;
130
+ if (ctx.result .code == PARSE_SYNTAX_ERROR)
131
+ return false ;
132
+
133
+ // Reset cursor to before parsing of joined table attempt.
134
+ lex.cursor = start;
135
+ lex.current_token = cur_tok = start_tok;
136
+ if (! parse_joined_table (ctx, cur_tok, joined_table))
137
+ goto err_expect_joined_table;
138
+ goto push_joined_table_primary;
139
+ err_expect_joined_table:
140
+ {
141
+ std::stringstream estr;
142
+ estr << " Expected <joined table> but found "
143
+ << cur_tok << std::endl;
144
+ create_syntax_error_marker (ctx, estr);
145
+ return false ;
146
+ }
147
+ push_joined_table_primary:
148
+ if (ctx.opts .disable_statement_construction )
149
+ return true ;
150
+ out = std::make_unique<joined_table_query_primary_t >(joined_table);
118
151
return true ;
119
152
}
120
153
@@ -129,7 +162,7 @@ bool parse_non_join_query_term(
129
162
bool parse_non_join_query_primary (
130
163
parse_context_t & ctx,
131
164
token_t & cur_tok,
132
- std::unique_ptr<non_join_query_primary_t >& out) {
165
+ std::unique_ptr<query_primary_t >& out) {
133
166
lexer_t & lex = ctx.lexer ;
134
167
parse_position_t start = lex.cursor ;
135
168
token_t start_tok = lex.current_token ;
0 commit comments