Skip to content

Commit e01c2b0

Browse files
authored
parser: use annotate-snippets in parser errors (#751)
instead of: ``` ERROR@124: unexpected trailing comma ``` we now show ``` error[syntax-error]: unexpected trailing comma β•­β–Έ 4 β”‚ array['a', 'b', 'c',] as y, β•°β•΄ ━ ``` which should make debugging test errors a little easier
1 parent badfde1 commit e01c2b0

21 files changed

+368
-91
lines changed

β€ŽCargo.lockβ€Ž

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žcrates/squawk_parser/Cargo.tomlβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ dir-test.workspace = true
2424
camino.workspace = true
2525
pg_query.workspace = true
2626
xshell.workspace = true
27+
annotate-snippets.workspace = true
2728

2829
[lints]
2930
workspace = true

β€Žcrates/squawk_parser/tests/snapshots/tests__alter_foreign_data_wrapper_err.snapβ€Ž

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@ SOURCE_FILE
1919
SEMICOLON ";"
2020
WHITESPACE "\n"
2121
---
22-
ERROR@46: Missing alter foreign data wrapper option or action.
22+
error[syntax-error]: Missing alter foreign data wrapper option or action.
23+
β•­β–Έ
24+
2 β”‚ alter foreign data wrapper w;
25+
β•°β•΄ ━

β€Žcrates/squawk_parser/tests/snapshots/tests__alter_sequence_err.snapβ€Ž

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@ SOURCE_FILE
1717
SEMICOLON ";"
1818
WHITESPACE "\n"
1919
---
20-
ERROR@34: expected ALTER SEQUENCE option
20+
error[syntax-error]: expected ALTER SEQUENCE option
21+
β•­β–Έ
22+
2 β”‚ alter sequence s;
23+
β•°β•΄ ━

β€Žcrates/squawk_parser/tests/snapshots/tests__alter_server_err.snapβ€Ž

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ SOURCE_FILE
1515
SEMICOLON ";"
1616
WHITESPACE "\n"
1717
---
18-
ERROR@32: expected ALTER SERVER option
18+
error[syntax-error]: expected ALTER SERVER option
19+
β•­β–Έ
20+
2 β”‚ alter server s;
21+
β•°β•΄ ━

β€Žcrates/squawk_parser/tests/snapshots/tests__alter_table_err.snapβ€Ž

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,31 @@ SOURCE_FILE
210210
SEMICOLON ";"
211211
WHITESPACE "\n"
212212
---
213-
ERROR@23: expected command, found ADD_KW
214-
ERROR@27: expected command, found COLUMN_KW
215-
ERROR@34: expected command, found IDENT
216-
ERROR@38: expected command, found BOOLEAN_KW
217-
ERROR@175: missing comma
218-
ERROR@505: expected COMMA
219-
ERROR@570: unexpected comma
213+
error[syntax-error]: expected command, found ADD_KW
214+
β•­β–Έ
215+
2 β”‚ add column foo boolean;
216+
╰╴━
217+
error[syntax-error]: expected command, found COLUMN_KW
218+
β•­β–Έ
219+
2 β”‚ add column foo boolean;
220+
β•°β•΄ ━
221+
error[syntax-error]: expected command, found IDENT
222+
β•­β–Έ
223+
2 β”‚ add column foo boolean;
224+
β•°β•΄ ━
225+
error[syntax-error]: expected command, found BOOLEAN_KW
226+
β•­β–Έ
227+
2 β”‚ add column foo boolean;
228+
β•°β•΄ ━
229+
error[syntax-error]: missing comma
230+
β•­β–Έ
231+
8 β”‚ validate constraint foo validate constraint b ;
232+
β•°β•΄ ━
233+
error[syntax-error]: expected COMMA
234+
β•­β–Έ
235+
16 β”‚ alter c set (a b = 1);
236+
β•°β•΄ ━
237+
error[syntax-error]: unexpected comma
238+
β•­β–Έ
239+
20 β”‚ alter c set (a, , b = 1);
240+
β•°β•΄ ━

β€Žcrates/squawk_parser/tests/snapshots/tests__copy_err.snapβ€Ž

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,11 @@ SOURCE_FILE
4343
SEMICOLON ";"
4444
WHITESPACE "\n"
4545
---
46-
ERROR@36: expected COMMA
47-
ERROR@79: expected COMMA
46+
error[syntax-error]: expected COMMA
47+
β•­β–Έ
48+
2 β”‚ copy x (i y) from '/tmp/input.file' (on_error ignore log_verbosity verbose);
49+
β•°β•΄ ━
50+
error[syntax-error]: expected COMMA
51+
β•­β–Έ
52+
2 β”‚ copy x (i y) from '/tmp/input.file' (on_error ignore log_verbosity verbose);
53+
β•°β•΄ ━

β€Žcrates/squawk_parser/tests/snapshots/tests__create_function_err.snapβ€Ž

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,23 @@ SOURCE_FILE
129129
FUNCTION_KW "function"
130130
WHITESPACE "\n\n"
131131
---
132-
ERROR@58: expected COMMA
133-
ERROR@121: expected COMMA
134-
ERROR@249: expected path name
135-
ERROR@249: expected param list
132+
error[syntax-error]: expected COMMA
133+
β•­β–Έ
134+
3 β”‚ returns table (a text b int)
135+
β•°β•΄ ━
136+
error[syntax-error]: expected COMMA
137+
β•­β–Έ
138+
6 β”‚ create function foo(arg float = 1 int4 = 4)
139+
β•°β•΄ ━
140+
error[syntax-error]: expected path name
141+
β•­β–Έ
142+
13 β”‚ create function
143+
β”‚ ┏━━━━━━━━━━━━━━━━┛
144+
14 β”‚ ┃
145+
╰╴┗━┛
146+
error[syntax-error]: expected param list
147+
β•­β–Έ
148+
13 β”‚ create function
149+
β”‚ ┏━━━━━━━━━━━━━━━━┛
150+
14 β”‚ ┃
151+
╰╴┗━┛

β€Žcrates/squawk_parser/tests/snapshots/tests__create_index_err.snapβ€Ž

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,7 @@ SOURCE_FILE
4444
SEMICOLON ";"
4545
WHITESPACE "\n"
4646
---
47-
ERROR@51: expected COMMA
47+
error[syntax-error]: expected COMMA
48+
β•­β–Έ
49+
2 β”‚ create index i on t (a nulls first b nulls first);
50+
β•°β•΄ ━

β€Žcrates/squawk_parser/tests/snapshots/tests__create_table_err.snapβ€Ž

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -673,16 +673,57 @@ SOURCE_FILE
673673
SEMICOLON ";"
674674
WHITESPACE "\n"
675675
---
676-
ERROR@39: expected path name
677-
ERROR@143: unexpected trailing comma
678-
ERROR@197: unexpected comma
679-
ERROR@198: unexpected comma
680-
ERROR@199: unexpected comma
681-
ERROR@200: unexpected comma
682-
ERROR@201: unexpected comma
683-
ERROR@1011: expected COMMA
684-
ERROR@1032: expected COMMA
685-
ERROR@1116: expected COMMA
686-
ERROR@1119: expected COMMA
687-
ERROR@1226: expected COMMA
688-
ERROR@1268: expected SEMICOLON
676+
error[syntax-error]: expected path name
677+
β•­β–Έ
678+
2 β”‚ create table (
679+
β•°β•΄ ━
680+
error[syntax-error]: unexpected trailing comma
681+
β•­β–Έ
682+
10 β”‚ create table t (a text,);
683+
β•°β•΄ ━
684+
error[syntax-error]: unexpected comma
685+
β•­β–Έ
686+
13 β”‚ create table t (,,,,,);
687+
β•°β•΄ ━
688+
error[syntax-error]: unexpected comma
689+
β•­β–Έ
690+
13 β”‚ create table t (,,,,,);
691+
β•°β•΄ ━
692+
error[syntax-error]: unexpected comma
693+
β•­β–Έ
694+
13 β”‚ create table t (,,,,,);
695+
β•°β•΄ ━
696+
error[syntax-error]: unexpected comma
697+
β•­β–Έ
698+
13 β”‚ create table t (,,,,,);
699+
β•°β•΄ ━
700+
error[syntax-error]: unexpected comma
701+
β•­β–Έ
702+
13 β”‚ create table t (,,,,,);
703+
β•°β•΄ ━
704+
error[syntax-error]: expected COMMA
705+
β•­β–Έ
706+
51 β”‚ for values from ('2024-01-01' 1) to ('2024-04-01' 5);
707+
β•°β•΄ ━
708+
error[syntax-error]: expected COMMA
709+
β•­β–Έ
710+
51 β”‚ for values from ('2024-01-01' 1) to ('2024-04-01' 5);
711+
β•°β•΄ ━
712+
error[syntax-error]: expected COMMA
713+
β•­β–Έ
714+
55 β”‚ for values in (1 2 3);
715+
β•°β•΄ ━
716+
error[syntax-error]: expected COMMA
717+
β•­β–Έ
718+
55 β”‚ for values in (1 2 3);
719+
β•°β•΄ ━
720+
error[syntax-error]: expected COMMA
721+
β•­β–Έ
722+
61 β”‚ exclude using btree ( a with buzz.> b with <)
723+
β•°β•΄ ━
724+
error[syntax-error]: expected SEMICOLON
725+
β•­β–Έ
726+
66 β”‚ )
727+
β”‚ ┏━━┛
728+
67 β”‚ ┃ -- ^ missing semi
729+
╰╴┗━┛

0 commit comments

Comments
Β (0)