[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
i18n for yacc backend messages
From: |
Jan Nieuwenhuizen |
Subject: |
i18n for yacc backend messages |
Date: |
Wed, 13 Apr 2005 20:57:55 +0200 |
User-agent: |
Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 (gnu/linux) |
Hi,
LilyPond is now fully localised, apart from some of the strings that
bison produces. The patch below (against CVS) is the first step to
fix that. Note that the construction of the syntax error message has
been written out, as per i18n guidelines.
Should we replace the macro yy_(x) with the standard (but user
namespace polluting) macro _(x)?
Usage:
xgettext --keyword=_ --keyword=yy_ --keyword=yyerror parser.tab.c
At the top of parser.y, do something like
#if !HAVE_GETTEXT
char *
gettext (char const *s)
{
return (char *)s;
}
#else
#include <libintl.h>
#endif
#define yy_(x) gettext (x)
Greetings,
Jan.
Index: ChangeLog
===================================================================
RCS file: /cvsroot/bison/bison/ChangeLog,v
retrieving revision 1.1219
diff -p -u -r1.1219 ChangeLog
--- ChangeLog 12 Apr 2005 22:38:43 -0000 1.1219
+++ ChangeLog 13 Apr 2005 18:56:09 -0000
@@ -1,3 +1,9 @@
+2005-04-13 Jan Nieuwenhuizen <address@hidden>
+
+ * data/c.m4 (b4_i18n_list): New macro.
+
+ * data/yacc.c: Use it. Enable i18n for syntax error.
+
2005-04-12 Paul Eggert <address@hidden>
* src/symtab.c (symbol_make_alias): Call symbol_type_set,
Index: data/c.m4
===================================================================
RCS file: /cvsroot/bison/bison/data/c.m4,v
retrieving revision 1.26
diff -p -u -r1.26 c.m4
--- data/c.m4 24 Sep 2004 14:14:58 -0000 1.26
+++ data/c.m4 13 Apr 2005 18:56:09 -0000
@@ -419,3 +419,13 @@ b4_location_if([ (void) yylocationp;
YYFPRINTF (yyoutput, ")");
}
]])
+
+# b4_i18n_list([STRING1], ...)
+# ------------------------------
+# Output the arguments _ (STRING1), _ (STRING2)...
+m4_define([b4_i18n_list],
+[m4_map([b4_i18n_map], $@)
+])
+
+m4_define([b4_i18n_map],
+[m4_map_sep([[_ ]], [, ], address@hidden)])
Index: data/yacc.c
===================================================================
RCS file: /cvsroot/bison/bison/data/yacc.c,v
retrieving revision 1.83
diff -p -u -r1.83 yacc.c
--- data/yacc.c 17 Mar 2005 19:19:44 -0000 1.83
+++ data/yacc.c 13 Apr 2005 18:56:09 -0000
@@ -373,6 +373,16 @@ static const char *const yytname[] =
{
]b4_tname[
};
+
+#if 0
+/* xgettext helper. Mark all strings to get picked-up by xgettext for
+ translation. Use C mockup as not to confuse toolboxes. */
+static char const *yytname_gettext_helper[] =
+{
+ ]b4_i18n_list([b4_tname])[
+};
+#endif
+
#endif
# ifdef YYPRINT
@@ -480,21 +490,21 @@ static const ]b4_int_type_for([b4_stos])
#define YYRECOVERING() (!!yyerrstatus)
-#define YYBACKUP(Token, Value) \
-do \
- if (yychar == YYEMPTY && yylen == 1) \
- { \
- yychar = (Token); \
- yylval = (Value); \
- yytoken = YYTRANSLATE (yychar); \
- YYPOPSTACK; \
- goto yybackup; \
- } \
- else \
- { \
- yyerror (]b4_yyerror_args["syntax error: cannot back up");\
- YYERROR; \
- } \
+#define YYBACKUP(Token, Value) \
+do \
+ if (yychar == YYEMPTY && yylen == 1) \
+ { \
+ yychar = (Token);
\
+ yylval = (Value);
\
+ yytoken = YYTRANSLATE (yychar); \
+ YYPOPSTACK; \
+ goto yybackup; \
+ } \
+ else \
+ { \
+ yyerror (]b4_yyerror_args[yy_ ("syntax error: cannot back up")); \
+ YYERROR; \
+ } \
while (0)
@@ -1078,7 +1088,6 @@ yyerrlab:
{
YYSIZE_T yysize = 0;
int yytype = YYTRANSLATE (yychar);
- const char* yyprefix;
char *yymsg;
int yyx;
@@ -1090,47 +1099,90 @@ yyerrlab:
int yychecklim = YYLAST - yyn;
int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
int yycount = 0;
+ char const *yytnamei[5];
- yyprefix = ", expecting ";
for (yyx = yyxbegin; yyx < yyxend; ++yyx)
if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
{
- yysize += yystrlen (yyprefix) + yystrlen (yytname [yyx]);
+ yytnamei[yycount] = yytname[yyx];
+ yysize += yystrlen (yy_ (yytnamei[yycount]));
yycount += 1;
if (yycount == 5)
{
+ yycount = 0;
yysize = 0;
break;
}
}
- yysize += (sizeof ("syntax error, unexpected ")
- + yystrlen (yytname[yytype]));
- yymsg = (char *) YYSTACK_ALLOC (yysize);
+ yysize += yystrlen (yy_ (yytname[yytype]));
+ switch (yycount)
+ {
+ case 0:
+#ifndef yy_
+#define yy_(x) x
+#endif
+#define SYNTAX_ERROR_UNEXPECTED0 yy_ ("syntax error, unexpected %s")
+#define SYNTAX_ERROR_UNEXPECTED1 yy_ ("syntax error, unexpected %s, expecting
%s")
+#define SYNTAX_ERROR_UNEXPECTED2 yy_ ("syntax error, unexpected %s, expecting
%s or %s")
+#define SYNTAX_ERROR_UNEXPECTED3 yy_ ("syntax error, unexpected %s, expecting
%s or %s or %s")
+#define SYNTAX_ERROR_UNEXPECTED4 yy_ ("syntax error, unexpected %s, expecting
%s or %s or %s or %s")
+ yysize += strlen (SYNTAX_ERROR_UNEXPECTED0);
+ yymsg = (char *) YYSTACK_ALLOC (yysize);
+ if (yymsg != 0)
+ sprintf (yymsg, SYNTAX_ERROR_UNEXPECTED0,
+ yy_ (yytname[yytype]));
+ break;
+ case 1:
+ yysize += strlen (SYNTAX_ERROR_UNEXPECTED1);
+ yymsg = (char *) YYSTACK_ALLOC (yysize);
+ if (yymsg != 0)
+ sprintf (yymsg, SYNTAX_ERROR_UNEXPECTED1,
+ yy_ (yytname[yytype]),
+ yy_ (yytnamei[0]));
+ break;
+ case 2:
+ yysize += strlen (SYNTAX_ERROR_UNEXPECTED2);
+ yymsg = (char *) YYSTACK_ALLOC (yysize);
+ if (yymsg != 0)
+ sprintf (yymsg, SYNTAX_ERROR_UNEXPECTED2,
+ yy_ (yytname[yytype]),
+ yy_ (yytname[0]),
+ yy_ (yytname[1]));
+ break;
+ case 3:
+ yysize += strlen (SYNTAX_ERROR_UNEXPECTED3);
+ yymsg = (char *) YYSTACK_ALLOC (yysize);
+ if (yymsg != 0)
+ sprintf (yymsg, SYNTAX_ERROR_UNEXPECTED3,
+ yy_ (yytname[yytype]),
+ yy_ (yytnamei[0]),
+ yy_ (yytnamei[1]),
+ yy_ (yytnamei[2]));
+ break;
+ case 4:
+ yysize += strlen (SYNTAX_ERROR_UNEXPECTED4);
+ yymsg = (char *) YYSTACK_ALLOC (yysize);
+ if (yymsg != 0)
+ sprintf (yymsg, SYNTAX_ERROR_UNEXPECTED4,
+ yy_ (yytname[yytype]),
+ yy_ (yytnamei[0]),
+ yy_ (yytnamei[1]),
+ yy_ (yytnamei[2]),
+ yy_ (yytnamei[3]));
+ break;
+ }
+
if (yymsg != 0)
{
- char *yyp = yystpcpy (yymsg, "syntax error, unexpected ");
- yyp = yystpcpy (yyp, yytname[yytype]);
-
- if (yycount < 5)
- {
- yyprefix = ", expecting ";
- for (yyx = yyxbegin; yyx < yyxend; ++yyx)
- if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
- {
- yyp = yystpcpy (yyp, yyprefix);
- yyp = yystpcpy (yyp, yytname[yyx]);
- yyprefix = " or ";
- }
- }
yyerror (]b4_yyerror_args[yymsg);
YYSTACK_FREE (yymsg);
}
else
- yyerror (]b4_yyerror_args["syntax error; also virtual memory
exhausted");
+ yyerror (]b4_yyerror_args[yy_ ("syntax error; also virtual memory
exhausted"));
}
else
#endif /* YYERROR_VERBOSE */
- yyerror (]b4_yyerror_args["syntax error");
+ yyerror (]b4_yyerror_args[yy_ ("syntax error"));
}
]b4_location_if([[ yyerror_range[0] = yylloc;]])[
@@ -1257,7 +1309,7 @@ yyabortlab:
| yyoverflowlab -- parser overflow comes here. |
`----------------------------------------------*/
yyoverflowlab:
- yyerror (]b4_yyerror_args["parser stack overflow");
+ yyerror (]b4_yyerror_args[yy_ ("parser stack overflow"));
yyresult = 2;
/* Fall through. */
#endif
--
Jan Nieuwenhuizen <address@hidden> | GNU LilyPond - The music typesetter
http://www.xs4all.nl/~jantien | http://www.lilypond.org
- i18n for yacc backend messages,
Jan Nieuwenhuizen <=
- Re: i18n for yacc backend messages, Paul Eggert, 2005/04/13
- Re: i18n for yacc backend messages, Jan Nieuwenhuizen, 2005/04/13
- Re: i18n for yacc backend messages, Paul Eggert, 2005/04/13
- Re: i18n for yacc backend messages, Jan Nieuwenhuizen, 2005/04/14
- Re: i18n for yacc backend messages, Paul Eggert, 2005/04/14
- Re: i18n for yacc backend messages, Jan Nieuwenhuizen, 2005/04/14
- Re: i18n for yacc backend messages, Paul Eggert, 2005/04/16
- Re: i18n for yacc backend messages, Jan Nieuwenhuizen, 2005/04/16
- Re: i18n for yacc backend messages, Hans Aberg, 2005/04/16
- Re: i18n for yacc backend messages, Akim Demaille, 2005/04/18