commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnue/geas/src/classdef parse.y scan.l


From: Reinhard Mueller
Subject: gnue/geas/src/classdef parse.y scan.l
Date: Mon, 29 Oct 2001 16:45:49 -0500

CVSROOT:        /cvsroot/gnue
Module name:    gnue
Changes by:     Reinhard Mueller <address@hidden>       01/10/29 16:45:49

Modified files:
        geas/src/classdef: parse.y scan.l 

Log message:
        Moved checking of underscore naming rules from the scanner to the parse 
to make error recovery possible.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/geas/src/classdef/parse.y.diff?tr1=1.18&tr2=1.19&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/geas/src/classdef/scan.l.diff?tr1=1.7&tr2=1.8&r1=text&r2=text

Patches:
Index: gnue/geas/src/classdef/parse.y
diff -u gnue/geas/src/classdef/parse.y:1.18 gnue/geas/src/classdef/parse.y:1.19
--- gnue/geas/src/classdef/parse.y:1.18 Sat Oct 20 16:49:10 2001
+++ gnue/geas/src/classdef/parse.y      Mon Oct 29 16:45:49 2001
@@ -19,7 +19,7 @@
    along with GEAS; if not, write to the Free Software Foundation, Inc.,
    59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
-   $Id: parse.y,v 1.18 2001/10/20 20:49:10 reinhard Exp $
+   $Id: parse.y,v 1.19 2001/10/29 21:45:49 reinhard Exp $
 */
 
 %{
@@ -61,9 +61,9 @@
 
 static void yyerror (const char *message, ...);
 
-/* functions that are called wile parsing */
+/* functions that are called while parsing */
 
-static void     _new_module (const gchar *name, geas_cd_access access);
+static gboolean _new_module (const gchar *name, geas_cd_access access);
 static gboolean _new_class  (const gchar *name, geas_cd_access access);
 static void     _set_class  (geas_cd_class *clss);
 static gboolean _new_type   (const gchar *name, geas_cd_access access);
@@ -77,13 +77,13 @@
 static void _set_type_ref  (geas_cd_class *clss);
 static void _set_type_list (geas_cd_class *clss);
 
-static gboolean _name_used (const gchar *name);
+static gboolean _name_ok (const gchar *name);
 
-static void _new_field (const gchar *name);
-static void _new_reference (const gchar *name, geas_cd_field *thisfield,
-                            geas_cd_field *otherfield);
-static void _new_list (const gchar *name, geas_cd_field *thisfield,
-                       geas_cd_field *otherfield);
+static gboolean _new_field (const gchar *name);
+static gboolean _new_reference (const gchar *name, geas_cd_field *thisfield,
+                                geas_cd_field *otherfield);
+static gboolean _new_list (const gchar *name, geas_cd_field *thisfield,
+                           geas_cd_field *otherfield);
 
 static gboolean _set_field_format (int format);
 
@@ -161,7 +161,12 @@
   |         PRIVATE                     { $$ = GEAS_CD_ACCESS_PRIVATE; }
 ;
 
-module:     access MODULE SYMBOL        { _new_module ($3, $1); g_free ($3); }
+module:     access MODULE SYMBOL        {
+                                          gboolean result;
+                                          result = _new_module ($3, $1);
+                                          g_free ($3);
+                                          if (!result) YYERROR;
+                                        }
 ;
 
 units:      unit
@@ -269,7 +274,7 @@
   |         classref '[' ']'            { _set_type_list ($1); }
 ;
 
-elemname:   SYMBOL                      { if (_name_used ($1)) YYERROR; }
+elemname:   SYMBOL                      { if (!_name_ok ($1)) YYERROR; }
 ;
 
 thisfield:  SYMBOL                      {
@@ -290,15 +295,19 @@
 
 reference:  elemname ':' otherfield '=' thisfield
                                         {
-                                          _new_reference ($1, $5, $3);
+                                          gboolean result;
+                                          result = _new_reference ($1, $5, $3);
                                           g_free ($1);
+                                          if (!result) YYERROR;
                                         }
 ;
 
 list:       elemname ':' otherfield '=' thisfield
                                         {
-                                          _new_list ($1, $5, $3);
+                                          gboolean result;
+                                          result = _new_list ($1, $5, $3);
                                           g_free ($1);
+                                          if (!result) YYERROR;
                                         }
 ;
 
@@ -310,7 +319,12 @@
   |         fields ',' field
 ;
 
-field:      elemname                    { _new_field ($1); g_free ($1); }
+field:      elemname                    {
+                                          gboolean result;
+                                          result = _new_field ($1);
+                                          g_free ($1);
+                                          if (!result) YYERROR;
+                                        }
             /* continued */ format fdefault properties
 ;
 
@@ -480,21 +494,54 @@
 }
 
 /* ------------------------------------------------------------------------- *\
+ * Check if a new identifier is valid
+\* ------------------------------------------------------------------------- */
+static gboolean
+_validate_identifier (const char *name)
+{
+  if (name[0] == '_')
+    {
+      yyerror ("leading underscores are not allowed in identifiers");
+      return (FALSE);
+    }
+  else if (name[strlen (name) - 1] == '_')
+    {
+      yyerror ("trailing underscores are not allowed in identifiers");
+      return (FALSE);
+    }
+  else if (strstr (name, "__"))
+    {
+      yyerror ("double underscores are not allowed in identifiers");
+      return (FALSE);
+    }
+  else
+    {
+      return (TRUE);
+    }
+}
+
+/* ------------------------------------------------------------------------- *\
  * [PUBLIC|PRIVATE] MODULE <name>
 \* ------------------------------------------------------------------------- */
-static void
+static gboolean
 _new_module (const gchar *name, geas_cd_access access)
 {
   switch (_current_pass)
     {
     case 1:
     case 2:
+      if (!_validate_identifier (name))
+        {
+          return (FALSE);
+        }
       _current_module = geas_cd_module_new (name, access);
       g_assert (_current_module);
+      return (TRUE);
       break;
 
     default:
       g_assert_not_reached ();
+      return (FALSE);
     }
 }
 
@@ -525,6 +572,10 @@
 
     case 2:
       /* The class must be new, otherwise the classname is duplicate. */
+      if (!_validate_identifier (name))
+        {
+          return (FALSE);
+        }
       _current_is_class = TRUE;
       _current_type = NULL;
       if (geas_cd_module_find_class (_current_module, name))
@@ -589,6 +640,10 @@
 
     case 2:
       /* The type must be new, otherwise the typename is duplicate. */
+      if (!_validate_identifier (name))
+        {
+          return (FALSE);
+        }
       _current_is_class = FALSE;
       _current_class = NULL;
       if (geas_cd_module_find_type (_current_module, name))
@@ -860,26 +915,29 @@
  * Test if a name is used in the current class or type
 \* ------------------------------------------------------------------------- */
 static gboolean
-_name_used (const gchar *name)
+_name_ok (const gchar *name)
 {
   switch (_current_pass)
     {
     case 1:
-      return (FALSE);
+      return (TRUE);
       break;
 
     case 2:
+      if (!_validate_identifier (name))
+        {
+          return (FALSE);
+        }
       if (_current_is_class)
         {
           if (geas_cd_class_find_field (_current_class, _current_module, name))
             {
               yyerror ("duplicate field or method name");
-              _current_field = NULL;
-              return (TRUE);
+              return (FALSE);
             }
           else
             {
-              return (FALSE);
+              return (TRUE);
             }
         }
       else
@@ -887,12 +945,11 @@
           if (geas_cd_type_find_field (_current_type, name))
             {
               yyerror ("duplicate field name");
-              _current_field = NULL;
-              return (TRUE);
+              return (FALSE);
             }
           else
             {
-              return (FALSE);
+              return (TRUE);
             }
         }
       break;
@@ -906,12 +963,13 @@
 /* ------------------------------------------------------------------------- *\
  * Found a new field
 \* ------------------------------------------------------------------------- */
-static void
+static gboolean
 _new_field (const gchar *name)
 {
   switch (_current_pass)
     {
     case 1:
+      return (TRUE);
       break;
 
     case 2:
@@ -973,52 +1031,64 @@
               g_assert_not_reached ();
             }
         }
+      return (TRUE);
       break;
 
     default:
       g_assert_not_reached ();
+      return (FALSE);
     }
 }
 
 /* ------------------------------------------------------------------------- *\
  * Found a new reference
 \* ------------------------------------------------------------------------- */
