Skip to content

Commit 67b4892

Browse files
committed
Improve syntax error messages
These will only do much good when we have better printing, but I figured this kind of thing should go in.
1 parent 5c61895 commit 67b4892

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

command-interface/parser.dylan

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ define class <command-parse-error> (<simple-error>)
1010
init-keyword: parser:;
1111
slot error-token :: <command-token>,
1212
init-keyword: token:;
13+
slot error-options :: <list>,
14+
init-keyword: options:;
1315
end class;
1416

1517
define class <command-ambiguous-error> (<command-parse-error>)
@@ -158,14 +160,16 @@ define method parser-advance (parser :: <command-parser>, token :: <command-toke
158160
format-string: "Unrecognized token \"%s\"",
159161
format-arguments: vector(token-string(token)),
160162
parser: parser,
161-
token: token));
163+
token: token,
164+
options: acceptable));
162165
// more than one: ambiguous token
163166
otherwise =>
164167
signal(make(<command-ambiguous-error>,
165168
format-string: "Ambiguous token \"%s\"",
166169
format-arguments: vector(token-string(token)),
167170
parser: parser,
168-
token: token));
171+
token: token,
172+
options: matches));
169173
end select;
170174
end method;
171175

command-interface/tty-cli.dylan

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ define method editor-execute (editor :: <tty-command-shell>)
4141
n-spaces(size(editor-prompt(editor))),
4242
command-annotate(src, token-srcloc(pe.error-token)),
4343
condition-to-string(pe));
44+
case
45+
instance?(pe, <command-ambiguous-error>) =>
46+
format-out("\nCan be interpreted as:\n");
47+
for(option in error-options(pe))
48+
format-out(" %=\n", option);
49+
end;
50+
instance?(pe, <command-unknown-error>) =>
51+
format-out("\nPossible options:\n");
52+
for(option in error-options(pe))
53+
format-out(" %=\n", option);
54+
end;
55+
end;
4456
exception (e :: <error>)
4557
// print condition and clear
4658
format-out("Error: %=\n", e);

0 commit comments

Comments
 (0)