mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-19 17:23:02 +00:00
parsers: support translatable token aliases
In addition to
%token NUM "number"
accept
%token NUM _("number")
in which case the token will be translated in error messages.
Do not use _() in the output if there are no translatable tokens.
* src/symtab.h, src/symtab.c (symbol): Add a 'translatable' member.
* src/parse-gram.y (TSTRING): New token.
(string_as_id.opt): Replace with...
(alias): this.
Use it.
* src/scan-gram.l (SC_ESCAPED_TSTRING): New start conditions, to match
TSTRINGs.
* src/output.c (prepare_symbols): Define b4_translatable if there are
translatable strings.
* data/skeletons/glr.c, data/skeletons/lalr1.cc,
* data/skeletons/yacc.c (yytnamerr): Receive b4_translatable, and use it.
This commit is contained in:
@@ -110,8 +110,8 @@ static void unexpected_newline (boundary, char const *);
|
||||
%}
|
||||
/* A C-like comment in directives/rules. */
|
||||
%x SC_YACC_COMMENT
|
||||
/* Strings and characters in directives/rules. */
|
||||
%x SC_ESCAPED_STRING SC_ESCAPED_CHARACTER
|
||||
/* Characters and strings in directives/rules. */
|
||||
%x SC_ESCAPED_CHARACTER SC_ESCAPED_STRING SC_ESCAPED_TSTRING
|
||||
/* A identifier was just read in directives/rules. Special state
|
||||
to capture the sequence 'identifier :'. */
|
||||
%x SC_AFTER_IDENTIFIER
|
||||
@@ -318,6 +318,7 @@ eqopt ({sp}=)?
|
||||
|
||||
/* Strings. */
|
||||
"\"" token_start = loc->start; BEGIN SC_ESCAPED_STRING;
|
||||
"_(\"" token_start = loc->start; BEGIN SC_ESCAPED_TSTRING;
|
||||
|
||||
/* Prologue. */
|
||||
"%{" code_start = loc->start; BEGIN SC_PROLOGUE;
|
||||
@@ -378,7 +379,7 @@ eqopt ({sp}=)?
|
||||
| added value. |
|
||||
`--------------------------------------------------------------*/
|
||||
|
||||
<SC_ESCAPED_CHARACTER,SC_ESCAPED_STRING,SC_TAG>
|
||||
<SC_ESCAPED_CHARACTER,SC_ESCAPED_STRING,SC_ESCAPED_TSTRING,SC_TAG>
|
||||
{
|
||||
\0 complain (loc, complaint, _("invalid null character"));
|
||||
}
|
||||
@@ -539,6 +540,20 @@ eqopt ({sp}=)?
|
||||
{eol} unexpected_newline (token_start, "\"");
|
||||
}
|
||||
|
||||
<SC_ESCAPED_TSTRING>
|
||||
{
|
||||
"\")" {
|
||||
STRING_FINISH;
|
||||
BEGIN INITIAL;
|
||||
loc->start = token_start;
|
||||
complain (loc, Wyacc,
|
||||
_("POSIX Yacc does not support string literals"));
|
||||
RETURN_VALUE (TSTRING, last_string);
|
||||
}
|
||||
<<EOF>> unexpected_eof (token_start, "\"");
|
||||
"\n" unexpected_newline (token_start, "\"");
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------.
|
||||
| Scanning a Bison character literal, decoding its escapes. |
|
||||
| The initial quote is already eaten. |
|
||||
@@ -601,7 +616,7 @@ eqopt ({sp}=)?
|
||||
| Decode escaped characters. |
|
||||
`----------------------------*/
|
||||
|
||||
<SC_ESCAPED_STRING,SC_ESCAPED_CHARACTER>
|
||||
<SC_ESCAPED_CHARACTER,SC_ESCAPED_STRING,SC_ESCAPED_TSTRING>
|
||||
{
|
||||
\\[0-7]{1,3} {
|
||||
verify (UCHAR_MAX < ULONG_MAX);
|
||||
@@ -797,7 +812,7 @@ eqopt ({sp}=)?
|
||||
| By default, grow the string obstack with the input. |
|
||||
`-----------------------------------------------------*/
|
||||
|
||||
<SC_COMMENT,SC_LINE_COMMENT,SC_BRACED_CODE,SC_PREDICATE,SC_PROLOGUE,SC_EPILOGUE,SC_STRING,SC_CHARACTER,SC_ESCAPED_STRING,SC_ESCAPED_CHARACTER>
|
||||
<SC_COMMENT,SC_LINE_COMMENT,SC_BRACED_CODE,SC_PREDICATE,SC_PROLOGUE,SC_EPILOGUE,SC_STRING,SC_CHARACTER,SC_ESCAPED_CHARACTER,SC_ESCAPED_STRING,SC_ESCAPED_TSTRING>
|
||||
{
|
||||
/* Accept multibyte characters in one block instead of byte after
|
||||
byte, so that add_column_width and mbsnwidth can compute correct
|
||||
|
||||
Reference in New Issue
Block a user