provide better parser output on error.

SVN revision: 58508
This commit is contained in:
Carsten Haitzler 2011-04-09 02:35:01 +00:00
parent 71b7acde90
commit a3d58eaddf
1 changed files with 69 additions and 11 deletions

View File

@ -84,6 +84,42 @@ static int verbatim_line1 = 0;
static int verbatim_line2 = 0;
static char *verbatim_str = NULL;
static void
err_show_stack(void)
{
char *s;
s = stack_id();
if (s)
{
printf("PARSE STACK:\n%s\n", s);
free(s);
}
else
printf("NO PARSE STACK\n");
}
static void
err_show_params(void)
{
Eina_List *l;
char *p;
printf("PARAMS:");
EINA_LIST_FOREACH(params, l, p)
{
printf(" %s", p);
}
printf("\n");
}
static void
err_show(void)
{
err_show_stack();
err_show_params();
}
static void
new_object(void)
{
@ -120,6 +156,7 @@ new_object(void)
ERR("%s: Error. %s:%i unhandled keyword %s",
progname, file_in, line - 1,
(char *)eina_list_data_get(eina_list_last(stack)));
err_show();
exit(-1);
}
free(id);
@ -150,6 +187,7 @@ new_statement(void)
ERR("%s: Error. %s:%i unhandled keyword %s",
progname, file_in, line - 1,
(char *)eina_list_data_get(eina_list_last(stack)));
err_show();
exit(-1);
}
free(id);
@ -433,6 +471,7 @@ stack_chop_top(void)
{
ERR("%s: Error. parse error %s:%i. } marker without matching { marker",
progname, file_in, line - 1);
err_show();
exit(-1);
}
}
@ -461,6 +500,7 @@ parse(char *data, off_t size)
{
ERR("%s: Error. parse error %s:%i. %c marker before ; marker",
progname, file_in, line - 1, *token);
err_show();
exit(-1);
}
else if (delim)
@ -472,6 +512,7 @@ parse(char *data, off_t size)
{
ERR("%s: Error. parse error %s:%i. } marker before ; marker",
progname, file_in, line - 1);
err_show();
exit(-1);
}
else
@ -499,6 +540,7 @@ parse(char *data, off_t size)
{
ERR("%s: Error. parse error %s:%i. { marker before ; marker",
progname, file_in, line - 1);
err_show();
exit(-1);
}
}
@ -582,6 +624,7 @@ parse(char *data, off_t size)
{
ERR("%s: Error. parse error %s:%i. { marker does not have matching } marker",
progname, file_in, line - 1);
err_show();
exit(-1);
}
new_object();
@ -666,7 +709,7 @@ compile(void)
p = strrchr(inc, '/');
if (!p) strcpy(inc, "./");
else *p = 0;
snprintf (tmpn, PATH_MAX, "%s/edje_cc.edc-tmp-XXXXXX", tmp_dir);
snprintf(tmpn, PATH_MAX, "%s/edje_cc.edc-tmp-XXXXXX", tmp_dir);
fd = mkstemp(tmpn);
if (fd >= 0)
{
@ -730,15 +773,14 @@ compile(void)
}
if (verbose)
{
INF("%s: Opening \"%s\" for input",
progname, file_in);
INF("%s: Opening \"%s\" for input", progname, file_in);
}
size = lseek(fd, 0, SEEK_END);
lseek(fd, 0, SEEK_SET);
data = malloc(size);
if (data && (read(fd, data, size) == size))
parse(data, size);
parse(data, size);
else
{
ERR("%s: Error. cannot read file \"%s\". %s",
@ -749,11 +791,13 @@ compile(void)
close(fd);
EINA_LIST_FOREACH(edje_file->styles, l, stl)
if (!stl->name)
{
ERR("%s: Error. style must have a name.", progname);
exit(-1);
}
{
if (!stl->name)
{
ERR("%s: Error. style must have a name.", progname);
exit(-1);
}
}
}
int
@ -778,6 +822,7 @@ is_num(int n)
{
ERR("%s: Error. %s:%i no parameter supplied as argument %i",
progname, file_in, line - 1, n + 1);
err_show();
exit(-1);
}
if (str[0] == 0) return 0;
@ -802,6 +847,7 @@ parse_str(int n)
{
ERR("%s: Error. %s:%i no parameter supplied as argument %i",
progname, file_in, line - 1, n + 1);
err_show();
exit(-1);
}
s = mem_strdup(str);
@ -837,6 +883,7 @@ _parse_enum(char *str, va_list va)
fprintf(stderr, "\n");
va_end(va2);
va_end(va);
err_show();
exit(-1);
}
@ -865,6 +912,7 @@ parse_enum(int n, ...)
{
ERR("%s: Error. %s:%i no parameter supplied as argument %i",
progname, file_in, line - 1, n + 1);
err_show();
exit(-1);
}
@ -902,6 +950,7 @@ parse_int(int n)
{
ERR("%s: Error. %s:%i no parameter supplied as argument %i",
progname, file_in, line - 1, n + 1);
err_show();
exit(-1);
}
i = my_atoi(str);
@ -919,6 +968,7 @@ parse_int_range(int n, int f, int t)
{
ERR("%s: Error. %s:%i no parameter supplied as argument %i",
progname, file_in, line - 1, n + 1);
err_show();
exit(-1);
}
i = my_atoi(str);
@ -926,6 +976,7 @@ parse_int_range(int n, int f, int t)
{
ERR("%s: Error. %s:%i integer %i out of range of %i to %i inclusive",
progname, file_in, line - 1, i, f, t);
err_show();
exit(-1);
}
return i;
@ -942,6 +993,7 @@ parse_bool(int n)
{
ERR("%s: Error. %s:%i no parameter supplied as argument %i",
progname, file_in, line - 1, n + 1);
err_show();
exit(-1);
}
@ -962,6 +1014,7 @@ parse_bool(int n)
{
ERR("%s: Error. %s:%i integer %i out of range of 0 to 1 inclusive",
progname, file_in, line - 1, i);
err_show();
exit(-1);
}
return i;
@ -978,6 +1031,7 @@ parse_float(int n)
{
ERR("%s: Error. %s:%i no parameter supplied as argument %i",
progname, file_in, line - 1, n + 1);
err_show();
exit(-1);
}
i = my_atof(str);
@ -995,6 +1049,7 @@ parse_float_range(int n, double f, double t)
{
ERR("%s: Error. %s:%i no parameter supplied as argument %i",
progname, file_in, line - 1, n + 1);
err_show();
exit(-1);
}
i = my_atof(str);
@ -1002,6 +1057,7 @@ parse_float_range(int n, double f, double t)
{
ERR("%s: Error. %s:%i float %3.3f out of range of %3.3f to %3.3f inclusive",
progname, file_in, line - 1, i, f, t);
err_show();
exit(-1);
}
return i;
@ -1014,8 +1070,9 @@ check_arg_count(int required_args)
if (num_args != required_args)
{
ERR("%s: Error. %s:%i got %i arguments, but expected %i",
progname, file_in, line - 1, num_args, required_args);
ERR("%s: Error. %s:%i got %i arguments, but expected %i",
progname, file_in, line - 1, num_args, required_args);
err_show();
exit(-1);
}
}
@ -1030,6 +1087,7 @@ check_min_arg_count(int min_required_args)
ERR("%s: Error. %s:%i got %i arguments, "
"but expected at least %i",
progname, file_in, line - 1, num_args, min_required_args);
err_show();
exit(-1);
}
}