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:
Akim Demaille
2018-12-28 08:47:04 +01:00
parent e9d404415a
commit 9096955fba
6 changed files with 79 additions and 18 deletions

View File

@@ -109,6 +109,7 @@ symbol_new (uniqstr tag, location loc)
res->tag = tag;
res->location = loc;
res->translatable = false;
res->location_of_lhs = false;
res->alias = NULL;
res->content = sym_content_new (res);
@@ -954,7 +955,7 @@ dummy_symbol_get (location loc)
}
bool
symbol_is_dummy (const symbol *sym)
symbol_is_dummy (symbol const *sym)
{
return sym->tag[0] == '@' || (sym->tag[0] == '$' && sym->tag[1] == '@');
}