From 2346344a0890851df35f466909b367cbcaee26a3 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Wed, 7 Jun 2006 07:09:32 +0000 Subject: [PATCH] * src/scan-gram.l: Move the "add a trailing ; to actions" code to... * src/scan-code.l: here. * tests/input.at (Torturing the Scanner): Fix another location error. --- ChangeLog | 8 ++++++++ src/scan-code.l | 27 +++++++++++++++++++++++++++ src/scan-gram.l | 24 +++--------------------- tests/input.at | 2 +- 4 files changed, 39 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index f0f0866b..59345570 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2006-06-07 Akim Demaille + + * src/scan-gram.l: Move the "add a trailing ; to actions" code + to... + * src/scan-code.l: here. + * tests/input.at (Torturing the Scanner): Fix another location + error. + 2006-06-07 Akim Demaille * src/Makefile.am (BUILT_SOURCES): Fix the trailing backslash. diff --git a/src/scan-code.l b/src/scan-code.l index 70b250bc..a24eecec 100644 --- a/src/scan-code.l +++ b/src/scan-code.l @@ -75,6 +75,9 @@ splice (\\[ \f\t\v]*\n)* %% %{ + /* Nesting level of the current code in braces. */ + int braces_level IF_LINT (= 0); + /* This scanner is special: it is invoked only once, henceforth is expected to return only once. This initialization is therefore done once per action to translate. */ @@ -157,6 +160,30 @@ splice (\\[ \f\t\v]*\n)* warn_at (*loc, _("stray `@'")); obstack_sgrow (&obstack_for_string, "@@"); } + + "{" STRING_GROW; ++braces_level; + "}" { + 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, ';'); + + STRING_GROW; + } } diff --git a/src/scan-gram.l b/src/scan-gram.l index 329e5087..dbe40b9c 100644 --- a/src/scan-gram.l +++ b/src/scan-gram.l @@ -46,7 +46,7 @@ #include "scan-gram.h" #define YY_DECL GRAM_LEX_DECL - + #define YY_USER_INIT \ code_start = scanner_cursor = loc->start; \ @@ -543,28 +543,10 @@ splice (\\[ \f\t\v]*\n)* "{"|"<"{splice}"%" STRING_GROW; braces_level++; "%"{splice}">" STRING_GROW; braces_level--; "}" { - 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) + --braces_level; + if (braces_level < 0) { STRING_FINISH; loc->start = code_start; diff --git a/tests/input.at b/tests/input.at index afacd201..973cfee1 100644 --- a/tests/input.at +++ b/tests/input.at @@ -192,7 +192,7 @@ AT_DATA([input.y], [{} ]) AT_CHECK([bison input.y], [1], [], -[[input.y:1.1-2: syntax error, unexpected {...} +[[input.y:1.0-1: syntax error, unexpected {...} ]]) -- 2.47.2