From 68ac70bc7bf365fa17bd6d7ea597fa0a05488b8d Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Fri, 23 Nov 2012 11:21:47 +0100 Subject: [PATCH] scanner: issue a single error for groups of invalid characters * src/scan-gram.l: Scan groups of invalid characters together. * tests/input.at, tests/named-refs.at: Adjust. --- src/scan-gram.l | 22 ++++++++++++++-------- tests/input.at | 6 +----- tests/named-refs.at | 13 ++++--------- 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/scan-gram.l b/src/scan-gram.l index 8774dc0a..fd6458fa 100644 --- a/src/scan-gram.l +++ b/src/scan-gram.l @@ -103,9 +103,9 @@ static void unexpected_newline (boundary, char const *); /* Bracketed identifiers support. */ %x SC_BRACKETED_ID SC_RETURN_BRACKETED_ID -letter [.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_] +letter [.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_] +notletter [^.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_]{-}[%\{] id {letter}({letter}|[-0-9])* -directive %{id} int [0-9]+ /* POSIX says that a tag must be both an id and a C union member, but @@ -218,7 +218,7 @@ splice (\\[ \f\t\v]*\n)* "%verbose" return PERCENT_VERBOSE; "%yacc" return PERCENT_YACC; - {directive} { + "%"{id}|"%"{notletter}([[:graph:]])+ { complain_at (*loc, _("invalid directive: %s"), quote (yytext)); } @@ -290,8 +290,10 @@ splice (\\[ \f\t\v]*\n)* BEGIN SC_BRACKETED_ID; } - . { - complain_at (*loc, _("invalid character: %s"), quote_mem (yytext, yyleng)); + [^\[%A-Za-z0-9_<>{}\"\'*;|=/, \f\n\t\v]+|. { + complain_at (*loc, "%s: %s", + ngettext ("invalid character", "invalid characters", yyleng), + quote_mem (yytext, yyleng)); } <> { @@ -373,10 +375,14 @@ splice (\\[ \f\t\v]*\n)* else complain_at (*loc, _("an identifier expected")); } - . { - complain_at (*loc, _("invalid character in bracketed name: %s"), - quote_mem (yytext, yyleng)); + + [^\].A-Za-z0-9_/ \f\n\t\v]+|. { + complain_at (*loc, "%s: %s", + ngettext ("invalid character in bracketed name", + "invalid characters in bracketed name", yyleng), + quote_mem (yytext, yyleng)); } + <> { BEGIN bracketed_id_context_state; unexpected_eof (bracketed_id_start, "]"); diff --git a/tests/input.at b/tests/input.at index 35812c80..faa939c1 100644 --- a/tests/input.at +++ b/tests/input.at @@ -39,11 +39,7 @@ default: 'a' } AT_CHECK([[$PERL -pi -e 's/\\(\d{3})/chr(oct($1))/ge' input.y || exit 77]]) AT_BISON_CHECK([input.y], [1], [], -[[input.y:1.1: error: invalid character: '\0' -input.y:1.1: error: invalid character: '\001' -input.y:1.1: error: invalid character: '\002' -input.y:1.1: error: invalid character: '\377' -input.y:1.2: error: invalid character: '?' +[[input.y:1.1-2: error: invalid characters: '\0\001\002\377?' input.y:3.1: error: invalid character: '?' input.y:4.14: error: invalid character: '}' input.y:5.1: error: invalid character: '%' diff --git a/tests/named-refs.at b/tests/named-refs.at index c8809c12..de48e0f7 100644 --- a/tests/named-refs.at +++ b/tests/named-refs.at @@ -443,19 +443,14 @@ AT_SETUP([Stray symbols in brackets]) AT_DATA_GRAMMAR([test.y], [[ %% -start: foo[ /* aaa */ *&-.+\000\001\002\377 ] bar +start: foo[ % /* aaa */ *&-.+\000\001\002\377 ] bar { s = $foo; } ]]) AT_CHECK([[$PERL -pi -e 's/\\(\d{3})/chr(oct($1))/ge' test.y || exit 77]]) AT_BISON_CHECK([-o test.c test.y], 1, [], -[[test.y:11.23: error: invalid character in bracketed name: '*' -test.y:11.24: error: invalid character in bracketed name: '&' -test.y:11.25: error: invalid character in bracketed name: '-' -test.y:11.27: error: invalid character in bracketed name: '+' -test.y:11.28: error: invalid character in bracketed name: '\0' -test.y:11.28: error: invalid character in bracketed name: '\001' -test.y:11.28: error: invalid character in bracketed name: '\002' -test.y:11.28: error: invalid character in bracketed name: '\377' +[[test.y:11.13: error: invalid character in bracketed name: '%' +test.y:11.25-27: error: invalid characters in bracketed name: '*&-' +test.y:11.29-30: error: invalid characters in bracketed name: '+\0\001\002\377' ]]) AT_CLEANUP -- 2.45.2