From 255227393f15ba5b593070f19d99fabbc96499b8 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 30 Dec 2002 22:40:52 +0000 Subject: [PATCH] ("}"): Append ";" before the last brace in braced code when not in Yacc mode, for compatibility with Bison 1.35. This resurrects the 2001-12-15 patch to src/reader.c. --- src/scan-gram.l | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/scan-gram.l b/src/scan-gram.l index da041a4f..502fabaa 100644 --- a/src/scan-gram.l +++ b/src/scan-gram.l @@ -542,9 +542,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 && ! yacc_flag) + obstack_1grow (&obstack_for_string, ';'); + + obstack_1grow (&obstack_for_string, '}'); + + if (outer_brace) { STRING_FINISH; rule_length++; -- 2.47.2