Code

Merge branch 'collectd-4.2' into collectd-4.3
[collectd.git] / src / liboconfig / parser.y
index 8df2c6e5fb230eaed09db85d73e6ad8d5294a819..49cd139dbd76bd1e4505b3184194d6066a1be11b 100644 (file)
@@ -30,6 +30,7 @@ extern int yylineno;
 extern char *yytext;
 
 extern oconfig_item_t *ci_root;
+extern char           *c_file;
 %}
 
 %start entire_file
@@ -64,6 +65,9 @@ extern oconfig_item_t *ci_root;
 %type <sl> statement_list
 %type <ci> entire_file
 
+/* pass an verbose, specific error message to yyerror() */
+%error-verbose
+
 %%
 string:
        QUOTED_STRING           {$$ = unquote ($1);}
@@ -192,7 +196,15 @@ entire_file:
 %%
 static int yyerror (const char *s)
 {
-       fprintf (stderr, "Error in line %i near `%s': %s\n", yylineno, yytext, s);
+       char *text;
+
+       if (*yytext == '\n')
+               text = "<newline>";
+       else
+               text = yytext;
+
+       fprintf (stderr, "Parse error in file `%s', line %i near `%s': %s\n",
+               c_file, yylineno, text, s);
        return (-1);
 } /* int yyerror */