* 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.
This commit is contained in:
Akim Demaille
2006-06-07 07:09:32 +00:00
parent 4862bdfd61
commit 2346344a08
4 changed files with 39 additions and 22 deletions

View File

@@ -1,3 +1,11 @@
2006-06-07 Akim Demaille <akim@epita.fr>
* 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 <akim@epita.fr>
* src/Makefile.am (BUILT_SOURCES): Fix the trailing backslash.

View File

@@ -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;
}
}
<SC_SYMBOL_ACTION>

View File

@@ -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;

View File

@@ -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 {...}
]])