[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 13/13] parsers: issue tname with i18n markup
From: |
Akim Demaille |
Subject: |
[PATCH 13/13] parsers: issue tname with i18n markup |
Date: |
Sat, 18 Jan 2020 16:40:12 +0100 |
Some users would like to avoid having to "parse" the *.y file to find
the strings to translate. Let's issue the translatable tokens with N_
to allow "parsing" the generated parsers instead.
See
https://lists.gnu.org/archive/html/bison-patches/2019-01/msg00015.html
* src/output.c (prepare_symbol_names): Issue symbol_names with N_()
markup.
---
src/output.c | 8 +++++++-
tests/calc.at | 1 +
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/src/output.c b/src/output.c
index 6f1e9f45..0b1c546c 100644
--- a/src/output.c
+++ b/src/output.c
@@ -206,7 +206,9 @@ prepare_symbol_names (char const *muscle_name)
: quotearg_alloc (symbols[i]->tag, -1, qo);
/* Width of the next token, including the two quotes, the
comma and the space. */
- int width = strlen (cp) + 2;
+ int width
+ = strlen (cp) + 2
+ + (!quote && symbols[i]->translatable ? strlen ("N_()") : 0);
if (j + width > 75)
{
@@ -216,7 +218,11 @@ prepare_symbol_names (char const *muscle_name)
if (i)
obstack_1grow (&format_obstack, ' ');
+ if (!quote && symbols[i]->translatable)
+ obstack_sgrow (&format_obstack, "N_(");
obstack_escape (&format_obstack, cp);
+ if (!quote && symbols[i]->translatable)
+ obstack_1grow (&format_obstack, ')');
free (cp);
obstack_1grow (&format_obstack, ',');
j += width;
diff --git a/tests/calc.at b/tests/calc.at
index 7ed7f891..81b783c4 100644
--- a/tests/calc.at
+++ b/tests/calc.at
@@ -422,6 +422,7 @@ void location_print (FILE *o, Span s);
]AT_YYLEX_DECLARE_EXTERN[
]AT_TOKEN_TRANSLATE_IF([[
+#define N_
static
const char *
_ (const char *cp)
--
2.24.1
- [PATCH 03/13] yacc.c: add support for parse.error detailed, (continued)
- [PATCH 03/13] yacc.c: add support for parse.error detailed, Akim Demaille, 2020/01/18
- [PATCH 04/13] yacc.c: tests: check detailed error messages, Akim Demaille, 2020/01/18
- [PATCH 05/13] regen, Akim Demaille, 2020/01/18
- [PATCH 06/13] bison: use detailed error messages, Akim Demaille, 2020/01/18
- [PATCH 07/13] regen, Akim Demaille, 2020/01/18
- [PATCH 09/13] tests: check that detailed error messages preserve UTF-8 characters, Akim Demaille, 2020/01/18
- [PATCH 08/13] yacc.c: escape trigraphs in detailed parse.error, Akim Demaille, 2020/01/18
- [PATCH 10/13] parsers: support translatable token aliases, Akim Demaille, 2020/01/18
- [PATCH 12/13] tests: check token internationalization, Akim Demaille, 2020/01/18
- [PATCH 13/13] parsers: issue tname with i18n markup,
Akim Demaille <=
- [PATCH 11/13] regen, Akim Demaille, 2020/01/18
- Re: [PATCH 00/13] Better error messages, Akim Demaille, 2020/01/20