]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
[script] Rename ply-scan to script-scan
authorCharlie Brej <cbrej@cs.man.ac.uk>
Mon, 20 Jul 2009 13:12:53 +0000 (14:12 +0100)
committerCharlie Brej <cbrej@cs.man.ac.uk>
Mon, 20 Jul 2009 13:12:53 +0000 (14:12 +0100)
The scan functions were originally aimed to be put in libply but then again I
can't think of anything that would use them so they are now renamed to left in
the plugin.

src/plugins/splash/script/Makefile.am
src/plugins/splash/script/ply-scan.h [deleted file]
src/plugins/splash/script/script-execute.c
src/plugins/splash/script/script-object.c
src/plugins/splash/script/script-parse.c
src/plugins/splash/script/script-scan.c [moved from src/plugins/splash/script/ply-scan.c with 67% similarity]
src/plugins/splash/script/script-scan.h [new file with mode: 0644]
src/plugins/splash/script/script.c
src/plugins/splash/script/script.h

index c3966c200451597a2b4c5f3b1d5fbe0d420af633..bb8a4a15ae85e3bee509ca65a6a27705cf4a3f19 100644 (file)
@@ -23,6 +23,8 @@ script_la_SOURCES = $(srcdir)/plugin.c                                        \
                     $(srcdir)/plugin.h                                        \
                     $(srcdir)/script.c                                        \
                     $(srcdir)/script.h                                        \
+                    $(srcdir)/script-scan.c                                   \
+                    $(srcdir)/script-scan.h                                   \
                     $(srcdir)/script-parse.c                                  \
                     $(srcdir)/script-parse.h                                  \
                     $(srcdir)/script-execute.c                                \
@@ -40,9 +42,7 @@ script_la_SOURCES = $(srcdir)/plugin.c                                        \
                     $(srcdir)/script-lib-plymouth.script                      \
                     $(srcdir)/script-lib-math.c                               \
                     $(srcdir)/script-lib-math.h                               \
-                    $(srcdir)/script-lib-math.script                          \
-                    $(srcdir)/ply-scan.c                                      \
-                    $(srcdir)/ply-scan.h                                      
+                    $(srcdir)/script-lib-math.script
 
 MAINTAINERCLEANFILES = Makefile.in
 CLEANFILES = *.string
diff --git a/src/plugins/splash/script/ply-scan.h b/src/plugins/splash/script/ply-scan.h
deleted file mode 100644 (file)
index b89961b..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-/* ply-scan.h - lexical scanner
- *
- * Copyright (C) 2009 Charlie Brej <cbrej@cs.man.ac.uk>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by: Charlie Brej <cbrej@cs.man.ac.uk>
- */
-#ifndef PLY_SCAN_H
-#define PLY_SCAN_H
-
-#include "ply-bitarray.h"
-#include <stdbool.h>
-
-typedef enum
-{
-  PLY_SCAN_TOKEN_TYPE_EMPTY,
-  PLY_SCAN_TOKEN_TYPE_EOF,
-  PLY_SCAN_TOKEN_TYPE_INTEGER,
-  PLY_SCAN_TOKEN_TYPE_FLOAT,
-  PLY_SCAN_TOKEN_TYPE_IDENTIFIER,
-  PLY_SCAN_TOKEN_TYPE_STRING,
-  PLY_SCAN_TOKEN_TYPE_SYMBOL,
-  PLY_SCAN_TOKEN_TYPE_COMMENT,
-  PLY_SCAN_TOKEN_TYPE_ERROR,
-} ply_scan_token_type_t;
-
-typedef struct
-{
-  ply_scan_token_type_t type;
-  union
-  {
-    char *string;
-    char symbol;
-    long long int integer;
-    double floatpoint;
-  } data;
-  int whitespace;
-  int line_index;
-  int column_index;
-} ply_scan_token_t;
-
-typedef struct
-{
-  union
-  {
-    int fd;
-    const char *string;
-  } source;
-  unsigned char cur_char;
-  ply_bitarray_t *identifier_1st_char;
-  ply_bitarray_t *identifier_nth_char;
-  int tokencount;
-  ply_scan_token_t **tokens;
-  int line_index;
-  int column_index;
-  bool source_is_file;
-} ply_scan_t;
-
-
-#define ply_scan_token_is_symbol(__token) \
-      (__token->type == PLY_SCAN_TOKEN_TYPE_SYMBOL)
-#define ply_scan_token_is_symbol_of_value(__token,__value) \
-      (__token->type == PLY_SCAN_TOKEN_TYPE_SYMBOL \
-      && __token->data.symbol == __value)
-#define ply_scan_token_is_identifier(__token) \
-      (__token->type == PLY_SCAN_TOKEN_TYPE_IDENTIFIER)
-#define ply_scan_token_is_identifier_of_value(__token,__value) \
-      (__token->type == PLY_SCAN_TOKEN_TYPE_IDENTIFIER \
-      && !strcmp(__token->data.string, __value))
-#define ply_scan_token_is_integer(__token) \
-      (__token->type == PLY_SCAN_TOKEN_TYPE_INTEGER)
-#define ply_scan_token_is_string(__token) \
-      (__token->type == PLY_SCAN_TOKEN_TYPE_STRING)
-#define ply_scan_token_is_float(__token) \
-      (__token->type == PLY_SCAN_TOKEN_TYPE_FLOAT)
-
-
-
-
-ply_scan_t *ply_scan_file (const char *filename);
-ply_scan_t *ply_scan_string (const char *string);
-void ply_scan_token_clean (ply_scan_token_t *token);
-void ply_scan_free (ply_scan_t *scan);
-unsigned char ply_scan_get_current_char (ply_scan_t *scan);
-unsigned char ply_scan_get_next_char (ply_scan_t *scan);
-ply_scan_token_t *ply_scan_get_current_token (ply_scan_t *scan);
-ply_scan_token_t *ply_scan_get_next_token (ply_scan_t *scan);
-ply_scan_token_t *ply_scan_peek_next_token (ply_scan_t *scan);
-void ply_scan_read_next_token (ply_scan_t       *scan,
-                               ply_scan_token_t *token);
-
-
-#endif /* PLY_SCAN_H */
index fd22d756cedd9821d8d3e970d7798cc2137c7c21..cace00f38bf6eee0d70afb95ef672a15af795bab 100644 (file)
@@ -20,7 +20,6 @@
  * Written by: Charlie Brej <cbrej@cs.man.ac.uk>
  */
 #define _GNU_SOURCE
-#include "ply-scan.h"
 #include "ply-hashtable.h"
 #include "ply-list.h"
 #include <stdio.h>
index 22d84e2b94c1d188d185c8107ca063378da40039..558b34913aa54fd0d21c96d6cb48af2e9369c9a2 100644 (file)
@@ -20,7 +20,6 @@
  * Written by: Charlie Brej <cbrej@cs.man.ac.uk>
  */
 #define _GNU_SOURCE
-#include "ply-scan.h"
 #include "ply-hashtable.h"
 #include "ply-list.h"
 #include "ply-bitarray.h"
index d3bfbcaf83c2281f8d291523f7238191c187d142..ab5a0c29b76bcc7f24a3dcba7c8e12ecfb5423da 100644 (file)
@@ -20,7 +20,6 @@
  * Written by: Charlie Brej <cbrej@cs.man.ac.uk>
  */
 #define _GNU_SOURCE
