From e62a2cf723b0a0830e066468c7a7cac4d3445136 Mon Sep 17 00:00:00 2001 From: An-Cheng Huang Date: Wed, 6 Feb 2008 15:06:53 -0800 Subject: make parse error message more useful --- src/cli_def.l | 16 ++++++++++++++-- src/cli_parse.y | 5 +++-- 2 files changed, 17 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/cli_def.l b/src/cli_def.l index 3158a0f..07c9c68 100644 --- a/src/cli_def.l +++ b/src/cli_def.l @@ -269,9 +269,11 @@ RE_ACT_FIELD (help|syntax|commit|delete|update|activate|create|begin|end|comp_he #[^\n]*\n { /* comment */ + ++yy_cli_def_lineno; } \n { + ++yy_cli_def_lineno; return EOL; } @@ -302,6 +304,7 @@ RE_ACT_FIELD (help|syntax|commit|delete|update|activate|create|begin|end|comp_he } \\\n { + ++yy_cli_def_lineno; /* continuation */ } @@ -352,7 +355,10 @@ RE_ACT_FIELD (help|syntax|commit|delete|update|activate|create|begin|end|comp_he free(tmp); } -\n { /* skip the \n */ } +\n { + /* skip the \n */ + ++yy_cli_def_lineno; + } <> { BEGIN(INITIAL); @@ -372,6 +378,9 @@ RE_ACT_FIELD (help|syntax|commit|delete|update|activate|create|begin|end|comp_he } \n?.* { + if (yy_cli_def_text[0] == '\n') { + ++yy_cli_def_lineno; + } append_action(yy_cli_def_text); } @@ -391,7 +400,10 @@ RE_ACT_FIELD (help|syntax|commit|delete|update|activate|create|begin|end|comp_he [ \t]+ { /* space */ } -\\\n { /* continuation */ } +\\\n { + /* continuation */ + ++yy_cli_def_lineno; + } {RE_TYPE_NAME} { int i = 0; diff --git a/src/cli_parse.y b/src/cli_parse.y index fd472e9..6378bc9 100644 --- a/src/cli_parse.y +++ b/src/cli_parse.y @@ -7,6 +7,7 @@ #include "cli_val.h" extern int yy_cli_def_lineno; +extern char *yy_cli_def_text; static vtw_def *parse_defp; static int parse_status; static boolean cli_def_type_only=0; /*{ if (cli_def_type_only) YYACCEPT;}*/ @@ -197,8 +198,8 @@ int parse_def(vtw_def *defp, char *path, boolean type_only) static void cli_deferror(const char *s) { - printf("Error: %s in file %s, line %d\n",s, parse_path, - yy_cli_def_lineno); + printf("Error: %s in file [%s], line %d, last token [%s]\n",s, parse_path, + yy_cli_def_lineno, yy_cli_def_text); } void yy_cli_parse_error(const char *s) -- cgit v1.2.3