]> git.saurik.com Git - bison.git/blobdiff - src/scan-gram.l
Regen.
[bison.git] / src / scan-gram.l
index da041a4fa270e936eaad77518711935828c02b08..5f7ac60e73b818c14747619288ec8ace3fc98804 100644 (file)
@@ -1,6 +1,6 @@
 /* Bison Grammar Scanner                             -*- C -*-
 
-   Copyright (C) 2002 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003 Free Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
 
@@ -154,10 +154,15 @@ splice     (\\[ \f\t\v]*\n)*
 <INITIAL,SC_AFTER_IDENTIFIER,SC_PRE_CODE>
 {
   [ \f\n\t\v]  ;
+  ","         warn_at (*loc, _("stray `,' treated as white space"));
 
   /* Comments. */
-  "/*"         token_start = loc->start; context_state = YY_START; BEGIN SC_YACC_COMMENT;
   "//".*       ;
+  "/*" {
+    token_start = loc->start;
+    context_state = YY_START;
+    BEGIN SC_YACC_COMMENT;
+  }
 
   /* #line directives are not documented, and may be withdrawn or
      modified in future versions of Bison.  */
@@ -215,10 +220,6 @@ splice      (\\[ \f\t\v]*\n)*
   "|"                     rule_length = 0; return PIPE;
   ";"                     return SEMICOLON;
 
-  "," {
-    warn_at (*loc, _("stray `,' treated as white space"));
-  }
-
   {id} {
     val->symbol = symbol_get (yytext, *loc);
     id_loc = *loc;
@@ -542,9 +543,28 @@ splice      (\\[ \f\t\v]*\n)*
   "{"|"<"{splice}"%"  STRING_GROW; braces_level++;
   "%"{splice}">"      STRING_GROW; braces_level--;
   "}" {
-    STRING_GROW;
-    braces_level--;
-    if (braces_level < 0)
+    bool outer_brace = --braces_level < 0;
+
+    /* As an undocumented Bison extension, append `;' before the last
+       brace in braced code, so that the user code can omit trailing
+       `;'.  But do not append `;' if emulating Yacc, since Yacc does
+       not append one.
+
+       FIXME: Bison should warn if a semicolon seems to be necessary
+       here, and should omit the semicolon if it seems unnecessary
+       (e.g., after ';', '{', or '}', each followed by comments or
+       white space).  Such a warning shouldn't depend on --yacc; it
+       should depend on a new --pedantic option, which would cause
+       Bison to warn if it detects an extension to POSIX.  --pedantic
+       should also diagnose other Bison extensions like %yacc.
+       Perhaps there should also be a GCC-style --pedantic-errors
+       option, so that such warnings are diagnosed as errors.  */
+    if (outer_brace && token_type == BRACED_CODE && ! yacc_flag)
+      obstack_1grow (&obstack_for_string, ';');
+
+    obstack_1grow (&obstack_for_string, '}');
+
+    if (outer_brace)
       {
        STRING_FINISH;
        rule_length++;
@@ -662,14 +682,14 @@ adjust_location (location *loc, char const *token, size_t size)
 static size_t
 no_cr_read (FILE *fp, char *buf, size_t size)
 {
-  size_t s = fread (buf, 1, size, fp);
-  if (s)
+  size_t bytes_read = fread (buf, 1, size, fp);
+  if (bytes_read)
     {
-      char *w = memchr (buf, '\r', s);
+      char *w = memchr (buf, '\r', bytes_read);
       if (w)
        {
          char const *r = ++w;
-         char const *lim = buf + s;
+         char const *lim = buf + bytes_read;
 
          for (;;)
            {
@@ -698,7 +718,7 @@ no_cr_read (FILE *fp, char *buf, size_t size)
        }
     }
 
-  return s;
+  return bytes_read;
 }