mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-17 00:03:03 +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:
24
src/output.c
24
src/output.c
@@ -50,6 +50,10 @@ static struct obstack format_obstack;
|
||||
| result of formatting the FIRST and then TABLE_DATA[BEGIN..END[ (of |
|
||||
| TYPE), and to the muscle NAME_max, the max value of the |
|
||||
| TABLE_DATA. |
|
||||
| |
|
||||
| For the typical case of outputting a complete table from 0, pass |
|
||||
| TABLE[0] as FIRST, and 1 as BEGIN. For instance |
|
||||
| muscle_insert_base_table ("pact", base, base[0], 1, nstates); |
|
||||
`-------------------------------------------------------------------*/
|
||||
|
||||
|
||||
@@ -248,6 +252,26 @@ prepare_symbols (void)
|
||||
prepare_symbol_names ("tname");
|
||||
prepare_symbol_names ("symbol_names");
|
||||
|
||||
/* translatable -- whether a token is translatable. */
|
||||
{
|
||||
bool translatable = false;
|
||||
for (int i = 0; i < ntokens; ++i)
|
||||
if (symbols[i]->translatable)
|
||||
{
|
||||
translatable = true;
|
||||
break;
|
||||
}
|
||||
if (translatable)
|
||||
{
|
||||
int *values = xnmalloc (nsyms, sizeof *values);
|
||||
for (int i = 0; i < ntokens; ++i)
|
||||
values[i] = symbols[i]->translatable;
|
||||
muscle_insert_int_table ("translatable", values,
|
||||
values[0], 1, ntokens);
|
||||
free (values);
|
||||
}
|
||||
}
|
||||
|
||||
/* Output YYTOKNUM. */
|
||||
{
|
||||
int *values = xnmalloc (ntokens, sizeof *values);
|
||||
|
||||
Reference in New Issue
Block a user