Improve error message when an unknown SWIG directive is used

This previously gave the cryptic "Error: Syntax error in input(1).", but
now gives "Error: Unknown directive '%foo'."
This commit is contained in:
Olly Betts 2015-01-08 12:07:54 +13:00
commit 04715f74e2
6 changed files with 29 additions and 2 deletions

View file

@ -27,6 +27,7 @@ extern "C" {
extern int cparse_cplusplus;
extern int cparse_cplusplusout;
extern int cparse_start_line;
extern String *cparse_unknown_directive;
extern void Swig_cparse_cplusplus(int);
extern void Swig_cparse_cplusplusout(int);

View file

@ -40,6 +40,9 @@ int cparse_cplusplus = 0;
/* Generate C++ compatible code when wrapping C code */
int cparse_cplusplusout = 0;
/* To allow better error reporting */
String *cparse_unknown_directive = 0;
/* Private vars */
static int scan_init = 0;
static int num_brace = 0;
@ -801,8 +804,11 @@ int yylex(void) {
if (strcmp(yytext, "inline") == 0)
return (yylex());
/* SWIG directives */
} else {
Delete(cparse_unknown_directive);
cparse_unknown_directive = NULL;
/* SWIG directives */
if (strcmp(yytext, "%module") == 0)
return (MODULE);
if (strcmp(yytext, "%insert") == 0)
@ -878,6 +884,9 @@ int yylex(void) {
}
if (strcmp(yytext, "%warn") == 0)
return (WARN);
/* Note down the apparently unknown directive for error reporting. */
cparse_unknown_directive = Swig_copy_string(yytext);
}
/* Have an unknown identifier, as a last step, we'll do a typedef lookup on it. */

View file

@ -1510,7 +1510,11 @@ declaration : swig_directive { $$ = $1; }
| SEMI { $$ = 0; }
| error {
$$ = 0;
Swig_error(cparse_file, cparse_line,"Syntax error in input(1).\n");
if (cparse_unknown_directive) {
Swig_error(cparse_file, cparse_line, "Unknown directive '%s'.\n", cparse_unknown_directive);
} else {
Swig_error(cparse_file, cparse_line, "Syntax error in input(1).\n");
}
exit(1);
}
/* Out of class constructor/destructor declarations */