-#include "ply-scan.h"
 #include "ply-hashtable.h"
 #include "ply-list.h"
 #include "ply-bitarray.h"
@@ -34,6 +33,7 @@
 #include <stdbool.h>
 
 #include "script.h"
+#include "script-scan.h"
 #include "script-parse.h"
 
 #define WITH_SEMIES
@@ -45,9 +45,9 @@ typedef struct
  int                presedence;
 }script_parse_operator_table_entry_t;
 
-static script_op_t *script_parse_op (ply_scan_t *scan);
-static script_exp_t *script_parse_exp (ply_scan_t *scan);
-static ply_list_t *script_parse_op_list (ply_scan_t *scan);
+static script_op_t *script_parse_op (script_scan_t *scan);
+static script_exp_t *script_parse_exp (script_scan_t *scan);
+static ply_list_t *script_parse_op_list (script_scan_t *scan);
 static void script_parse_op_list_free (ply_list_t *op_list);
 
 static script_exp_t *script_parse_new_exp_single (script_exp_type_t  type,
@@ -70,7 +70,7 @@ static script_exp_t *script_parse_new_exp_dual (script_exp_type_t  type,
   return exp;
 }
 
-static void script_parse_error (ply_scan_token_t *token,
+static void script_parse_error (script_scan_token_t *token,
                                 const char       *expected)
 {
   ply_error ("Parser error L:%d C:%d : %s\n",
@@ -80,19 +80,19 @@ static void script_parse_error (ply_scan_token_t *token,
 }
 
 static const script_parse_operator_table_entry_t*   /* Only allows 1 or 2 character symbols */
-script_parse_operator_table_entry_lookup (ply_scan_t                                *scan,
+script_parse_operator_table_entry_lookup (script_scan_t                                *scan,
                                           const script_parse_operator_table_entry_t *table)
 {
   int entry_index;
-  ply_scan_token_t *curtoken = ply_scan_get_current_token (scan);
-  ply_scan_token_t *peektoken = ply_scan_peek_next_token (scan);
+  script_scan_token_t *curtoken = script_scan_get_current_token (scan);
+  script_scan_token_t *peektoken = script_scan_peek_next_token (scan);
   for (entry_index = 0; table[entry_index].symbol; entry_index++)
     {
-      if (!ply_scan_token_is_symbol (curtoken)) continue;
+      if (!script_scan_token_is_symbol (curtoken)) continue;
       if (curtoken->data.symbol != table[entry_index].symbol[0]) continue;
       if (table[entry_index].symbol[1])
         {
-          if (!ply_scan_token_is_symbol (peektoken)) continue;
+          if (!script_scan_token_is_symbol (peektoken)) continue;
           if (peektoken->data.symbol != table[entry_index].symbol[1]) continue;
           if (peektoken->whitespace) continue;
         }
@@ -101,34 +101,34 @@ script_parse_operator_table_entry_lookup (ply_scan_t
   return &table[entry_index];
 }
 
-static void script_parse_advance_scan_by_string (ply_scan_t *scan,
+static void script_parse_advance_scan_by_string (script_scan_t *scan,
                                                  const char *string)
 {
   while (*string)
     {
-      ply_scan_get_next_token(scan);
+      script_scan_get_next_token(scan);
       string++;
     }
 }
 
-static script_function_t *script_parse_function_def (ply_scan_t *scan)
+static script_function_t *script_parse_function_def (script_scan_t *scan)
 {
-  ply_scan_token_t *curtoken = ply_scan_get_current_token (scan);
+  script_scan_token_t *curtoken = script_scan_get_current_token (scan);
   ply_list_t *parameter_list;
 
-  if (!ply_scan_token_is_symbol_of_value (curtoken, '('))
+  if (!script_scan_token_is_symbol_of_value (curtoken, '('))
     {
       script_parse_error (curtoken,
         "Function declaration requires parameters to be declared within '(' brackets");
       return NULL;
     }
-  curtoken = ply_scan_get_next_token (scan);
+  curtoken = script_scan_get_next_token (scan);
   parameter_list = ply_list_new ();
 
   while (true)
     {
-      if (ply_scan_token_is_symbol_of_value (curtoken, ')')) break;
-      if (!ply_scan_token_is_identifier (curtoken))
+      if (script_scan_token_is_symbol_of_value (curtoken, ')')) break;
+      if (!script_scan_token_is_identifier (curtoken))
         {
           script_parse_error (curtoken,
             "Function declaration parameters must be valid identifiers");
@@ -137,19 +137,19 @@ static script_function_t *script_parse_function_def (ply_scan_t *scan)
       char *parameter = strdup (curtoken->data.string);
       ply_list_append_data (parameter_list, parameter);
 
-      curtoken = ply_scan_get_next_token (scan);
+      curtoken = script_scan_get_next_token (scan);
 
-      if (ply_scan_token_is_symbol_of_value (curtoken, ')')) break;
-      if (!ply_scan_token_is_symbol_of_value (curtoken, ','))
+      if (script_scan_token_is_symbol_of_value (curtoken, ')')) break;
+      if (!script_scan_token_is_symbol_of_value (curtoken, ','))
         {
           script_parse_error (curtoken,
             "Function declaration parameters must separated with ',' and terminated with a ')'");
           return NULL;
         }
-      curtoken = ply_scan_get_next_token (scan);
+      curtoken = script_scan_get_next_token (scan);
     }
 
-  curtoken = ply_scan_get_next_token (scan);
+  curtoken = script_scan_get_next_token (scan);
 
   script_op_t *func_op = script_parse_op (scan);
   
@@ -159,40 +159,40 @@ static script_function_t *script_parse_function_def (ply_scan_t *scan)
   return function;
 }
 
-static script_exp_t *script_parse_exp_tm (ply_scan_t *scan)
+static script_exp_t *script_parse_exp_tm (script_scan_t *scan)
 {
-  ply_scan_token_t *curtoken = ply_scan_get_current_token (scan);
+  script_scan_token_t *curtoken = script_scan_get_current_token (scan);
   script_exp_t *exp = NULL;
 
-  if (ply_scan_token_is_integer (curtoken))
+  if (script_scan_token_is_integer (curtoken))
     {
       exp = malloc (sizeof (script_exp_t));
       exp->type = SCRIPT_EXP_TYPE_TERM_INT;
       exp->data.integer = curtoken->data.integer;
-      ply_scan_get_next_token (scan);
+      script_scan_get_next_token (scan);
       return exp;
     }
-  if (ply_scan_token_is_float (curtoken))
+  if (script_scan_token_is_float (curtoken))
     {
       exp = malloc (sizeof (script_exp_t));
       exp->type = SCRIPT_EXP_TYPE_TERM_FLOAT;
       exp->data.floatpoint = curtoken->data.floatpoint;
-      ply_scan_get_next_token (scan);
+      script_scan_get_next_token (scan);
       return exp;
     }
-  if (ply_scan_token_is_identifier (curtoken))
+  if (script_scan_token_is_identifier (curtoken))
     {
       exp = malloc (sizeof (script_exp_t));
-      if (ply_scan_token_is_identifier_of_value (curtoken, "NULL"))
+      if (script_scan_token_is_identifier_of_value (curtoken, "NULL"))
         exp->type = SCRIPT_EXP_TYPE_TERM_NULL;
-      else if (ply_scan_token_is_identifier_of_value (curtoken, "global"))
+      else if (script_scan_token_is_identifier_of_value (curtoken, "global"))
         exp->type = SCRIPT_EXP_TYPE_TERM_GLOBAL;
-      else if (ply_scan_token_is_identifier_of_value (curtoken, "local"))
+      else if (script_scan_token_is_identifier_of_value (curtoken, "local"))
         exp->type = SCRIPT_EXP_TYPE_TERM_LOCAL;
-      else if (ply_scan_token_is_identifier_of_value (curtoken, "fun"))
+      else if (script_scan_token_is_identifier_of_value (curtoken, "fun"))
         {
           exp->type = SCRIPT_EXP_TYPE_FUNCTION_DEF;
-          ply_scan_get_next_token (scan);
+          script_scan_get_next_token (scan);
           exp->data.function_def = script_parse_function_def (scan);
           return exp;
         }
@@ -201,71 +201,71 @@ static script_exp_t *script_parse_exp_tm (ply_scan_t *scan)
           exp->type = SCRIPT_EXP_TYPE_TERM_VAR;
           exp->data.string = strdup (curtoken->data.string);
         }
-      curtoken = ply_scan_get_next_token (scan);
+      curtoken = script_scan_get_next_token (scan);
       return exp;
     }
-  if (ply_scan_token_is_string (curtoken))
+  if (script_scan_token_is_string (curtoken))
     {
       exp = malloc (sizeof (script_exp_t));
       exp->type = SCRIPT_EXP_TYPE_TERM_STRING;
       exp->data.string = strdup (curtoken->data.string);
-      ply_scan_get_next_token (scan);
+      script_scan_get_next_token (scan);
       return exp;
     }
-  if (ply_scan_token_is_symbol_of_value (curtoken, '('))
+  if (script_scan_token_is_symbol_of_value (curtoken, '('))
     {
-      ply_scan_get_next_token (scan);
+      script_scan_get_next_token (scan);
       exp = script_parse_exp (scan);
-      curtoken = ply_scan_get_current_token (scan);
+      curtoken = script_scan_get_current_token (scan);
       if (!exp)
         {
           script_parse_error (curtoken,
             "Expected valid contents of bracketed expression");
           return NULL;
         }
-      if (!ply_scan_token_is_symbol_of_value (curtoken, ')'))
+      if (!script_scan_token_is_symbol_of_value (curtoken, ')'))
         {
           script_parse_error (curtoken,
             "Expected bracketed block to be terminated with a ')'");
           return NULL;
         }
-      ply_scan_get_next_token (scan);
+      script_scan_get_next_token (scan);
       return exp;
     }
   return NULL;
 }
 
-static script_exp_t *script_parse_exp_pi (ply_scan_t *scan)
+static script_exp_t *script_parse_exp_pi (script_scan_t *scan)
 {
   script_exp_t *exp = script_parse_exp_tm (scan);
-  ply_scan_token_t *curtoken = ply_scan_get_current_token (scan);
+  script_scan_token_t *curtoken = script_scan_get_current_token (scan);
 
   while (true)
     {
-      if (!ply_scan_token_is_symbol (curtoken)) break;
-      if (ply_scan_token_is_symbol_of_value (curtoken, '('))
+      if (!script_scan_token_is_symbol (curtoken)) break;
+      if (script_scan_token_is_symbol_of_value (curtoken, '('))
         {
           script_exp_t *func = malloc (sizeof (script_exp_t));
           ply_list_t *parameters = ply_list_new ();
-          ply_scan_get_next_token (scan);
+          script_scan_get_next_token (scan);
           while (true)
             {
-              if (ply_scan_token_is_symbol_of_value (curtoken, ')')) break;
+              if (script_scan_token_is_symbol_of_value (curtoken, ')')) break;
               script_exp_t *parameter = script_parse_exp (scan);
 
               ply_list_append_data (parameters, parameter);
 
-              curtoken = ply_scan_get_current_token (scan);
-              if (ply_scan_token_is_symbol_of_value (curtoken, ')')) break;
-              if (!ply_scan_token_is_symbol_of_value (curtoken, ','))
+              curtoken = script_scan_get_current_token (scan);
+              if (script_scan_token_is_symbol_of_value (curtoken, ')')) break;
+              if (!script_scan_token_is_symbol_of_value (curtoken, ','))
                 {
                   script_parse_error (curtoken,
                     "Function parameters should be separated with a ',' and terminated with a ')'");
                   return NULL;
                 }
-              curtoken = ply_scan_get_next_token (scan);
+              curtoken = script_scan_get_next_token (scan);
             }
-          ply_scan_get_next_token (scan);
+          script_scan_get_next_token (scan);
           func->data.function_exe.name = exp;
           exp = func;
           exp->type = SCRIPT_EXP_TYPE_FUNCTION_EXE;
@@ -274,16 +274,16 @@ static script_exp_t *script_parse_exp_pi (ply_scan_t *scan)
         }
       script_exp_t *key;
 
-      if (ply_scan_token_is_symbol_of_value (curtoken, '.'))
+      if (script_scan_token_is_symbol_of_value (curtoken, '.'))
         {
-          ply_scan_get_next_token (scan);
-          if (ply_scan_token_is_identifier (curtoken))
+          script_scan_get_next_token (scan);
+          if (script_scan_token_is_identifier (curtoken))
             {
               key = malloc (sizeof (script_exp_t));
               key->type = SCRIPT_EXP_TYPE_TERM_STRING;
               key->data.string = strdup (curtoken->data.string);
             }
-          else if (ply_scan_token_is_integer (curtoken))       /* errrr, integer keys without being [] bracketed */
+          else if (script_scan_token_is_integer (curtoken))       /* errrr, integer keys without being [] bracketed */
             {
               key = malloc (sizeof (script_exp_t));                       /* This is broken with floats as obj.10.6 is obj[10.6] and not obj[10][6] */
               key->type = SCRIPT_EXP_TYPE_TERM_INT;
@@ -295,20 +295,20 @@ static script_exp_t *script_parse_exp_pi (ply_scan_t *scan)
                 "A dot based hash index must be an identifier (or a integer)");
               return NULL;
             }
-          curtoken = ply_scan_get_next_token (scan);
+          curtoken = script_scan_get_next_token (scan);
         }
-      else if (ply_scan_token_is_symbol_of_value (curtoken, '['))
+      else if (script_scan_token_is_symbol_of_value (curtoken, '['))
         {
-          ply_scan_get_next_token (scan);
+          script_scan_get_next_token (scan);
           key = script_parse_exp (scan);
-          curtoken = ply_scan_get_current_token (scan);
-          if (!ply_scan_token_is_symbol_of_value (curtoken, ']'))
+          curtoken = script_scan_get_current_token (scan);
+          if (!script_scan_token_is_symbol_of_value (curtoken, ']'))
             {
               script_parse_error (curtoken,
                 "Expected a ']' to terminate the index expression");
               return NULL;
             }
-          curtoken = ply_scan_get_next_token (scan);
+          curtoken = script_scan_get_next_token (scan);
         }
       else break;
       exp = script_parse_new_exp_dual (SCRIPT_EXP_TYPE_HASH, exp, key);
@@ -316,7 +316,7 @@ static script_exp_t *script_parse_exp_pi (ply_scan_t *scan)
   return exp;
 }
 
-static script_exp_t *script_parse_exp_pr (ply_scan_t *scan)
+static script_exp_t *script_parse_exp_pr (script_scan_t *scan)
 {
   static const script_parse_operator_table_entry_t operator_table[] =
     {
@@ -335,7 +335,7 @@ static script_exp_t *script_parse_exp_pr (ply_scan_t *scan)
   return script_parse_new_exp_single(entry->exp_type, script_parse_exp_pr (scan));
 }
 
-static script_exp_t *script_parse_exp_po (ply_scan_t *scan)
+static script_exp_t *script_parse_exp_po (script_scan_t *scan)
 {
   static const script_parse_operator_table_entry_t operator_table[] =
     {
@@ -356,7 +356,7 @@ static script_exp_t *script_parse_exp_po (ply_scan_t *scan)
   return exp;
 }
 
-static script_exp_t *script_parse_exp_ltr (ply_scan_t *scan, int presedence)
+static script_exp_t *script_parse_exp_ltr (script_scan_t *scan, int presedence)
 {
   static const script_parse_operator_table_entry_t operator_table[] =
     {
@@ -394,7 +394,7 @@ static script_exp_t *script_parse_exp_ltr (ply_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 (ply_scan_get_current_token (scan),
+          script_parse_error (script_scan_get_current_token (scan),
                               "An invalid RHS of an expression");
           return NULL;
         }
@@ -402,7 +402,7 @@ static script_exp_t *script_parse_exp_ltr (ply_scan_t *scan, int presedence)
   return exp;
 }
 
-static script_exp_t *script_parse_exp_as (ply_scan_t *scan)
+static script_exp_t *script_parse_exp_as (script_scan_t *scan)
 {
   static const script_parse_operator_table_entry_t operator_table[] =
     {
@@ -424,33 +424,33 @@ static script_exp_t *script_parse_exp_as (ply_scan_t *scan)
   script_exp_t *rhs = script_parse_exp_as (scan);
   if (!rhs)
     {
-      script_parse_error (ply_scan_get_current_token (scan),
+      script_parse_error (script_scan_get_current_token (scan),
                           "An invalid RHS of an expression");
       return NULL;
     }
   return script_parse_new_exp_dual (entry->exp_type, lhs, rhs);
 }
 
-static script_exp_t *script_parse_exp (ply_scan_t *scan)
+static script_exp_t *script_parse_exp (script_scan_t *scan)
 {
   return script_parse_exp_as (scan);
 }
 
-static script_op_t *script_parse_op_block (ply_scan_t *scan)
+static script_op_t *script_parse_op_block (script_scan_t *scan)
 {
-  ply_scan_token_t *curtoken = ply_scan_get_current_token (scan);
+  script_scan_token_t *curtoken = script_scan_get_current_token (scan);
 
-  if (!ply_scan_token_is_symbol_of_value (curtoken, '{'))
+  if (!script_scan_token_is_symbol_of_value (curtoken, '{'))
     return NULL;
-  ply_scan_get_next_token (scan);
+  script_scan_get_next_token (scan);
   ply_list_t *sublist = script_parse_op_list (scan);
-  if (!ply_scan_token_is_symbol_of_value (curtoken, '}'))
+  if (!script_scan_token_is_symbol_of_value (curtoken, '}'))
     {
-      script_parse_error (ply_scan_get_current_token (scan),
+      script_parse_error (script_scan_get_current_token (scan),
                           "Expected a '}' to terminate the operation block");
       return NULL;
     }
-  curtoken = ply_scan_get_next_token (scan);
+  curtoken = script_scan_get_next_token (scan);
 
   script_op_t *op = malloc (sizeof (script_op_t));
   op->type = SCRIPT_OP_TYPE_OP_BLOCK;
@@ -458,47 +458,47 @@ static script_op_t *script_parse_op_block (ply_scan_t *scan)
   return op;
 }
 
-static script_op_t *script_parse_if_while (ply_scan_t *scan)
+static script_op_t *script_parse_if_while (script_scan_t *scan)
 {
-  ply_scan_token_t *curtoken = ply_scan_get_current_token (scan);
+  script_scan_token_t *curtoken = script_scan_get_current_token (scan);
   script_op_type_t type;
 
-  if       (ply_scan_token_is_identifier_of_value (curtoken, "if"))
+  if       (script_scan_token_is_identifier_of_value (curtoken, "if"))
     type = SCRIPT_OP_TYPE_IF;
-  else if  (ply_scan_token_is_identifier_of_value (curtoken, "while"))
+  else if  (script_scan_token_is_identifier_of_value (curtoken, "while"))
     type = SCRIPT_OP_TYPE_WHILE;
   else return NULL;
-  curtoken = ply_scan_get_next_token (scan);
-  if (!ply_scan_token_is_symbol_of_value (curtoken, '('))
+  curtoken = script_scan_get_next_token (scan);
+  if (!script_scan_token_is_symbol_of_value (curtoken, '('))
     {
       script_parse_error (curtoken,
                           "Expected a '(' at the start of a condition block");
       return NULL;
     }
-  curtoken = ply_scan_get_next_token (scan);
+  curtoken = script_scan_get_next_token (scan);
 
   script_exp_t *cond = script_parse_exp (scan);
-  curtoken = ply_scan_get_current_token (scan);
+  curtoken = script_scan_get_current_token (scan);
   if (!cond)
     {
       script_parse_error (curtoken, "Expected a valid condition expression");
       return NULL;
     }
-  if (!ply_scan_token_is_symbol_of_value (curtoken, ')'))
+  if (!script_scan_token_is_symbol_of_value (curtoken, ')'))
     {
       script_parse_error (curtoken,
                           "Expected a ')' at the end of a condition block");
       return NULL;
     }
-  ply_scan_get_next_token (scan);
+  script_scan_get_next_token (scan);
   script_op_t *cond_op = script_parse_op (scan);
   script_op_t *else_op = NULL;
 
-  curtoken = ply_scan_get_current_token (scan);
+  curtoken = script_scan_get_current_token (scan);
   if ((type == SCRIPT_OP_TYPE_IF)
-      && (ply_scan_token_is_identifier_of_value (curtoken, "else")))
+      && (script_scan_token_is_identifier_of_value (curtoken, "else")))
     {
-      ply_scan_get_next_token (scan);
+      script_scan_get_next_token (scan);
       else_op = script_parse_op (scan);
     }
   script_op_t *op = malloc (sizeof (script_op_t));
@@ -509,19 +509,19 @@ static script_op_t *script_parse_if_while (ply_scan_t *scan)
   return op;
 }
 
-static script_op_t *script_parse_for (ply_scan_t *scan)
+static script_op_t *script_parse_for (script_scan_t *scan)
 {
-  ply_scan_token_t *curtoken = ply_scan_get_current_token (scan);
+  script_scan_token_t *curtoken = script_scan_get_current_token (scan);
 
-  if (!ply_scan_token_is_identifier_of_value (curtoken, "for")) return NULL;
-  curtoken = ply_scan_get_next_token (scan);
-  if (!ply_scan_token_is_symbol_of_value (curtoken, '('))
+  if (!script_scan_token_is_identifier_of_value (curtoken, "for")) return NULL;
+  curtoken = script_scan_get_next_token (scan);
+  if (!script_scan_token_is_symbol_of_value (curtoken, '('))
     {
       script_parse_error (curtoken,
                           "Expected a '(' at the start of a condition block");
       return NULL;
     }
-  curtoken = ply_scan_get_next_token (scan);
+  curtoken = script_scan_get_next_token (scan);
 
   script_exp_t *first = script_parse_exp (scan);
   if (!first)
@@ -529,14 +529,14 @@ static script_op_t *script_parse_for (ply_scan_t *scan)
       script_parse_error (curtoken, "Expected a valid first expression");
       return NULL;
     }
-  curtoken = ply_scan_get_current_token (scan);
-  if (!ply_scan_token_is_symbol_of_value (curtoken, ';'))
+  curtoken = script_scan_get_current_token (scan);
+  if (!script_scan_token_is_symbol_of_value (curtoken, ';'))
     {
       script_parse_error (curtoken,
                           "Expected a ';' after the first 'for' expression");
       return NULL;
     }
-  ply_scan_get_next_token (scan);
+  script_scan_get_next_token (scan);
 
   script_exp_t *cond = script_parse_exp (scan);
   if (!cond)
@@ -544,13 +544,13 @@ static script_op_t *script_parse_for (ply_scan_t *scan)
       script_parse_error (curtoken, "Expected a valid condition expression");
       return NULL;
     }
-  curtoken = ply_scan_get_current_token (scan);
-  if (!ply_scan_token_is_symbol_of_value (curtoken, ';'))
+  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");
       return NULL;
     }
-  ply_scan_get_next_token (scan);
+  script_scan_get_next_token (scan);
 
   script_exp_t *last = script_parse_exp (scan);
   if (!last)
@@ -558,13 +558,13 @@ static script_op_t *script_parse_for (ply_scan_t *scan)
       script_parse_error (curtoken, "Expected a valid last expression");
       return NULL;
     }
-  curtoken = ply_scan_get_current_token (scan);
-  if (!ply_scan_token_is_symbol_of_value (curtoken, ')'))
+  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");
       return NULL;
     }
-  ply_scan_get_next_token (scan);
+  script_scan_get_next_token (scan);
   script_op_t *op_body = script_parse_op (scan);
 
   script_op_t *op_first = malloc (sizeof (script_op_t));
@@ -590,13 +590,13 @@ static script_op_t *script_parse_for (ply_scan_t *scan)
   return op_block;
 }
 
-static script_op_t *script_parse_function (ply_scan_t *scan)
+static script_op_t *script_parse_function (script_scan_t *scan)
 {
-  ply_scan_token_t *curtoken = ply_scan_get_current_token (scan);
+  script_scan_token_t *curtoken = script_scan_get_current_token (scan);
 
-  if (!ply_scan_token_is_identifier_of_value (curtoken, "fun")) return NULL;
-  curtoken = ply_scan_get_next_token (scan);
-  if (!ply_scan_token_is_identifier (curtoken))
+  if (!script_scan_token_is_identifier_of_value (curtoken, "fun")) return NULL;
+  curtoken = script_scan_get_next_token (scan);
+  if (!script_scan_token_is_identifier (curtoken))
     {
       script_parse_error (curtoken,
                           "A function declaration requires a valid name");
@@ -606,7 +606,7 @@ static script_op_t *script_parse_function (ply_scan_t *scan)
   name->type = SCRIPT_EXP_TYPE_TERM_VAR;
   name->data.string = strdup (curtoken->data.string);
 
-  curtoken = ply_scan_get_next_token (scan);
+  curtoken = script_scan_get_next_token (scan);
 
   script_function_t *function = script_parse_function_def (scan);
   if (!function) return NULL;
@@ -618,41 +618,41 @@ static script_op_t *script_parse_function (ply_scan_t *scan)
   return op;
 }
 
-static script_op_t *script_parse_return (ply_scan_t *scan)
+static script_op_t *script_parse_return (script_scan_t *scan)
 {
-  ply_scan_token_t *curtoken = ply_scan_get_current_token (scan);
+  script_scan_token_t *curtoken = script_scan_get_current_token (scan);
   script_op_type_t type;
-  if      (ply_scan_token_is_identifier_of_value (curtoken, "return"))
+  if      (script_scan_token_is_identifier_of_value (curtoken, "return"))
     type = SCRIPT_OP_TYPE_RETURN;
-  else if (ply_scan_token_is_identifier_of_value (curtoken, "break"))
+  else if (script_scan_token_is_identifier_of_value (curtoken, "break"))
     type = SCRIPT_OP_TYPE_BREAK;
-  else if (ply_scan_token_is_identifier_of_value (curtoken, "continue"))
+  else if (script_scan_token_is_identifier_of_value (curtoken, "continue"))
     type = SCRIPT_OP_TYPE_CONTINUE;
   else return NULL;
-  curtoken = ply_scan_get_next_token (scan);
+  curtoken = script_scan_get_next_token (scan);
 
   script_op_t *op = malloc (sizeof (script_op_t));
   if (type == SCRIPT_OP_TYPE_RETURN)
     {
       op->data.exp = script_parse_exp (scan);                  /* May be NULL */
-      curtoken = ply_scan_get_current_token (scan);
+      curtoken = script_scan_get_current_token (scan);
     }
 #ifdef WITH_SEMIES
-  if (!ply_scan_token_is_symbol_of_value (curtoken, ';'))
+  if (!script_scan_token_is_symbol_of_value (curtoken, ';'))
     {
       script_parse_error (curtoken, "Expected ';' after an expression");
       return NULL;
     }
-  curtoken = ply_scan_get_next_token (scan);
+  curtoken = script_scan_get_next_token (scan);
 #endif
 
   op->type = type;
   return op;
 }
 
-static script_op_t *script_parse_op (ply_scan_t *scan)
+static script_op_t *script_parse_op (script_scan_t *scan)
 {
-  ply_scan_token_t *curtoken = ply_scan_get_current_token (scan);
+  script_scan_token_t *curtoken = script_scan_get_current_token (scan);
   script_op_t *reply = NULL;
 
   reply = script_parse_op_block (scan);
@@ -671,14 +671,14 @@ static script_op_t *script_parse_op (ply_scan_t *scan)
   {
     script_exp_t *exp = script_parse_exp (scan);
     if (!exp) return NULL;
-    curtoken = ply_scan_get_current_token (scan);
+    curtoken = script_scan_get_current_token (scan);
 #ifdef WITH_SEMIES
-    if (!ply_scan_token_is_symbol_of_value (curtoken, ';'))
+    if (!script_scan_token_is_symbol_of_value (curtoken, ';'))
       {
         script_parse_error (curtoken, "Expected ';' after an expression");
         return NULL;
       }
-    curtoken = ply_scan_get_next_token (scan);
+    curtoken = script_scan_get_next_token (scan);
 #endif
 
     script_op_t *op = malloc (sizeof (script_op_t));
@@ -689,7 +689,7 @@ static script_op_t *script_parse_op (ply_scan_t *scan)
   return NULL;
 }
 
-static ply_list_t *script_parse_op_list (ply_scan_t *scan)
+static ply_list_t *script_parse_op_list (script_scan_t *scan)
 {
   ply_list_t *op_list = ply_list_new ();
 
@@ -865,7 +865,7 @@ static void script_parse_op_list_free (ply_list_t *op_list)
 
 script_op_t *script_parse_file (const char *filename)
 {
-  ply_scan_t *scan = ply_scan_file (filename);
+  script_scan_t *scan = script_scan_file (filename);
 
   if (!scan)
     {
@@ -874,13 +874,13 @@ script_op_t *script_parse_file (const char *filename)
     }
   ply_list_t *list = script_parse_op_list (scan);
 
-  ply_scan_token_t *curtoken = ply_scan_get_current_token (scan);
-  if (curtoken->type != PLY_SCAN_TOKEN_TYPE_EOF)
+  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");
       return NULL;
     }
-  ply_scan_free (scan);
+  script_scan_free (scan);
   script_op_t *op = malloc (sizeof (script_op_t));
   op->type = SCRIPT_OP_TYPE_OP_BLOCK;
   op->data.list = list;
@@ -889,7 +889,7 @@ script_op_t *script_parse_file (const char *filename)
 
 script_op_t *script_parse_string (const char *string)
 {
-  ply_scan_t *scan = ply_scan_string (string);
+  script_scan_t *scan = script_scan_string (string);
 
   if (!scan)
     {
@@ -897,7 +897,7 @@ script_op_t *script_parse_string (const char *string)
       return NULL;
     }
   ply_list_t *list = script_parse_op_list (scan);
-  ply_scan_free (scan);
+  script_scan_free (scan);
   script_op_t *op = malloc (sizeof (script_op_t));
   op->type = SCRIPT_OP_TYPE_OP_BLOCK;
   op->data.list = list;
similarity index 67%
rename from src/plugins/splash/script/ply-scan.c
rename to src/plugins/splash/script/script-scan.c
index cc08398c5472c1f7624a9446cae4c4c25de1d596..5910b187d29160f2b8ac78c9146dddbe8dc3d9a9 100644 (file)
@@ -19,8 +19,6 @@
  *
  * Written by: Charlie Brej <cbrej@cs.man.ac.uk>
  */
-#include "ply-bitarray.h"
-#include "ply-scan.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <string.h>
 
+#include "ply-bitarray.h"
+#include "script-scan.h"
+
 #define COLUMN_START_INDEX 0
 
-static ply_scan_t *ply_scan_new (void)
+static script_scan_t *script_scan_new (void)
 {
   unsigned char *chars;
-  ply_scan_t *scan = calloc (1, sizeof (ply_scan_t));
+  script_scan_t *scan = calloc (1, sizeof (script_scan_t));
 
   scan->tokens = NULL;
   scan->tokencount = 0;
@@ -58,54 +59,54 @@ static ply_scan_t *ply_scan_new (void)
   return scan;
 }
 
-ply_scan_t *ply_scan_file (const char *filename)
+script_scan_t *script_scan_file (const char *filename)
 {
   int fd = open (filename, O_RDONLY);
   if (fd < 0) return NULL;
-  ply_scan_t *scan = ply_scan_new ();
+  script_scan_t *scan = script_scan_new ();
   scan->source.fd = fd;
   scan->source_is_file = true;
-  ply_scan_get_next_char (scan);
+  script_scan_get_next_char (scan);
   return scan;
 }
 
-ply_scan_t *ply_scan_string (const char *string)
+script_scan_t *script_scan_string (const char *string)
 {
-  ply_scan_t *scan = ply_scan_new ();
+  script_scan_t *scan = script_scan_new ();
   scan->source.string = string;
   scan->source_is_file = false;
-  ply_scan_get_next_char (scan);
+  script_scan_get_next_char (scan);
   return scan;
 }
 
-void ply_scan_token_clean (ply_scan_token_t *token)
+void script_scan_token_clean (script_scan_token_t *token)
 {
   switch (token->type)
     {
-      case PLY_SCAN_TOKEN_TYPE_EMPTY:
-      case PLY_SCAN_TOKEN_TYPE_EOF:
-      case PLY_SCAN_TOKEN_TYPE_INTEGER:
-      case PLY_SCAN_TOKEN_TYPE_FLOAT:
-      case PLY_SCAN_TOKEN_TYPE_SYMBOL:
+      case script_scan_TOKEN_TYPE_EMPTY:
+      case script_scan_TOKEN_TYPE_EOF:
+      case script_scan_TOKEN_TYPE_INTEGER:
+      case script_scan_TOKEN_TYPE_FLOAT:
+      case script_scan_TOKEN_TYPE_SYMBOL:
         break;
-      case PLY_SCAN_TOKEN_TYPE_IDENTIFIER:
-      case PLY_SCAN_TOKEN_TYPE_STRING:
-      case PLY_SCAN_TOKEN_TYPE_COMMENT:
-      case PLY_SCAN_TOKEN_TYPE_ERROR:
+      case script_scan_TOKEN_TYPE_IDENTIFIER:
+      case script_scan_TOKEN_TYPE_STRING:
+      case script_scan_TOKEN_TYPE_COMMENT:
+      case script_scan_TOKEN_TYPE_ERROR:
         free (token->data.string);
         break;
     }
-  token->type = PLY_SCAN_TOKEN_TYPE_EMPTY;
+  token->type = script_scan_TOKEN_TYPE_EMPTY;
   token->whitespace = 0;
 }
 
-void ply_scan_free (ply_scan_t *scan)
+void script_scan_free (script_scan_t *scan)
 {
   int i;
   if (scan->source_is_file) close (scan->source.fd);
   for (i = 0; i < scan->tokencount; i++)
     {
-      ply_scan_token_clean (scan->tokens[i]);
+      script_scan_token_clean (scan->tokens[i]);
       free (scan->tokens[i]);
     }
   ply_bitarray_free (scan->identifier_1st_char);
@@ -114,12 +115,12 @@ void ply_scan_free (ply_scan_t *scan)
   free (scan);
 }
 
-unsigned char ply_scan_get_current_char (ply_scan_t *scan)
+unsigned char script_scan_get_current_char (script_scan_t *scan)
 {
   return scan->cur_char;
 }
 
-unsigned char ply_scan_get_next_char (ply_scan_t *scan)
+unsigned char script_scan_get_next_char (script_scan_t *scan)
 {
   if (scan->cur_char == '\n')
     {
@@ -141,10 +142,10 @@ unsigned char ply_scan_get_next_char (ply_scan_t *scan)
   return scan->cur_char;
 }
 
-void ply_scan_read_next_token (ply_scan_t       *scan,
-                               ply_scan_token_t *token)
+void script_scan_read_next_token (script_scan_t       *scan,
+                               script_scan_token_t *token)
 {
-  unsigned char curchar = ply_scan_get_current_char (scan);     /* FIXME Double check these unsigned chars are ok */
+  unsigned char curchar = script_scan_get_current_char (scan);     /* FIXME Double check these unsigned chars are ok */
   unsigned char nextchar;
 
   token->whitespace = 0;
@@ -152,19 +153,19 @@ void ply_scan_read_next_token (ply_scan_t       *scan,
     {
       if (curchar == ' ')
         {
-          curchar = ply_scan_get_next_char (scan);
+          curchar = script_scan_get_next_char (scan);
           token->whitespace++;
           continue;
         }                                                                                           /* FIXME restrcuture */
       if (curchar == '\n')
         {
-          curchar = ply_scan_get_next_char (scan);
+          curchar = script_scan_get_next_char (scan);
           token->whitespace++;
           continue;
         }
       if (curchar == '\t')
         {
-          curchar = ply_scan_get_next_char (scan);
+          curchar = script_scan_get_next_char (scan);
           token->whitespace++;
           continue;
         }
@@ -172,12 +173,12 @@ void ply_scan_read_next_token (ply_scan_t       *scan,
     }
   token->line_index = scan->line_index;
   token->column_index = scan->column_index;
-  nextchar = ply_scan_get_next_char (scan);
+  nextchar = script_scan_get_next_char (scan);
 
   if (ply_bitarray_lookup (scan->identifier_1st_char, curchar))
     {
       int index = 1;
-      token->type = PLY_SCAN_TOKEN_TYPE_IDENTIFIER;
+      token->type = script_scan_TOKEN_TYPE_IDENTIFIER;
       token->data.string =  malloc (2 * sizeof (char));
       token->data.string[0] = curchar;
       token->data.string[1] = '\0';
@@ -189,7 +190,7 @@ void ply_scan_read_next_token (ply_scan_t       *scan,
           token->data.string[index] = curchar;
           token->data.string[index + 1] = '\0';
           index++;
-          curchar = ply_scan_get_next_char (scan);
+          curchar = script_scan_get_next_char (scan);
         }
       return;
     }
@@ -201,7 +202,7 @@ void ply_scan_read_next_token (ply_scan_t       *scan,
         {
           int_value *= 10;
           int_value += curchar - '0';
-          curchar = ply_scan_get_next_char (scan);
+          curchar = script_scan_get_next_char (scan);
         }
 
       if (curchar == '.')
@@ -209,31 +210,31 @@ void ply_scan_read_next_token (ply_scan_t       *scan,
           double floatpoint = int_value;
           double scalar = 1;
 
-          curchar = ply_scan_get_next_char (scan);
+          curchar = script_scan_get_next_char (scan);
           while (curchar >= '0' && curchar <= '9')
             {
               scalar /= 10;
               floatpoint += scalar * (curchar - '0');
-              curchar = ply_scan_get_next_char (scan);
+              curchar = script_scan_get_next_char (scan);
             }
-          token->type = PLY_SCAN_TOKEN_TYPE_FLOAT;
+          token->type = script_scan_TOKEN_TYPE_FLOAT;
           token->data.floatpoint = floatpoint;
         }
       else
         {
-          token->type = PLY_SCAN_TOKEN_TYPE_INTEGER;
+          token->type = script_scan_TOKEN_TYPE_INTEGER;
           token->data.integer = int_value;
         }
       return;
     }
   if (!curchar)
     {
-      token->type = PLY_SCAN_TOKEN_TYPE_EOF;
+      token->type = script_scan_TOKEN_TYPE_EOF;
       return;
     }
   if (curchar == '\"')
     {
-      token->type = PLY_SCAN_TOKEN_TYPE_STRING;
+      token->type = script_scan_TOKEN_TYPE_STRING;
       int index = 0;
       token->data.string = malloc (sizeof (char));
       token->data.string[0] = '\0';
@@ -244,18 +245,18 @@ void ply_scan_read_next_token (ply_scan_t       *scan,
           if (curchar == '\0')
             {
               token->data.string = strdup("End of file before end of string");
-              token->type = PLY_SCAN_TOKEN_TYPE_ERROR;
+              token->type = script_scan_TOKEN_TYPE_ERROR;
               return;
             }
           if (curchar == '\n')
             {
               token->data.string = strdup("Line terminator before end of string");
-              token->type = PLY_SCAN_TOKEN_TYPE_ERROR;
+              token->type = script_scan_TOKEN_TYPE_ERROR;
               return;
             }
           if (curchar == '\\')
             {
-              curchar = ply_scan_get_next_char (scan);
+              curchar = script_scan_get_next_char (scan);
               switch (curchar)
                 {
                   case 'n':
@@ -279,9 +280,9 @@ void ply_scan_read_next_token (ply_scan_t       *scan,
           token->data.string[index] = curchar;
           token->data.string[index + 1] = '\0';
           index++;
-          curchar = ply_scan_get_next_char (scan);
+          curchar = script_scan_get_next_char (scan);
         }
-      ply_scan_get_next_char (scan);
+      script_scan_get_next_char (scan);
       return;
     }
   {
@@ -290,7 +291,7 @@ void ply_scan_read_next_token (ply_scan_t       *scan,
     if ((curchar == '/') && (nextchar == '/'))
       {
         linecomment = true;
-        nextchar = ply_scan_get_next_char (scan);
+        nextchar = script_scan_get_next_char (scan);
       }
     if (linecomment)
       {
@@ -300,7 +301,7 @@ void ply_scan_read_next_token (ply_scan_t       *scan,
         curchar = nextchar;
         for (curchar = nextchar;
              curchar != '\n' && curchar != '\0';
-             curchar = ply_scan_get_next_char (scan))
+             curchar = script_scan_get_next_char (scan))
           {
             token->data.string = realloc (token->data.string,
                                           (index + 2) * sizeof (char));
@@ -308,7 +309,7 @@ void ply_scan_read_next_token (ply_scan_t       *scan,
             token->data.string[index + 1] = '\0';
             index++;
           }
-        token->type = PLY_SCAN_TOKEN_TYPE_COMMENT;
+        token->type = script_scan_TOKEN_TYPE_COMMENT;
         return;
       }
   }
@@ -319,8 +320,8 @@ void ply_scan_read_next_token (ply_scan_t       *scan,
       int depth = 1;
       token->data.string = malloc (sizeof (char));
       token->data.string[0] = '\0';
-      curchar = ply_scan_get_next_char (scan);
-      nextchar = ply_scan_get_next_char (scan);
+      curchar = script_scan_get_next_char (scan);
+      nextchar = script_scan_get_next_char (scan);
 
       while (true)
         {
@@ -328,7 +329,7 @@ void ply_scan_read_next_token (ply_scan_t       *scan,
             {
               free (token->data.string);
               token->data.string = strdup("End of file before end of comment");
-              token->type = PLY_SCAN_TOKEN_TYPE_ERROR;
+              token->type = script_scan_TOKEN_TYPE_ERROR;
               return;
             }
           if ((curchar == '/') && (nextchar == '*'))
@@ -344,19 +345,19 @@ void ply_scan_read_next_token (ply_scan_t       *scan,
           token->data.string[index + 1] = '\0';
           index++;
           curchar = nextchar;
-          nextchar = ply_scan_get_next_char (scan);
+          nextchar = script_scan_get_next_char (scan);
         }
-      ply_scan_get_next_char (scan);
-      token->type = PLY_SCAN_TOKEN_TYPE_COMMENT;
+      script_scan_get_next_char (scan);
+      token->type = script_scan_TOKEN_TYPE_COMMENT;
       return;
     }
   /* all other */
-  token->type = PLY_SCAN_TOKEN_TYPE_SYMBOL;
+  token->type = script_scan_TOKEN_TYPE_SYMBOL;
   token->data.symbol = curchar;
   return;
 }
 
-static ply_scan_token_t *ply_scan_peek_token (ply_scan_t *scan,
+static script_scan_token_t *script_scan_peek_token (script_scan_t *scan,
                                               int         n)
 {
   int i;
@@ -364,45 +365,45 @@ static ply_scan_token_t *ply_scan_peek_token (ply_scan_t *scan,
   if (scan->tokencount <= n)
     {
       scan->tokens =
-        realloc (scan->tokens, (n + 1) * sizeof (ply_scan_token_t *));
+        realloc (scan->tokens, (n + 1) * sizeof (script_scan_token_t *));
       for (i = scan->tokencount; i <= n; i++)                                   /* FIXME warning about possibely inifnite loop */
         {
-          scan->tokens[i] = malloc (sizeof (ply_scan_token_t));
-          scan->tokens[i]->type = PLY_SCAN_TOKEN_TYPE_EMPTY;
+          scan->tokens[i] = malloc (sizeof (script_scan_token_t));
+          scan->tokens[i]->type = script_scan_TOKEN_TYPE_EMPTY;
         }
       scan->tokencount = n + 1;
     }
-  if (scan->tokens[n]->type == PLY_SCAN_TOKEN_TYPE_EMPTY)
+  if (scan->tokens[n]->type == script_scan_TOKEN_TYPE_EMPTY)
     {
-      if ((n > 0) && (scan->tokens[n - 1]->type == PLY_SCAN_TOKEN_TYPE_EMPTY))
-        ply_scan_peek_token (scan, n - 1);
+      if ((n > 0) && (scan->tokens[n - 1]->type == script_scan_TOKEN_TYPE_EMPTY))
+        script_scan_peek_token (scan, n - 1);
       do
         {
-          ply_scan_token_clean (scan->tokens[n]);
-          ply_scan_read_next_token (scan, scan->tokens[n]);                     /* FIXME if skipping comments, add whitespace to next token */
+          script_scan_token_clean (scan->tokens[n]);
+          script_scan_read_next_token (scan, scan->tokens[n]);                     /* FIXME if skipping comments, add whitespace to next token */
         }
-      while (scan->tokens[n]->type == PLY_SCAN_TOKEN_TYPE_COMMENT);             /* FIXME optionally pass comments back */
+      while (scan->tokens[n]->type == script_scan_TOKEN_TYPE_COMMENT);             /* FIXME optionally pass comments back */
     }
   return scan->tokens[n];
 }
 
-ply_scan_token_t *ply_scan_get_next_token (ply_scan_t *scan)
+script_scan_token_t *script_scan_get_next_token (script_scan_t *scan)
 {
   int i;
-  ply_scan_token_clean (scan->tokens[0]);
+  script_scan_token_clean (scan->tokens[0]);
   for (i = 0; i < (scan->tokencount - 1); i++)
     *scan->tokens[i] = *scan->tokens[i + 1];
-  scan->tokens[(scan->tokencount - 1)]->type = PLY_SCAN_TOKEN_TYPE_EMPTY;
-  return ply_scan_peek_token (scan, 0);
+  scan->tokens[(scan->tokencount - 1)]->type = script_scan_TOKEN_TYPE_EMPTY;
+  return script_scan_peek_token (scan, 0);
 }
 
-ply_scan_token_t *ply_scan_get_current_token (ply_scan_t *scan)
+script_scan_token_t *script_scan_get_current_token (script_scan_t *scan)
 {
-  return ply_scan_peek_token (scan, 0);
+  return script_scan_peek_token (scan, 0);
 }
 
-ply_scan_token_t *ply_scan_peek_next_token (ply_scan_t *scan)
+script_scan_token_t *script_scan_peek_next_token (script_scan_t *scan)
 {
-  return ply_scan_peek_token (scan, 1);
+  return script_scan_peek_token (scan, 1);
 }
 
diff --git a/src/plugins/splash/script/script-scan.h b/src/plugins/splash/script/script-scan.h
new file mode 100644 (file)
index 0000000..355bf68
--- /dev/null
@@ -0,0 +1,107 @@
+/* ply-scan.h - lexical scanner
+ *
+ * Copyright (C) 2009 Charlie Brej <cbrej@cs.man.ac.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Written by: Charlie Brej <cbrej@cs.man.ac.uk>
+ */
+#ifndef script_scan_H
+#define script_scan_H
+
+#include "ply-bitarray.h"
+#include <stdbool.h>
+
+typedef enum
+{
+  script_scan_TOKEN_TYPE_EMPTY,
+  script_scan_TOKEN_TYPE_EOF,
+  script_scan_TOKEN_TYPE_INTEGER,
+  script_scan_TOKEN_TYPE_FLOAT,
+  script_scan_TOKEN_TYPE_IDENTIFIER,
+  script_scan_TOKEN_TYPE_STRING,
+  script_scan_TOKEN_TYPE_SYMBOL,
+  script_scan_TOKEN_TYPE_COMMENT,
+  script_scan_TOKEN_TYPE_ERROR,
+} script_scan_token_type_t;
+
+typedef struct
+{
+  script_scan_token_type_t type;
+  union
+  {
+    char *string;
+    char symbol;
+    long long int integer;
+    double floatpoint;
+  } data;
+  int whitespace;
+  int line_index;
+  int column_index;
+} script_scan_token_t;
+
+typedef struct
+{
+  union
+  {
+    int fd;
+    const char *string;
+  } source;
+  unsigned char cur_char;
+  ply_bitarray_t *identifier_1st_char;
+  ply_bitarray_t *identifier_nth_char;
+  int tokencount;
+  script_scan_token_t **tokens;
+  int line_index;
+  int column_index;
+  bool source_is_file;
+} script_scan_t;
+
+
+#define script_scan_token_is_symbol(__token) \
+      (__token->type == script_scan_TOKEN_TYPE_SYMBOL)
+#define script_scan_token_is_symbol_of_value(__token,__value) \
+      (__token->type == script_scan_TOKEN_TYPE_SYMBOL \
+      && __token->data.symbol == __value)
+#define script_scan_token_is_identifier(__token) \
+      (__token->type == script_scan_TOKEN_TYPE_IDENTIFIER)
+#define script_scan_token_is_identifier_of_value(__token,__value) \
+      (__token->type == script_scan_TOKEN_TYPE_IDENTIFIER \
+      && !strcmp(__token->data.string, __value))
+#define script_scan_token_is_integer(__token) \
+      (__token->type == script_scan_TOKEN_TYPE_INTEGER)
+#define script_scan_token_is_string(__token) \
+      (__token->type == script_scan_TOKEN_TYPE_STRING)
+#define script_scan_token_is_float(__token) \
+      (__token->type == script_scan_TOKEN_TYPE_FLOAT)
+
+
+
+
+script_scan_t *script_scan_file (const char *filename);
+script_scan_t *script_scan_string (const char *string);
+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);
+unsigned char script_scan_get_next_char (script_scan_t *scan);
+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);
+
+
+#endif /* script_scan_H */
index db95047c91f1c02d2de7bc6da91c5ad9ca4196cb..525cb083316c4395ec0f6a4711ce639648fcc1fb 100644 (file)
@@ -20,7 +20,6 @@
  * Written by: Charlie Brej <cbrej@cs.man.ac.uk>
  */
 #define _GNU_SOURCE
-#include "ply-scan.h"
 #include "ply-hashtable.h"
 #include "ply-list.h"
 #include "ply-bitarray.h"
index 64997be9b4c8b229f79b549d4bc8f57f497ebaa8..338b9bd1da5e3a7d4de7193b2f50712b0b4092ca 100644 (file)
@@ -24,7 +24,6 @@
 
 #include "ply-hashtable.h"
 #include "ply-list.h"
-#include "ply-scan.h"
 
 typedef enum                        /* FIXME add _t to all types */
 {