-static void
+static gboolean
 _new_reference (const gchar *name, geas_cd_field *thisfield,
                 geas_cd_field *otherfield)
 {
   switch (_current_pass)
     {
     case 1:
+      return (TRUE);
       break;
 
     case 2:
       _current_field = geas_cd_class_reference_new
         (_current_class, _current_module, name,
          geas_cd_field_get_thisclass (otherfield), thisfield, otherfield);
+      return (TRUE);
+      break;
+
     default:
       g_assert_not_reached ();
+      return (FALSE);
     }
 }
 
 /* ------------------------------------------------------------------------- *\
  * Found a new list
 \* ------------------------------------------------------------------------- */
-static void
+static gboolean
 _new_list (const gchar *name, geas_cd_field *thisfield,
            geas_cd_field *otherfield)
 {
   switch (_current_pass)
     {
     case 1:
+      return (TRUE);
       break;
 
     case 2:
       _current_field = geas_cd_class_list_new
         (_current_class, _current_module, name,
          geas_cd_field_get_thisclass (otherfield), thisfield, otherfield);
+      return (TRUE);
+      break;
+
     default:
       g_assert_not_reached ();
+      return (FALSE);
     }
 }
 
Index: gnue/geas/src/classdef/scan.l
diff -u gnue/geas/src/classdef/scan.l:1.7 gnue/geas/src/classdef/scan.l:1.8
--- gnue/geas/src/classdef/scan.l:1.7   Sat Sep 22 18:21:09 2001
+++ gnue/geas/src/classdef/scan.l       Mon Oct 29 16:45:49 2001
@@ -19,7 +19,7 @@
    along with GEAS; if not, write to the Free Software Foundation, Inc.,
    59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
-   $Id: scan.l,v 1.7 2001/09/22 22:21:09 reinhard Exp $
+   $Id: scan.l,v 1.8 2001/10/29 21:45:49 reinhard Exp $
 */
 
 %option case-insensitive
@@ -153,15 +153,7 @@
   * Identifiers
  \* ------------------------------------------------------------------------ */
 
- /* FIXME: This must be handled in parse.y or error recovery doesn't work */
-_{WORD}             { TTP; _geas_cd_scan_error ("leading underscores are not "
-                                    "allowed in identifiers"); }
-{WORD}__{ALPHANUM}+ { TTP; _geas_cd_scan_error ("double underscores are not "
-                                    "allowed in identifiers"); }
-{WORD}_             { TTP; _geas_cd_scan_error ("trailing underscores are not "
-                                    "allowed in identifiers"); }
-
-{WORD}              { TTP; yylval.string = g_strdup (yytext); return (SYMBOL); 
}
+{WORD} { TTP; yylval.string = g_strdup (yytext); return (SYMBOL); }
                         
  /* ------------------------------------------------------------------------ *\
   * Other single-character items like <, >, =, etc.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]