]> git.saurik.com Git - bison.git/blobdiff - src/scan-gram.l
Do not let the scan-skel token buffer grow unboundedly in the usual case.
[bison.git] / src / scan-gram.l
index da041a4fa270e936eaad77518711935828c02b08..a2c61fd67e9ea92fb6dcbd59aff19aef47ef5b93 100644 (file)
@@ -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++;