]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
[script] Keep the filename while scanning for parsing error messages
authorCharlie Brej <cbrej@cs.man.ac.uk>
Sun, 30 Aug 2009 19:53:13 +0000 (20:53 +0100)
committerCharlie Brej <cbrej@cs.man.ac.uk>
Sun, 30 Aug 2009 19:53:13 +0000 (20:53 +0100)
src/plugins/splash/script/Makefile.am
src/plugins/splash/script/script-debug.h
src/plugins/splash/script/script-lib-image.c
src/plugins/splash/script/script-lib-math.c
src/plugins/splash/script/script-lib-plymouth.c
src/plugins/splash/script/script-lib-sprite.c
src/plugins/splash/script/script-parse.c
src/plugins/splash/script/script-parse.h
src/plugins/splash/script/script-scan.c
src/plugins/splash/script/script-scan.h

index 6dde7cbc7b041bbbc36204468f137c591b3b9100..3fbe8356007eb869a9390a127e986e08f896f00d 100644 (file)
@@ -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                         \
index 8b6a41eae3471db19243090188e590ba965ebde1..92c70bfb4e71cff9cd1f8beecedf3ddd6ff2ab33 100644 (file)
@@ -27,6 +27,7 @@ typedef struct
 {
   int line_index;
   int column_index;
+  char* name;
 } script_debug_source_location_t;
 
 
index 5903fac551cad7ee25d1cd783b19e22165008fae..37ad2e9dba1aa552ec959631c2b51e4267ebb5be 100644 (file)
@@ -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);
 
index 3b63b2a5be8509c5115b38b996f5374806706409..ad3b0054b6912fa43cb40bb4c42dfe840b19967c 100644 (file)
@@ -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);
 
index d3b5f4cbafeb6212a64ea22388bc28380f929797..a601d434d6d54c7a28e014357faa87ca57e290fa 100644 (file)
@@ -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 */
 
index b883e684e9feb682cd729df625fb20d49b69df20..e8dde377f38922f29a1153bf395cc0f2a461b671 100644 (file)
@@ -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;
index 08146ea58c1ae0ca3f73c4a4c3b0fcf4a42f9576..dbe4da67726984aed14073f2a6db3a540396d758 100644 (file)
@@ -33,7 +33,7 @@
 #include <string.h>
 #include <stdbool.h>
 
-#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)
     {
index 0c017c4a2730c2758f7f4f0c11396db0744115f8..44a63fd650b2fcc25dfb63bff57646ecc49eb1ef 100644 (file)
@@ -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 */
index 114d0e76dee1159781e88430307570671e3dd61f..ead752f1453f9efa3d26ed04ebe5244332bd6abd 100644 (file)
@@ -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))
index 0b23b015bed3632c264dd274b94f8c695a2b3b6f..7891d4a1cba292573921cdaa59e7ff26e8ad3593 100644 (file)
@@ -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 */