]> git.saurik.com Git - bison.git/blobdiff - src/scan-code.l
skeletons: b4_dollar_pushdef and popdef to simpify complex definitions
[bison.git] / src / scan-code.l
index e30bf9db6b6837135d2ff5e5fc535347df0cc63a..31befe9172f9bc7e8d6c99f543e4f8c5649ff2af 100644 (file)
@@ -98,11 +98,15 @@ ref      -?[0-9]+|{id}|"["{id}"]"|"$"
   int braces_level = 0;
 
   /* Whether a semicolon is probably needed.
-     The heuristic is that a semicolon is not needed after '{', '}', ';',
-     or a C preprocessor directive, and that whitespaces and comments
-     do not affect this flag.
-     Note that '{' does not need a semicolon because of '{}'.
-     A semicolon may be needed before a cpp direcive, but don't bother.  */
+
+     The heuristic is that a semicolon is not needed after '{', '}',
+     ';', or a C preprocessor directive, and that whitespaces and
+     comments do not affect this flag.  Note that '{' does not need a
+     semicolon because of '{}'.  A semicolon may be needed before a
+     cpp directive, but don't bother.
+
+     While it is maintained in several start-conditions (factoring
+     opportunities), it is meaningful only for SC_RULE_ACTION. */
   bool need_semicolon = false;
 
   /* Whether in a C preprocessor directive.  Don't use a start condition
@@ -160,7 +164,8 @@ ref      -?[0-9]+|{id}|"["{id}"]"|"$"
 }
 
 
-<SC_RULE_ACTION,SC_SYMBOL_ACTION>{
+<SC_RULE_ACTION,SC_SYMBOL_ACTION>
+{
   "'" {
     STRING_GROW;
     BEGIN SC_CHARACTER;
@@ -179,6 +184,15 @@ ref      -?[0-9]+|{id}|"["{id}"]"|"$"
     STRING_GROW;
     BEGIN SC_LINE_COMMENT;
   }
+  [$@]  {
+    warn_at (*loc, _("stray '%s'"), yytext);
+    obstack_escape (&obstack_for_string, yytext);
+    need_semicolon = true;
+  }
+  [\[\]]  {
+    obstack_escape (&obstack_for_string, yytext);
+    need_semicolon = true;
+  }
 }
 
 <SC_RULE_ACTION>
@@ -197,24 +211,6 @@ ref      -?[0-9]+|{id}|"["{id}"]"|"$"
       obstack_sgrow (&obstack_for_string, ref_tail_fields);
     need_semicolon = true;
   }
-  "$"  {
-    warn_at (*loc, _("stray '$'"));
-    obstack_sgrow (&obstack_for_string, "$][");
-    need_semicolon = true;
-  }
-  "@"  {
-    warn_at (*loc, _("stray '@'"));
-    obstack_sgrow (&obstack_for_string, "@@");
-    need_semicolon = true;
-  }
-  "["  {
-    obstack_sgrow (&obstack_for_string, "@{");
-    need_semicolon = true;
-  }
-  "]"  {
-    obstack_sgrow (&obstack_for_string, "@}");
-    need_semicolon = true;
-  }
 
   ";"  STRING_GROW;                 need_semicolon = false;
   "{"  STRING_GROW; ++braces_level; need_semicolon = false;
@@ -279,29 +275,17 @@ ref      -?[0-9]+|{id}|"["{id}"]"|"$"
 }
 
 
-  /*-----------------------------------------.
-  | Escape M4 quoting characters in C code.  |
-  `-----------------------------------------*/
-
 <*>
 {
-  \$   obstack_sgrow (&obstack_for_string, "$][");
-  \@   obstack_sgrow (&obstack_for_string, "@@");
-  \[   obstack_sgrow (&obstack_for_string, "@{");
-  \]   obstack_sgrow (&obstack_for_string, "@}");
-}
+  /* Escape M4 quoting characters in C code.  */
+  [$@\[\]]    obstack_escape (&obstack_for_string, yytext);
 
-  /*-----------------------------------------------------.
-  | By default, grow the string obstack with the input.  |
-  `-----------------------------------------------------*/
+  /* By default, grow the string obstack with the input.  */
+  .|\n        STRING_GROW;
 
-<*>.|\n        STRING_GROW;
-
- /* End of processing. */
-<*><<EOF>>      {
-                   STRING_FINISH;
-                   return last_string;
-                 }
+  /* End of processing. */
+  <<EOF>>     STRING_FINISH; return last_string;
+}
 
 %%