[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: i18n for yacc backend messages
From: |
Jan Nieuwenhuizen |
Subject: |
Re: i18n for yacc backend messages |
Date: |
Thu, 14 Apr 2005 13:56:11 +0200 |
User-agent: |
Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 (gnu/linux) |
Paul Eggert writes:
> OK, but why can't you use the token name '\drums' instead of 'DRUMS'? E.g.,
> something like this:
>
> %token DRUMS "\\drums"
I'll look into this. Still, we have tokens like 'new_lyrics',
'directionless_char', and sequences like STRING, string,
simple_string.
We don't want to export the internal layout to the user (new_lyrics),
directionless_char should be translated, and STRING, string, simple
string should all be translated, probably to the same meaning to be
helpful for a user.
> I guess I was thinking about the option of having the tokens
> translated for both scanning and printing; but it sounds like Lilypond
> doesn't do that so my thoughts were headed in the wrong direction.
No, it's only for error reporting, as far as my wishes go.
> I'm afraid that the message is cryptic even in English.
> The CVS version now is translatable to some extent,
> so at least we're better off than before.
Yes, it is. So how about the patch below. Having a single string
makes it easier to massage the english message too?
Thanks,
Jan.
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 14 Apr 2005 11:46:40 -0000
@@ -309,6 +309,15 @@ m4_define([b4_c_args],
m4_define([b4_c_arg],
[$2])
+# b4_gettext_list([STRING1], ...)
+# -------------------------------
+# Output the arguments _(STRING1), _(STRING2)...
+m4_define([b4_gettext_list],
+[m4_map([b4_gettext_map], $@)])
+
+m4_define([b4_gettext_map],
+[m4_map_sep([[_]], [, ], address@hidden)])
+
## ----------- ##
## Synclines. ##
Index: data/yacc.c
===================================================================
RCS file: /cvsroot/bison/bison/data/yacc.c,v
retrieving revision 1.84
diff -p -u -r1.84 yacc.c
--- data/yacc.c 14 Apr 2005 00:08:56 -0000 1.84
+++ data/yacc.c 14 Apr 2005 11:46:40 -0000
@@ -373,6 +373,22 @@ static const char *const yytname[] =
{
]b4_tname[
};
+
+#define YYEXPECTINGMAX 5
+static char const* SYNTAX_ERROR_UNEXPECTED[] =
+{
+ _ ("syntax error, unexpected %s"),
+ _ ("syntax error, unexpected %s, expecting %s"),
+ _ ("syntax error, unexpected %s, expecting %s or %s"),
+};
+static char const* SYNTAX_ERROR_OR = _ (" or %s");
+
+# if 0
+static char const *yytname_gettext_helper[] =
+{
+ ]b4_gettext_list([b4_tname])[
+};
+# endif
#endif
/* INFRINGES ON USER NAME SPACE */
@@ -1083,7 +1099,6 @@ yyerrlab:
{
YYSIZE_T yysize = 0;
int yytype = YYTRANSLATE (yychar);
- const char* yyprefix;
char *yymsg;
int yyx;
@@ -1095,38 +1110,60 @@ yyerrlab:
int yychecklim = YYLAST - yyn;
int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
int yycount = 0;
+ int yymcount
+ = sizeof (SYNTAX_ERROR_UNEXPECTED) / sizeof (char const*) - 1;
+ char const **yytnamei = (char const**) YYSTACK_ALLOC (YYEXPECTINGMAX);
- yyprefix = _(", expecting ");
- for (yyx = yyxbegin; yyx < yyxend; ++yyx)
- if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
- {
- yysize += yystrlen (yyprefix) + yystrlen (yytname [yyx]);
- yycount += 1;
- if (yycount == 5)
+ if (yytnamei != 0)
+ {
+ for (yyx = yyxbegin; yyx < yyxend; ++yyx)
+ if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
{
- yysize = 0;
- break;
+ yytnamei[yycount] = _ (yytname[yyx]);
+ yysize += yystrlen (yytnamei[yycount]);
+ yycount += 1;
+ if (yycount == YYEXPECTINGMAX)
+ {
+ yycount = 0;
+ yysize = 0;
+ break;
+ }
}
- }
- yysize += (strlen (_("syntax error, unexpected "))
- + yystrlen (yytname[yytype]) + 1);
- yymsg = (char *) YYSTACK_ALLOC (yysize);
- if (yymsg != 0)
- {
- char *yyp = yystpcpy (yymsg, _("syntax error, unexpected "));
- yyp = yystpcpy (yyp, yytname[yytype]);
- if (yycount < 5)
+ yysize += yystrlen (_ (yytname[yytype]));
+ if (yycount < yymcount)
+ yymcount = yycount;
+ yysize += strlen (_ (SYNTAX_ERROR_UNEXPECTED[yymcount]));
+ if (yycount > yymcount)
+ yysize += strlen (_ (SYNTAX_ERROR_OR)) * (yycount - yymcount);
+ yymsg = (char *) YYSTACK_ALLOC (yysize);
+ if (yymsg != 0)
{
- 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 ");
- }
+ switch (yymcount)
+ {
+ case 0:
+ sprintf (yymsg, _ (SYNTAX_ERROR_UNEXPECTED[0]),
+ _ (yytname[yytype]));
+ break;
+ case 1:
+ sprintf (yymsg, _ (SYNTAX_ERROR_UNEXPECTED[1]),
+ _ (yytname[yytype]), _ (yytnamei[0]));
+ break;
+ default:
+ sprintf (yymsg, _ (SYNTAX_ERROR_UNEXPECTED[2]),
+ _ (yytname[yytype]), _ (yytnamei[0]),
+ _ (yytnamei[1]));
+ for (yyx = yymcount; yyx < yycount; yyx++)
+ sprintf (yymsg + strlen (yymsg), _ (SYNTAX_ERROR_OR),
+ _ (yytnamei[yyx]));
+ break;
+ }
}
+ YYSTACK_FREE (yytnamei);
+ }
+
+ if (yymsg != 0)
+ {
yyerror (]b4_yyerror_args[yymsg);
YYSTACK_FREE (yymsg);
}
--
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, 2005/04/13
- 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 <=
- 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
- Re: i18n for yacc backend messages, Hans Aberg, 2005/04/18
- Re: i18n for yacc backend messages, Akim Demaille, 2005/04/18
- Re: i18n for yacc backend messages, Hans Aberg, 2005/04/18
- Re: i18n for yacc backend messages, Jan Nieuwenhuizen, 2005/04/14
- Message not available
- Message not available
- Re: i18n for yacc backend messages, Paul Eggert, 2005/04/16
- Re: i18n for yacc backend messages, Jan Nieuwenhuizen, 2005/04/16