Skip to content

Commit ed79308

Browse files
committed
parser: cleanup expr parsing error handling
we don't need to report errors manually, the expr function already does that for us.
1 parent ab798b0 commit ed79308

File tree

1 file changed

+42
-102
lines changed

1 file changed

+42
-102
lines changed

crates/squawk_parser/src/grammar.rs

Lines changed: 42 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ fn tuple_expr(p: &mut Parser<'_>) -> CompletedMarker {
188188
fn case_expr(p: &mut Parser<'_>) -> CompletedMarker {
189189
let m = p.start();
190190
p.expect(CASE_KW);
191-
if !p.at(WHEN_KW) && expr(p).is_none() {
192-
p.error("expected an expression");
191+
if !p.at(WHEN_KW) {
192+
expr(p);
193193
}
194194
when_clause_list(p);
195195
opt_else_clause(p);
@@ -256,9 +256,7 @@ fn extract_fn(p: &mut Parser<'_>) -> CompletedMarker {
256256
p.expect(L_PAREN);
257257
extract_arg(p);
258258
p.expect(FROM_KW);
259-
if expr(p).is_none() {
260-
p.error("expected an expression");
261-
}
259+
expr(p);
262260
p.expect(R_PAREN);
263261
let m = m.complete(p, EXTRACT_FN).precede(p);
264262
opt_agg_clauses(p);
@@ -276,19 +274,13 @@ fn overlay_fn(p: &mut Parser<'_>) -> CompletedMarker {
276274
p.expect(OVERLAY_KW);
277275
p.expect(L_PAREN);
278276
if !p.at(R_PAREN) {
279-
if expr(p).is_none() {
280-
p.error("expected an expression");
281-
}
277+
expr(p);
282278
if p.eat(PLACING_KW) {
283-
if expr(p).is_none() {
284-
p.error("expected an expression");
285-
}
279+
expr(p);
286280
p.expect(FROM_KW);
287-
if expr(p).is_none() {
288-
p.error("expected an expression");
289-
}
290-
if p.eat(FOR_KW) && expr(p).is_none() {
291-
p.error("expected an expression");
281+
expr(p);
282+
if p.eat(FOR_KW) {
283+
expr(p);
292284
}
293285
} else if p.eat(COMMA) {
294286
opt_expr_list(p);
@@ -321,13 +313,9 @@ fn position_fn(p: &mut Parser<'_>) -> CompletedMarker {
321313
let m = p.start();
322314
p.expect(POSITION_KW);
323315
p.expect(L_PAREN);
324-
if b_expr(p).is_none() {
325-
p.error("expected an expression");
326-
}
316+
b_expr(p);
327317
p.expect(IN_KW);
328-
if b_expr(p).is_none() {
329-
p.error("expected an expression");
330-
}
318+
b_expr(p);
331319
p.expect(R_PAREN);
332320
let m = m.complete(p, POSITION_FN).precede(p);
333321
opt_agg_clauses(p);
@@ -379,40 +367,32 @@ fn substring_fn(p: &mut Parser<'_>) -> CompletedMarker {
379367
let m = p.start();
380368
p.expect(SUBSTRING_KW);
381369
p.expect(L_PAREN);
382-
if expr(p).is_none() {
383-
p.error("expected an expression");
384-
}
370+
expr(p);
385371
match p.current() {
386372
// FOR a_expr FROM a_expr
387373
// FOR a_expr
388374
FOR_KW => {
389375
p.bump(FOR_KW);
390-
if expr(p).is_none() {
391-
p.error("expected an expression");
392-
}
376+
expr(p);
393377
// [ from expr ]
394-
if p.eat(FROM_KW) && expr(p).is_none() {
395-
p.error("expected an expression");
378+
if p.eat(FROM_KW) {
379+
expr(p);
396380
}
397381
}
398382
// FROM a_expr
399383
// FROM a_expr FOR a_expr
400384
FROM_KW => {
401385
p.bump(FROM_KW);
402-
if expr(p).is_none() {
403-
p.error("expected an expression");
404-
}
386+
expr(p);
405387
// [ for expr ]
406-
if p.eat(FOR_KW) && expr(p).is_none() {
407-
p.error("expected an expression");
388+
if p.eat(FOR_KW) {
389+
expr(p);
408390
}
409391
}
410392
// SIMILAR a_expr ESCAPE a_expr
411393
SIMILAR_KW => {
412394
p.bump(SIMILAR_KW);
413-
if expr(p).is_none() {
414-
p.error("expected an expression");
415-
}
395+
expr(p);
416396
}
417397
_ if p.eat(COMMA) => {
418398
opt_expr_list(p);
@@ -807,9 +787,7 @@ fn atom_expr(p: &mut Parser<'_>) -> Option<CompletedMarker> {
807787
let m = p.start();
808788
p.bump_any();
809789
p.bump(L_PAREN);
810-
if expr(p).is_none() {
811-
p.error("expected an expression");
812-
}
790+
expr(p);
813791
p.expect(AS_KW);
814792
type_name(p);
815793
opt_collate(p);
@@ -1894,9 +1872,7 @@ fn opt_type_name_with(p: &mut Parser<'_>, type_args_enabled: bool) -> Option<Com
18941872
TIMESTAMP_KW | TIME_KW => {
18951873
p.bump_any();
18961874
if p.eat(L_PAREN) {
1897-
if expr(p).is_none() {
1898-
p.error("expected an expression");
1899-
}
1875+
expr(p);
19001876
p.expect(R_PAREN);
19011877
}
19021878
opt_with_timezone(p);
@@ -2151,13 +2127,9 @@ fn between_expr(p: &mut Parser<'_>) -> CompletedMarker {
21512127
p.eat(NOT_KW);
21522128
p.expect(BETWEEN_KW);
21532129
p.eat(SYMMETRIC_KW);
2154-
if bexpr(p).is_none() {
2155-
p.error("expected an expression");
2156-
}
2130+
bexpr(p);
21572131
p.expect(AND_KW);
2158-
if bexpr(p).is_none() {
2159-
p.error("expected an expression");
2160-
}
2132+
bexpr(p);
21612133
m.complete(p, BETWEEN_EXPR)
21622134
}
21632135

@@ -2193,9 +2165,7 @@ fn opt_filter_clause(p: &mut Parser<'_>) {
21932165
p.expect(FILTER_KW);
21942166
p.expect(L_PAREN);
21952167
p.expect(WHERE_KW);
2196-
if expr(p).is_none() {
2197-
p.error("expected an expression");
2198-
}
2168+
expr(p);
21992169
p.expect(R_PAREN);
22002170
m.complete(p, FILTER_CLAUSE);
22012171
}
@@ -2248,28 +2218,22 @@ fn index_expr(p: &mut Parser<'_>, lhs: CompletedMarker) -> CompletedMarker {
22482218
return m.complete(p, SLICE_EXPR);
22492219
} else {
22502220
// foo[:b]
2251-
if expr(p).is_none() {
2252-
p.error("expected an expression");
2253-
}
2221+
expr(p);
22542222
p.expect(R_BRACK);
22552223
return m.complete(p, SLICE_EXPR);
22562224
}
22572225
}
22582226
// foo[a]
22592227
// foo[a:]
22602228
// foo[a:b]
2261-
if expr(p).is_none() {
2262-
p.error("expected an expression");
2263-
}
2229+
expr(p);
22642230
if p.eat(COLON) {
22652231
// foo[a:]
22662232
if p.eat(R_BRACK) {
22672233
return m.complete(p, SLICE_EXPR);
22682234
}
22692235
// foo[a:b]
2270-
if expr(p).is_none() {
2271-
p.error("expected an expression");
2272-
}
2236+
expr(p);
22732237
p.expect(R_BRACK);
22742238
return m.complete(p, SLICE_EXPR);
22752239
}
@@ -2655,13 +2619,9 @@ fn opt_cycle_clause(p: &mut Parser<'_>) {
26552619
p.expect(SET_KW);
26562620
name_ref(p);
26572621
if p.eat(TO_KW) {
2658-
if expr(p).is_none() {
2659-
p.error("expected an expression");
2660-
}
2622+
expr(p);
26612623
p.expect(DEFAULT_KW);
2662-
if expr(p).is_none() {
2663-
p.error("expected an expression");
2664-
}
2624+
expr(p);
26652625
}
26662626
p.expect(USING_KW);
26672627
name_ref(p);
@@ -2874,8 +2834,8 @@ fn opt_fetch_clause(p: &mut Parser<'_>) -> Option<CompletedMarker> {
28742834
p.error("expected first or next");
28752835
}
28762836
// [ count ]
2877-
if !p.at(ROWS_KW) && !p.at(ROW_KW) && expr(p).is_none() {
2878-
p.error("expected an expression");
2837+
if !p.at(ROWS_KW) && !p.at(ROW_KW) {
2838+
expr(p);
28792839
}
28802840
// { ROW | ROWS }
28812841
if !p.eat(ROW_KW) {
@@ -2915,9 +2875,7 @@ fn sort_by_list(p: &mut Parser<'_>) {
29152875

29162876
fn sort_by(p: &mut Parser<'_>) {
29172877
let m = p.start();
2918-
if expr(p).is_none() {
2919-
p.error("expected an expression");
2920-
}
2878+
expr(p);
29212879
opt_sort_order(p);
29222880
opt_nulls_order(p);
29232881
m.complete(p, SORT_BY);
@@ -3473,9 +3431,7 @@ fn on_clause(p: &mut Parser<'_>) {
34733431
assert!(p.at(ON_KW));
34743432
let m = p.start();
34753433
p.bump(ON_KW);
3476-
if expr(p).is_none() {
3477-
p.error("expected an expression");
3478-
}
3434+
expr(p);
34793435
m.complete(p, ON_CLAUSE);
34803436
}
34813437

@@ -3885,9 +3841,7 @@ fn opt_constraint_inner(p: &mut Parser<'_>) -> Option<SyntaxKind> {
38853841
p.expect(ALWAYS_KW);
38863842
p.expect(AS_KW);
38873843
p.expect(L_PAREN);
3888-
if expr(p).is_none() {
3889-
p.error("expected an expression");
3890-
}
3844+
expr(p);
38913845
p.expect(R_PAREN);
38923846
opt_virtual_or_stored(p);
38933847
GENERATED_CONSTRAINT
@@ -3900,9 +3854,7 @@ fn opt_constraint_inner(p: &mut Parser<'_>) -> Option<SyntaxKind> {
39003854
}
39013855
p.expect(AS_KW);
39023856
if p.eat(L_PAREN) {
3903-
if expr(p).is_none() {
3904-
p.error("expected an expression");
3905-
}
3857+
expr(p);
39063858
p.expect(R_PAREN);
39073859
opt_virtual_or_stored(p);
39083860
} else {
@@ -4066,9 +4018,7 @@ fn opt_index_elem(p: &mut Parser<'_>) -> bool {
40664018
return false;
40674019
}
40684020
if p.eat(L_PAREN) {
4069-
if expr(p).is_none() {
4070-
p.error("expected an expression");
4071-
}
4021+
expr(p);
40724022
p.expect(R_PAREN);
40734023
} else {
40744024
if expr(p).is_none() {
@@ -4546,9 +4496,7 @@ fn opt_where_clause(p: &mut Parser<'_>) -> Option<CompletedMarker> {
45464496
}
45474497
let m = p.start();
45484498
p.bump(WHERE_KW);
4549-
if expr(p).is_none() {
4550-
p.error("expected an expression");
4551-
}
4499+
expr(p);
45524500
Some(m.complete(p, WHERE_CLAUSE))
45534501
}
45544502

@@ -4622,9 +4570,7 @@ fn opt_group_by_item(p: &mut Parser<'_>) -> Option<CompletedMarker> {
46224570
GROUPING_SETS
46234571
}
46244572
_ => {
4625-
if expr(p).is_none() {
4626-
p.error("expected an expression");
4627-
}
4573+
expr(p);
46284574
GROUPING_EXPR
46294575
}
46304576
};
@@ -4638,9 +4584,7 @@ fn opt_having_clause(p: &mut Parser<'_>) -> Option<CompletedMarker> {
46384584
}
46394585
let m = p.start();
46404586
p.bump(HAVING_KW);
4641-
if expr(p).is_none() {
4642-
p.error("expected an expression");
4643-
}
4587+
expr(p);
46444588
Some(m.complete(p, HAVING_CLAUSE))
46454589
}
46464590

@@ -4657,9 +4601,7 @@ fn frame_start_end(p: &mut Parser<'_>) {
46574601
p.bump_any();
46584602
}
46594603
_ => {
4660-
if expr(p).is_none() {
4661-
p.error("expected an expression");
4662-
}
4604+
expr(p);
46634605
if p.at(PRECEDING_KW) || p.at(FOLLOWING_KW) {
46644606
p.bump_any();
46654607
} else {
@@ -4768,8 +4710,8 @@ fn opt_limit_clause(p: &mut Parser<'_>) -> Option<CompletedMarker> {
47684710
m.abandon(p);
47694711
return None;
47704712
}
4771-
if !p.eat(ALL_KW) && expr(p).is_none() {
4772-
p.error("expected an expression");
4713+
if !p.eat(ALL_KW) {
4714+
expr(p);
47734715
}
47744716
Some(m.complete(p, LIMIT_CLAUSE))
47754717
}
@@ -4781,9 +4723,7 @@ fn opt_offset_clause(p: &mut Parser<'_>) -> Option<CompletedMarker> {
47814723
}
47824724
let m = p.start();
47834725
p.bump(OFFSET_KW);
4784-
if expr(p).is_none() {
4785-
p.error("expected an expression");
4786-
}
4726+
expr(p);
47874727
if p.at(ROW_KW) || p.at(ROWS_KW) {
47884728
p.bump_any();
47894729
}

0 commit comments

Comments
 (0)