Skip to content

Commit

Permalink
Add in a new function to try and make better IMCC error messages. Dum…
Browse files Browse the repository at this point in the history
…p whatever information we can get our hands on into the message, and hope it's enough. Or too much. or not enough.
  • Loading branch information
Whiteknight committed Jul 23, 2011
1 parent 166738c commit 05b0911
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
23 changes: 18 additions & 5 deletions compilers/imcc/imcc.l
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,6 @@ int yywrap(void* yyscanner) {

/* pop old frame */
if (imcc->frames->s.next) {
/* TODO: Double-check this */
pop_parser_state(imcc, yyscanner);
if (YYSTATE == INITIAL || YYSTATE == emit)
BEGIN(imcc->frames->s.pasm_file ? emit : INITIAL);
Expand Down Expand Up @@ -1378,15 +1377,29 @@ imcc_compile_buffer_safe(ARGMOD(imc_info_t *imcc), yyscan_t yyscanner,
return success;
}

static void
do_a_better_error_message(imc_info_t * imcc, void * yyscanner)
{
STRING * loc;
imcc->error_code = IMCC_PARSEFAIL_EXCEPTION;
if (imcc->frames && imcc->frames->is_macro)
loc = Parrot_sprintf_c(imcc->interp, "in macro '.%Ss' line %d",
imcc->frames->s.file, imcc->line);
else
loc = Parrot_sprintf_c(imcc->interp, "in file '%Ss' line %d",
imcc->frames->s.file, imcc->line);
imcc->error_message = Parrot_sprintf_c(imcc->interp,
"Unexpected parser exit. Unknown syntax error.\n"
"\tLast line reported is %d\n"
"\tLast file reported is %S", imcc->line, loc);
}

INTVAL
imcc_run_compilation(ARGMOD(imc_info_t *imcc), void *yyscanner) {
/* TODO: Kill this stuff and use Parrot exceptions exclusively */
IMCC_TRY(imcc->jump_buf, imcc->error_code) {
if (yyparse(yyscanner, imcc)) {
imcc->error_code = IMCC_PARSEFAIL_EXCEPTION;
/* TODO: Be slightly less unhelpful */
imcc->error_message = string_from_literal(imcc->interp,
"syntax error ... somewhere");
do_a_better_error_message(imcc, yyscanner);
return 0;
}

Expand Down
23 changes: 18 additions & 5 deletions compilers/imcc/imclexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -4911,7 +4911,6 @@ int yywrap(void* yyscanner) {

/* pop old frame */
if (imcc->frames->s.next) {
/* TODO: Double-check this */
pop_parser_state(imcc, yyscanner);
if (YYSTATE == INITIAL || YYSTATE == emit)
BEGIN(imcc->frames->s.pasm_file ? emit : INITIAL);
Expand Down Expand Up @@ -5560,15 +5559,29 @@ imcc_compile_buffer_safe(ARGMOD(imc_info_t *imcc), yyscan_t yyscanner,
return success;
}

static void
do_a_better_error_message(imc_info_t * imcc, void * yyscanner)
{
STRING * loc;
imcc->error_code = IMCC_PARSEFAIL_EXCEPTION;
if (imcc->frames && imcc->frames->is_macro)
loc = Parrot_sprintf_c(imcc->interp, "in macro '.%Ss' line %d",
imcc->frames->s.file, imcc->line);
else
loc = Parrot_sprintf_c(imcc->interp, "in file '%Ss' line %d",
imcc->frames->s.file, imcc->line);
imcc->error_message = Parrot_sprintf_c(imcc->interp,
"Unexpected parser exit. Unknown syntax error.\n"
"\tLast line reported is %d\n"
"\tLast file reported is %S", imcc->line, loc);
}

INTVAL
imcc_run_compilation(ARGMOD(imc_info_t *imcc), void *yyscanner) {
/* TODO: Kill this stuff and use Parrot exceptions exclusively */
IMCC_TRY(imcc->jump_buf, imcc->error_code) {
if (yyparse(yyscanner, imcc)) {
imcc->error_code = IMCC_PARSEFAIL_EXCEPTION;
/* TODO: Be slightly less unhelpful */
imcc->error_message = string_from_literal(imcc->interp,
"syntax error ... somewhere");
do_a_better_error_message(imcc, yyscanner);
return 0;
}

Expand Down

0 comments on commit 05b0911

Please sign in to comment.