mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-17 08:13:02 +00:00
factor the handling of m4 escaping
The conversion from @ to @@ and so forth is coded is too many different places. Factor, a bit. * src/scan-code.l: Instead of duplicating the logic of obstack_escape, use it. It sure is less efficient, but the cost is negligible. This allows to factor rules that are alike. And to factor some start-condition clauses. * tests/input.at (Stray $ or @): New. * NEWS: Document it.
This commit is contained in:
6
NEWS
6
NEWS
@@ -22,6 +22,12 @@ GNU Bison NEWS
|
|||||||
|
|
||||||
*** glr.cc: set_debug_level and debug_level work as expected.
|
*** glr.cc: set_debug_level and debug_level work as expected.
|
||||||
|
|
||||||
|
*** Stray @ or $ in actions
|
||||||
|
|
||||||
|
While Bison used to warn about stray $ or @ in action rules, it did not
|
||||||
|
for other actions such as printers, destructors, or initial actions. It
|
||||||
|
now does.
|
||||||
|
|
||||||
** Type names in printers and destructors
|
** Type names in printers and destructors
|
||||||
|
|
||||||
For consistency with rule actions, it is now possible to qualify $$ by a
|
For consistency with rule actions, it is now possible to qualify $$ by a
|
||||||
|
|||||||
@@ -103,7 +103,10 @@ ref -?[0-9]+|{id}|"["{id}"]"|"$"
|
|||||||
';', or a C preprocessor directive, and that whitespaces and
|
';', or a C preprocessor directive, and that whitespaces and
|
||||||
comments do not affect this flag. Note that '{' does not need a
|
comments do not affect this flag. Note that '{' does not need a
|
||||||
semicolon because of '{}'. A semicolon may be needed before a
|
semicolon because of '{}'. A semicolon may be needed before a
|
||||||
cpp directive, but don't bother. */
|
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;
|
bool need_semicolon = false;
|
||||||
|
|
||||||
/* Whether in a C preprocessor directive. Don't use a start condition
|
/* Whether in a C preprocessor directive. Don't use a start condition
|
||||||
@@ -181,6 +184,15 @@ ref -?[0-9]+|{id}|"["{id}"]"|"$"
|
|||||||
STRING_GROW;
|
STRING_GROW;
|
||||||
BEGIN SC_LINE_COMMENT;
|
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>
|
<SC_RULE_ACTION>
|
||||||
@@ -199,24 +211,6 @@ ref -?[0-9]+|{id}|"["{id}"]"|"$"
|
|||||||
obstack_sgrow (&obstack_for_string, ref_tail_fields);
|
obstack_sgrow (&obstack_for_string, ref_tail_fields);
|
||||||
need_semicolon = true;
|
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; need_semicolon = false;
|
||||||
"{" STRING_GROW; ++braces_level; need_semicolon = false;
|
"{" STRING_GROW; ++braces_level; need_semicolon = false;
|
||||||
@@ -281,30 +275,18 @@ ref -?[0-9]+|{id}|"["{id}"]"|"$"
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------.
|
|
||||||
| Escape M4 quoting characters in C code. |
|
|
||||||
`-----------------------------------------*/
|
|
||||||
|
|
||||||
<*>
|
<*>
|
||||||
{
|
{
|
||||||
\$ obstack_sgrow (&obstack_for_string, "$][");
|
/* Escape M4 quoting characters in C code. */
|
||||||
\@ obstack_sgrow (&obstack_for_string, "@@");
|
[$@\[\]] obstack_escape (&obstack_for_string, yytext);
|
||||||
\[ obstack_sgrow (&obstack_for_string, "@{");
|
|
||||||
\] obstack_sgrow (&obstack_for_string, "@}");
|
/* By default, grow the string obstack with the input. */
|
||||||
|
.|\n STRING_GROW;
|
||||||
|
|
||||||
|
/* End of processing. */
|
||||||
|
<<EOF>> STRING_FINISH; return last_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------.
|
|
||||||
| By default, grow the string obstack with the input. |
|
|
||||||
`-----------------------------------------------------*/
|
|
||||||
|
|
||||||
<*>.|\n STRING_GROW;
|
|
||||||
|
|
||||||
/* End of processing. */
|
|
||||||
<*><<EOF>> {
|
|
||||||
STRING_FINISH;
|
|
||||||
return last_string;
|
|
||||||
}
|
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
static inline bool
|
static inline bool
|
||||||
|
|||||||
@@ -1371,6 +1371,36 @@ m4_popdef([AT_TEST])
|
|||||||
AT_CLEANUP
|
AT_CLEANUP
|
||||||
|
|
||||||
|
|
||||||
|
## -------------- ##
|
||||||
|
## Stray $ or @. ##
|
||||||
|
## -------------- ##
|
||||||
|
|
||||||
|
AT_SETUP([[Stray $ or @]])
|
||||||
|
|
||||||
|
AT_DATA_GRAMMAR([[input.y]],
|
||||||
|
[[%token TOK
|
||||||
|
%destructor { $%; @%; } <*>;
|
||||||
|
%initial-action { $%; @%; };
|
||||||
|
%printer { $%; @%; } <*>;
|
||||||
|
%%
|
||||||
|
exp: TOK { $%; @%; };
|
||||||
|
]])
|
||||||
|
|
||||||
|
AT_BISON_CHECK([[input.y]], 0, [],
|
||||||
|
[[input.y:10.19: warning: stray '$'
|
||||||
|
input.y:10.23: warning: stray '@'
|
||||||
|
input.y:11.19: warning: stray '$'
|
||||||
|
input.y:11.23: warning: stray '@'
|
||||||
|
input.y:12.19: warning: stray '$'
|
||||||
|
input.y:12.23: warning: stray '@'
|
||||||
|
input.y:14.19: warning: stray '$'
|
||||||
|
input.y:14.23: warning: stray '@'
|
||||||
|
]])
|
||||||
|
|
||||||
|
AT_CLEANUP
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## ---------------- ##
|
## ---------------- ##
|
||||||
## Code injection. ##
|
## Code injection. ##
|
||||||
## ---------------- ##
|
## ---------------- ##
|
||||||
|
|||||||
Reference in New Issue
Block a user