diff options
author | Demi Marie Obenour <demiobenour@gmail.com> | 2022-11-18 17:49:37 -0500 |
---|---|---|
committer | Demi Marie Obenour <demiobenour@gmail.com> | 2022-11-30 21:46:39 -0500 |
commit | 0d2140bba5887f07f14027a30af85d8f8ebc5c1f (patch) | |
tree | e4803696a3f5f538fbe5be04f05badd4f0cc8af4 /yacc | |
parent | d212a2421fe257008627ed23ee7752f841edf192 (diff) | |
download | ocaml-0d2140bba5887f07f14027a30af85d8f8ebc5c1f.tar.gz |
ocamlyacc: refactor error messages
This deletes a bunch of duplicated code.
Diffstat (limited to 'yacc')
-rw-r--r-- | yacc/error.c | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/yacc/error.c b/yacc/error.c index aaa396477d..ee71fa311e 100644 --- a/yacc/error.c +++ b/yacc/error.c @@ -77,39 +77,36 @@ static void print_pos(char *st_line, char *st_cptr) } -void syntax_error(int st_lineno, char *st_line, char *st_cptr) +static Noreturn void gen_error(int st_lineno, char *st_line, char *st_cptr, char *msg) { - fprintf(stderr, "File \"%s\", line %d: syntax error\n", - virtual_input_file_name, st_lineno); + fprintf(stderr, "File \"%s\", line %d: %s\n", + virtual_input_file_name, st_lineno, msg); print_pos(st_line, st_cptr); done(1); } +void syntax_error(int st_lineno, char *st_line, char *st_cptr) +{ + gen_error(st_lineno, st_line, st_cptr, "syntax error"); +} + + void unterminated_comment(int c_lineno, char *c_line, char *c_cptr) { - fprintf(stderr, "File \"%s\", line %d: unmatched /*\n", - virtual_input_file_name, c_lineno); - print_pos(c_line, c_cptr); - done(1); + gen_error(c_lineno, c_line, c_cptr, "unmatched /*"); } void unterminated_string(int s_lineno, char *s_line, char *s_cptr) { - fprintf(stderr, "File \"%s\", line %d: unterminated string\n", - virtual_input_file_name, s_lineno); - print_pos(s_line, s_cptr); - done(1); + gen_error(s_lineno, s_line, s_cptr, "unterminated string"); } void unterminated_text(int t_lineno, char *t_line, char *t_cptr) { - fprintf(stderr, "File \"%s\", line %d: unmatched %%{\n", - virtual_input_file_name, t_lineno); - print_pos(t_line, t_cptr); - done(1); + gen_error(t_lineno, t_line, t_cptr, "unmatched %{"); } |