From: Charlie Brej Date: Sun, 30 Aug 2009 19:53:13 +0000 (+0100) Subject: [script] Keep the filename while scanning for parsing error messages X-Git-Tag: 0.7.2~24^2~9 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b5b0ace5325454c3e33df61096dccfe01450205c;p=thirdparty%2Fplymouth.git [script] Keep the filename while scanning for parsing error messages --- diff --git a/src/plugins/splash/script/Makefile.am b/src/plugins/splash/script/Makefile.am index 6dde7cbc..3fbe8356 100644 --- a/src/plugins/splash/script/Makefile.am +++ b/src/plugins/splash/script/Makefile.am @@ -31,6 +31,8 @@ script_la_SOURCES = $(srcdir)/plugin.c \ $(srcdir)/script-execute.h \ $(srcdir)/script-object.c \ $(srcdir)/script-object.h \ + $(srcdir)/script-debug.c \ + $(srcdir)/script-debug.h \ $(srcdir)/script-lib-image.c \ $(srcdir)/script-lib-image.h \ $(srcdir)/script-lib-image.script \ diff --git a/src/plugins/splash/script/script-debug.h b/src/plugins/splash/script/script-debug.h index 8b6a41ea..92c70bfb 100644 --- a/src/plugins/splash/script/script-debug.h +++ b/src/plugins/splash/script/script-debug.h @@ -27,6 +27,7 @@ typedef struct { int line_index; int column_index; + char* name; } script_debug_source_location_t; diff --git a/src/plugins/splash/script/script-lib-image.c b/src/plugins/splash/script/script-lib-image.c index 5903fac5..37ad2e9d 100644 --- a/src/plugins/splash/script/script-lib-image.c +++ b/src/plugins/splash/script/script-lib-image.c @@ -185,7 +185,7 @@ script_lib_image_data_t *script_lib_image_setup (script_state_t *state, "image", NULL); - data->script_main_op = script_parse_string (script_lib_image_string); + data->script_main_op = script_parse_string (script_lib_image_string, "script-lib-image.script"); script_return_t ret = script_execute (state, data->script_main_op); script_obj_unref (ret.object); diff --git a/src/plugins/splash/script/script-lib-math.c b/src/plugins/splash/script/script-lib-math.c index 3b63b2a5..ad3b0054 100644 --- a/src/plugins/splash/script/script-lib-math.c +++ b/src/plugins/splash/script/script-lib-math.c @@ -103,7 +103,7 @@ script_lib_math_data_t *script_lib_math_setup (script_state_t *state) "value", NULL); - data->script_main_op = script_parse_string (script_lib_math_string); + data->script_main_op = script_parse_string (script_lib_math_string, "script-lib-math.script"); script_return_t ret = script_execute (state, data->script_main_op); script_obj_unref (ret.object); diff --git a/src/plugins/splash/script/script-lib-plymouth.c b/src/plugins/splash/script/script-lib-plymouth.c index d3b5f4cb..a601d434 100644 --- a/src/plugins/splash/script/script-lib-plymouth.c +++ b/src/plugins/splash/script/script-lib-plymouth.c @@ -122,7 +122,7 @@ script_lib_plymouth_data_t *script_lib_plymouth_setup (script_state_t *state) &data->script_message_func, "function", NULL); - data->script_main_op = script_parse_string (script_lib_plymouth_string); + data->script_main_op = script_parse_string (script_lib_plymouth_string, "script-lib-plymouth.script"); script_return_t ret = script_execute (state, data->script_main_op); script_obj_unref (ret.object); /* Throw anything sent back away */ diff --git a/src/plugins/splash/script/script-lib-sprite.c b/src/plugins/splash/script/script-lib-sprite.c index b883e684..e8dde377 100644 --- a/src/plugins/splash/script/script-lib-sprite.c +++ b/src/plugins/splash/script/script-lib-sprite.c @@ -331,7 +331,7 @@ script_lib_sprite_data_t *script_lib_sprite_setup (script_state_t *state, "blue", NULL); - data->script_main_op = script_parse_string (script_lib_sprite_string); + data->script_main_op = script_parse_string (script_lib_sprite_string, "script-lib-sprite.script"); data->background_color_start = 0x000000; data->background_color_end = 0x000000; data->full_refresh = true; diff --git a/src/plugins/splash/script/script-parse.c b/src/plugins/splash/script/script-parse.c index 08146ea5..dbe4da67 100644 --- a/src/plugins/splash/script/script-parse.c +++ b/src/plugins/splash/script/script-parse.c @@ -33,7 +33,7 @@ #include #include -#include "script.h" +#include "script-debug.h" #include "script-scan.h" #include "script-parse.h" @@ -146,13 +146,14 @@ static script_op_t *script_parse_new_op_cond (script_op_type_t type, return op; } -static void script_parse_error (script_scan_token_t *token, - const char *expected) +static void script_parse_error (script_debug_source_location_t *location, + const char *message) { - ply_error ("Parser error L:%d C:%d : %s\n", - token->location.line_index, - token->location.column_index, - expected); + ply_error ("Parser error \"%s\" L:%d C:%d : %s\n", + location->name, + location->line_index, + location->column_index, + message); } static const script_parse_operator_table_entry_t* /* Only allows 1 or 2 character symbols */ @@ -194,7 +195,7 @@ static script_function_t *script_parse_function_def (script_scan_t *scan) if (!script_scan_token_is_symbol_of_value (curtoken, '(')) { - script_parse_error (curtoken, + script_parse_error (&curtoken->location, "Function declaration requires parameters to be declared within '(' brackets"); return NULL; } @@ -206,7 +207,7 @@ static script_function_t *script_parse_function_def (script_scan_t *scan) if (script_scan_token_is_symbol_of_value (curtoken, ')')) break; if (!script_scan_token_is_identifier (curtoken)) { - script_parse_error (curtoken, + script_parse_error (&curtoken->location, "Function declaration parameters must be valid identifiers"); return NULL; } @@ -218,7 +219,7 @@ static script_function_t *script_parse_function_def (script_scan_t *scan) if (script_scan_token_is_symbol_of_value (curtoken, ')')) break; if (!script_scan_token_is_symbol_of_value (curtoken, ',')) { - script_parse_error (curtoken, + script_parse_error (&curtoken->location, "Function declaration parameters must separated with ',' and terminated with a ')'"); return NULL; } @@ -290,13 +291,13 @@ static script_exp_t *script_parse_exp_tm (script_scan_t *scan) curtoken = script_scan_get_current_token (scan); if (!exp) { - script_parse_error (curtoken, + script_parse_error (&curtoken->location, "Expected valid contents of bracketed expression"); return NULL; } if (!script_scan_token_is_symbol_of_value (curtoken, ')')) { - script_parse_error (curtoken, + script_parse_error (&curtoken->location, "Expected bracketed block to be terminated with a ')'"); return NULL; } @@ -329,7 +330,7 @@ static script_exp_t *script_parse_exp_pi (script_scan_t *scan) if (script_scan_token_is_symbol_of_value (curtoken, ')')) break; if (!script_scan_token_is_symbol_of_value (curtoken, ',')) { - script_parse_error (curtoken, + script_parse_error (&curtoken->location, "Function parameters should be separated with a ',' and terminated with a ')'"); return NULL; } @@ -350,7 +351,7 @@ static script_exp_t *script_parse_exp_pi (script_scan_t *scan) } else { - script_parse_error (curtoken, + script_parse_error (&curtoken->location, "A dot based hash index must be an identifier (or a integer)"); return NULL; } @@ -363,7 +364,7 @@ static script_exp_t *script_parse_exp_pi (script_scan_t *scan) curtoken = script_scan_get_current_token (scan); if (!script_scan_token_is_symbol_of_value (curtoken, ']')) { - script_parse_error (curtoken, + script_parse_error (&curtoken->location, "Expected a ']' to terminate the index expression"); return NULL; } @@ -453,7 +454,7 @@ static script_exp_t *script_parse_exp_ltr (script_scan_t *scan, int presedence) exp = script_parse_new_exp_dual(entry->exp_type, exp, script_parse_exp_ltr (scan, presedence + 1)); if (!exp->data.dual.sub_b) { - script_parse_error (script_scan_get_current_token (scan), + script_parse_error (&script_scan_get_current_token (scan)->location, "An invalid RHS of an expression"); return NULL; } @@ -483,7 +484,7 @@ static script_exp_t *script_parse_exp_as (script_scan_t *scan) script_exp_t *rhs = script_parse_exp_as (scan); if (!rhs) { - script_parse_error (script_scan_get_current_token (scan), + script_parse_error (&script_scan_get_current_token (scan)->location, "An invalid RHS of an expression"); return NULL; } @@ -503,9 +504,11 @@ static script_op_t *script_parse_op_block (script_scan_t *scan) return NULL; script_scan_get_next_token (scan); ply_list_t *sublist = script_parse_op_list (scan); + + curtoken = script_scan_get_current_token (scan); if (!script_scan_token_is_symbol_of_value (curtoken, '}')) { - script_parse_error (script_scan_get_current_token (scan), + script_parse_error (&curtoken->location, "Expected a '}' to terminate the operation block"); return NULL; } @@ -528,7 +531,7 @@ static script_op_t *script_parse_if_while (script_scan_t *scan) curtoken = script_scan_get_next_token (scan); if (!script_scan_token_is_symbol_of_value (curtoken, '(')) { - script_parse_error (curtoken, + script_parse_error (&curtoken->location, "Expected a '(' at the start of a condition block"); return NULL; } @@ -538,12 +541,12 @@ static script_op_t *script_parse_if_while (script_scan_t *scan) curtoken = script_scan_get_current_token (scan); if (!cond) { - script_parse_error (curtoken, "Expected a valid condition expression"); + script_parse_error (&curtoken->location, "Expected a valid condition expression"); return NULL; } if (!script_scan_token_is_symbol_of_value (curtoken, ')')) { - script_parse_error (curtoken, + script_parse_error (&curtoken->location, "Expected a ')' at the end of a condition block"); return NULL; } @@ -570,7 +573,7 @@ static script_op_t *script_parse_for (script_scan_t *scan) curtoken = script_scan_get_next_token (scan); if (!script_scan_token_is_symbol_of_value (curtoken, '(')) { - script_parse_error (curtoken, + script_parse_error (&curtoken->location, "Expected a '(' at the start of a condition block"); return NULL; } @@ -579,13 +582,13 @@ static script_op_t *script_parse_for (script_scan_t *scan) script_exp_t *first = script_parse_exp (scan); if (!first) { - script_parse_error (curtoken, "Expected a valid first expression"); + script_parse_error (&curtoken->location, "Expected a valid first expression"); return NULL; } curtoken = script_scan_get_current_token (scan); if (!script_scan_token_is_symbol_of_value (curtoken, ';')) { - script_parse_error (curtoken, + script_parse_error (&curtoken->location, "Expected a ';' after the first 'for' expression"); return NULL; } @@ -594,13 +597,13 @@ static script_op_t *script_parse_for (script_scan_t *scan) script_exp_t *cond = script_parse_exp (scan); if (!cond) { - script_parse_error (curtoken, "Expected a valid condition expression"); + script_parse_error (&curtoken->location, "Expected a valid condition expression"); return NULL; } curtoken = script_scan_get_current_token (scan); if (!script_scan_token_is_symbol_of_value (curtoken, ';')) { - script_parse_error (curtoken, "Expected a ';' after the 'for' condition"); + script_parse_error (&curtoken->location, "Expected a ';' after the 'for' condition"); return NULL; } script_scan_get_next_token (scan); @@ -608,13 +611,13 @@ static script_op_t *script_parse_for (script_scan_t *scan) script_exp_t *last = script_parse_exp (scan); if (!last) { - script_parse_error (curtoken, "Expected a valid last expression"); + script_parse_error (&curtoken->location, "Expected a valid last expression"); return NULL; } curtoken = script_scan_get_current_token (scan); if (!script_scan_token_is_symbol_of_value (curtoken, ')')) { - script_parse_error (curtoken, "Expected a ')' at the end of a for block"); + script_parse_error (&curtoken->location, "Expected a ')' at the end of a for block"); return NULL; } script_scan_get_next_token (scan); @@ -641,7 +644,7 @@ static script_op_t *script_parse_function (script_scan_t *scan) curtoken = script_scan_get_next_token (scan); if (!script_scan_token_is_identifier (curtoken)) { - script_parse_error (curtoken, + script_parse_error (&curtoken->location, "A function declaration requires a valid name"); return NULL; } @@ -681,7 +684,7 @@ static script_op_t *script_parse_return (script_scan_t *scan) #ifdef WITH_SEMIES if (!script_scan_token_is_symbol_of_value (curtoken, ';')) { - script_parse_error (curtoken, "Expected ';' after an expression"); + script_parse_error (&curtoken->location, "Expected ';' after an expression"); return NULL; } curtoken = script_scan_get_next_token (scan); @@ -715,7 +718,7 @@ static script_op_t *script_parse_op (script_scan_t *scan) #ifdef WITH_SEMIES if (!script_scan_token_is_symbol_of_value (curtoken, ';')) { - script_parse_error (curtoken, "Expected ';' after an expression"); + script_parse_error (&curtoken->location, "Expected ';' after an expression"); return NULL; } curtoken = script_scan_get_next_token (scan); @@ -914,7 +917,7 @@ script_op_t *script_parse_file (const char *filename) script_scan_token_t *curtoken = script_scan_get_current_token (scan); if (curtoken->type != SCRIPT_SCAN_TOKEN_TYPE_EOF) { - script_parse_error (curtoken, "Unparsed characters at end of file"); + script_parse_error (&curtoken->location, "Unparsed characters at end of file"); return NULL; } script_scan_free (scan); @@ -922,9 +925,10 @@ script_op_t *script_parse_file (const char *filename) return op; } -script_op_t *script_parse_string (const char *string) +script_op_t *script_parse_string (const char *string, + const char *name) { - script_scan_t *scan = script_scan_string (string); + script_scan_t *scan = script_scan_string (string, name); if (!scan) { diff --git a/src/plugins/splash/script/script-parse.h b/src/plugins/splash/script/script-parse.h index 0c017c4a..44a63fd6 100644 --- a/src/plugins/splash/script/script-parse.h +++ b/src/plugins/splash/script/script-parse.h @@ -25,7 +25,8 @@ #include "script.h" script_op_t *script_parse_file (const char *filename); -script_op_t *script_parse_string (const char *string); +script_op_t *script_parse_string (const char *string, + const char *name); void script_parse_op_free (script_op_t *op); #endif /* SCRIPT_PARSE */ diff --git a/src/plugins/splash/script/script-scan.c b/src/plugins/splash/script/script-scan.c index 114d0e76..ead752f1 100644 --- a/src/plugins/splash/script/script-scan.c +++ b/src/plugins/splash/script/script-scan.c @@ -64,15 +64,18 @@ script_scan_t *script_scan_file (const char *filename) int fd = open (filename, O_RDONLY); if (fd < 0) return NULL; script_scan_t *scan = script_scan_new (); + scan->name = strdup (filename); scan->source.fd = fd; scan->source_is_file = true; script_scan_get_next_char (scan); return scan; } -script_scan_t *script_scan_string (const char *string) +script_scan_t *script_scan_string (const char *string, + const char *name) { script_scan_t *scan = script_scan_new (); + scan->name = strdup (name); scan->source.string = string; scan->source_is_file = false; script_scan_get_next_char (scan); @@ -111,6 +114,7 @@ void script_scan_free (script_scan_t *scan) } ply_bitarray_free (scan->identifier_1st_char); ply_bitarray_free (scan->identifier_nth_char); + free (scan->name); free (scan->tokens); free (scan); } @@ -173,6 +177,7 @@ void script_scan_read_next_token (script_scan_t *scan, } token->location.line_index = scan->line_index; token->location.column_index = scan->column_index; + token->location.name = scan->name; nextchar = script_scan_get_next_char (scan); if (ply_bitarray_lookup (scan->identifier_1st_char, curchar)) diff --git a/src/plugins/splash/script/script-scan.h b/src/plugins/splash/script/script-scan.h index 0b23b015..7891d4a1 100644 --- a/src/plugins/splash/script/script-scan.h +++ b/src/plugins/splash/script/script-scan.h @@ -60,6 +60,7 @@ typedef struct int fd; const char *string; } source; + char* name; unsigned char cur_char; ply_bitarray_t *identifier_1st_char; ply_bitarray_t *identifier_nth_char; @@ -92,7 +93,8 @@ typedef struct script_scan_t *script_scan_file (const char *filename); -script_scan_t *script_scan_string (const char *string); +script_scan_t *script_scan_string (const char *string, + const char *name); void script_scan_token_clean (script_scan_token_t *token); void script_scan_free (script_scan_t *scan); unsigned char script_scan_get_current_char (script_scan_t *scan); @@ -101,7 +103,7 @@ script_scan_token_t *script_scan_get_current_token (script_scan_t *scan); script_scan_token_t *script_scan_get_next_token (script_scan_t *scan); script_scan_token_t *script_scan_peek_next_token (script_scan_t *scan); void script_scan_read_next_token (script_scan_t *scan, - script_scan_token_t *token); + script_scan_token_t *token); #endif /* script_scan_H */