I'd like to push these patches to branch-2.5. In preparation for a future patch, they port some changes from master. I don't believe there are any other changes from master that these depend upon, but I'll wait a little while for comments before pushing just in case.
>From 25e58bde0668c9ec0955e432f16fd8d2bd4bc0da Mon Sep 17 00:00:00 2001 From: Joel E. Denny <[email protected]> Date: Tue, 22 Dec 2009 15:44:29 -0500 Subject: [PATCH] Port small part of master's 8901f32e so future ports are easier. * data/lalr1.cc (yy::parser::yysyntax_error_): Always add second argument, but name it in the function definition only when verbose error messages are enabled and it'll thus be used. (yy::parser::parse): Update use of yysyntax_error_. --- ChangeLog | 8 ++++++++ data/lalr1.cc | 10 ++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index ec11063..69b3e76 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2009-12-22 Joel E. Denny <[email protected]> + + Port small part of master's 8901f32e so future ports are easier. + * data/lalr1.cc (yy::parser::yysyntax_error_): Always add second + argument, but name it in the function definition only when + verbose error messages are enabled and it'll thus be used. + (yy::parser::parse): Update use of yysyntax_error_. + 2009-12-20 Joel E. Denny <[email protected]> Fix handling of yychar manipulation in user semantic actions. diff --git a/data/lalr1.cc b/data/lalr1.cc index c36ba3d..a2d473d 100644 --- a/data/lalr1.cc +++ b/data/lalr1.cc @@ -153,8 +153,7 @@ b4_user_stype /// Generate an error message. /// \param state the state where the error occurred. /// \param tok the lookahead token. - virtual std::string yysyntax_error_ (int yystate]dnl -b4_error_verbose_if([, int tok])[); + virtual std::string yysyntax_error_ (int yystate, int tok); #if YYDEBUG /// \brief Report a symbol value on the debug stream. @@ -726,8 +725,7 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[; if (!yyerrstatus_) { ++yynerrs_; - error (yylloc, yysyntax_error_ (yystate]dnl -b4_error_verbose_if([, yytoken])[)); + error (yylloc, yysyntax_error_ (yystate, yytoken)); } yyerror_range[0] = yylloc; @@ -851,8 +849,8 @@ b4_error_verbose_if([, yytoken])[)); // Generate an error message. std::string - ]b4_parser_class_name[::yysyntax_error_ (int yystate]dnl -b4_error_verbose_if([, int tok])[) + ]b4_parser_class_name[::yysyntax_error_ (int yystate, int]dnl +b4_error_verbose_if([ tok])[) { std::string res; YYUSE (yystate); -- 1.5.4.3 >From 5749444467aca67b06e4150d1dc8ba25b4ca5f33 Mon Sep 17 00:00:00 2001 From: Akim Demaille <[email protected]> Date: Thu, 21 Aug 2008 21:46:13 +0200 Subject: [PATCH] Support i18n of the parse error messages. * TODO (lalr1.cc/I18n): Remove. * data/lalr1.cc (yysyntax_error_): Support the translation of the error messages, as done in yacc.c. Stay within the yy* pseudo namespace. (cherry picked from commit a0ffc1751e712e55b27aa7349ec7db302557476b) Conflicts: TODO data/lalr1.cc --- ChangeLog | 8 +++++ TODO | 3 -- data/lalr1.cc | 80 +++++++++++++++++++++++++++++++++++---------------------- 3 files changed, 57 insertions(+), 34 deletions(-) diff --git a/ChangeLog b/ChangeLog index 69b3e76..90329be 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-11-11 Akim Demaille <[email protected]> + + Support i18n of the parse error messages. + * TODO (lalr1.cc/I18n): Remove. + * data/lalr1.cc (yysyntax_error_): Support the translation of the + error messages, as done in yacc.c. + Stay within the yy* pseudo namespace. + 2009-12-22 Joel E. Denny <[email protected]> Port small part of master's 8901f32e so future ports are easier. diff --git a/TODO b/TODO index 6686ca4..9184513 100644 --- a/TODO +++ b/TODO @@ -22,9 +22,6 @@ parser") refers to the current `output' format. ** vector Move to using vector, drop stack.hh. -** I18n -Catch up with yacc.c. - * Report ** GLR diff --git a/data/lalr1.cc b/data/lalr1.cc index a2d473d..f4cadc0 100644 --- a/data/lalr1.cc +++ b/data/lalr1.cc @@ -850,9 +850,9 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[; // Generate an error message. std::string ]b4_parser_class_name[::yysyntax_error_ (int yystate, int]dnl -b4_error_verbose_if([ tok])[) +b4_error_verbose_if([ yytoken])[) { - std::string res; + std::string yyres; YYUSE (yystate); #if YYERROR_VERBOSE int yyn = yypact_[yystate]; @@ -866,38 +866,56 @@ b4_error_verbose_if([ tok])[) /* Stay within bounds of both yycheck and yytname. */ int yychecklim = yylast_ - yyn + 1; int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_; - int count = 0; - for (int x = yyxbegin; x < yyxend; ++x) - if (yycheck_[x + yyn] == x && x != yyterror_ - && !yy_table_value_is_error_ (yytable_[x + yyn])) - ++count; - - // FIXME: This method of building the message is not compatible - // with internationalization. It should work like yacc.c does it. - // That is, first build a string that looks like this: - // "syntax error, unexpected %s or %s or %s" - // Then, invoke YY_ on this string. - // Finally, use the string as a format to output - // yytname_[tok], etc. - // Until this gets fixed, this message appears in English only. - res = "syntax error, unexpected "; - res += yytnamerr_ (yytname_[tok]); - if (count < 5) - { - count = 0; - for (int x = yyxbegin; x < yyxend; ++x) - if (yycheck_[x + yyn] == x && x != yyterror_ - && !yy_table_value_is_error_ (yytable_[x + yyn])) - { - res += (!count++) ? ", expecting " : " or "; - res += yytnamerr_ (yytname_[x]); - } - } + + // Number of "expected" tokens. + size_t yycount = 0; + // Its maximum. + enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; + // Arguments of yyformat. + char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; + yyarg[yycount++] = yytname_[yytoken]; + for (int yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck_[yyx + yyn] == yyx && yyx != yyterror_ + && !yy_table_value_is_error_ (yytable_[yyx + yyn])) + { + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) + { + yycount = 1; + break; + } + else + yyarg[yycount++] = yytname_[yyx]; + } + + char const* yyformat = 0; + switch (yycount) + { +#define YYCASE_(N, S) \ + case N: \ + yyformat = S; \ + break + YYCASE_(1, YY_("syntax error, unexpected %s")); + YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); + YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); + YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); + YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); +#undef YYCASE_ + } + // Argument number. + size_t yyi = 0; + for (char const* yyp = yyformat; *yyp; ++yyp) + if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount) + { + yyres += yytnamerr_ (yyarg[yyi++]); + ++yyp; + } + else + yyres += *yyp; } else #endif - res = YY_("syntax error"); - return res; + yyres = YY_("syntax error"); + return yyres; } -- 1.5.4.3 >From 15e9d8e1eeca764f377a88deba7238309984f9ce Mon Sep 17 00:00:00 2001 From: Akim Demaille <[email protected]> Date: Thu, 21 Aug 2008 22:04:27 +0200 Subject: [PATCH] Prefer M4 to CPP. * data/lalr1.cc: Use b4_error_verbose_if instead of #if YYERROR_VERBOSE. (cherry picked from commit 422c18f48d3d545c538c61dbb7471cfa7b9e920c) --- ChangeLog | 6 ++++++ data/lalr1.cc | 25 ++++++++++--------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 90329be..48fb89b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2008-11-11 Akim Demaille <[email protected]> + Prefer M4 to CPP. + * data/lalr1.cc: Use b4_error_verbose_if instead of #if + YYERROR_VERBOSE. + +2008-11-11 Akim Demaille <[email protected]> + Support i18n of the parse error messages. * TODO (lalr1.cc/I18n): Remove. * data/lalr1.cc (yysyntax_error_): Support the translation of the diff --git a/data/lalr1.cc b/data/lalr1.cc index f4cadc0..e7620a2 100644 --- a/data/lalr1.cc +++ b/data/lalr1.cc @@ -233,12 +233,10 @@ b4_user_stype #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE /// For a symbol, its name in clear. static const char* const yytname_[]; -#endif +#endif]b4_error_verbose_if([ -#if YYERROR_VERBOSE /// Convert the symbol name \a n to a form suitable for a diagnostic. - virtual std::string yytnamerr_ (const char *n); -#endif + static std::string yytnamerr_ (const char *n);])[ #if YYDEBUG /// A type to store symbol numbers and -1. @@ -384,8 +382,7 @@ do { \ #define YYERROR goto yyerrorlab #define YYRECOVERING() (!!yyerrstatus_) -]b4_namespace_open[ -#if YYERROR_VERBOSE +]b4_namespace_open[]b4_error_verbose_if([[ /* Return YYSTR after stripping away unnecessary quotes and backslashes, so that it's suitable for yyerror. The heuristic is @@ -423,8 +420,7 @@ do { \ return yystr; } - -#endif +]])[ /// Build a parser object. ]b4_parser_class_name::b4_parser_class_name[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [ @@ -849,12 +845,11 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[; // Generate an error message. std::string - ]b4_parser_class_name[::yysyntax_error_ (int yystate, int]dnl -b4_error_verbose_if([ yytoken])[) + ]b4_parser_class_name[::yysyntax_error_ (]dnl +b4_error_verbose_if([int yystate, int yytoken], + [int, int])[) { - std::string yyres; - YYUSE (yystate); -#if YYERROR_VERBOSE + std::string yyres;]b4_error_verbose_if([[ int yyn = yypact_[yystate]; if (yypact_ninf_ < yyn && yyn <= yylast_) { @@ -913,8 +908,8 @@ b4_error_verbose_if([ yytoken])[) yyres += *yyp; } else -#endif - yyres = YY_("syntax error"); + ]])dnl +[ yyres = YY_("syntax error"); return yyres; } -- 1.5.4.3 >From 4b389c048b7adc6d05c731ab33e8ab0c469fd8c6 Mon Sep 17 00:00:00 2001 From: Akim Demaille <[email protected]> Date: Thu, 11 Dec 2008 00:59:13 +0100 Subject: [PATCH] Simplify the i18n of the error messages. * data/lalr1.cc: Comment changes. (cherry picked from commit eeb29422377c730846f784716f22be1759491bcf) Conflicts: data/yacc.c --- ChangeLog | 5 +++++ data/lalr1.cc | 3 ++- 2 files changed, 7 insertions(+), 1 deletions(-) diff --git a/ChangeLog b/ChangeLog index 48fb89b..518ec2a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-12-11 Akim Demaille <[email protected]> + + Simplify the i18n of the error messages. + * data/lalr1.cc: Comment changes. + 2008-11-11 Akim Demaille <[email protected]> Prefer M4 to CPP. diff --git a/data/lalr1.cc b/data/lalr1.cc index e7620a2..a3f7567 100644 --- a/data/lalr1.cc +++ b/data/lalr1.cc @@ -862,7 +862,8 @@ b4_error_verbose_if([int yystate, int yytoken], int yychecklim = yylast_ - yyn + 1; int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_; - // Number of "expected" tokens. + // Number of reported tokens (one for the "unexpected", one per + // "expected"). size_t yycount = 0; // Its maximum. enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; -- 1.5.4.3 >From 415c09b8ec3f8fa3597295ee0381b5558b84c21d Mon Sep 17 00:00:00 2001 From: Joel E. Denny <[email protected]> Date: Tue, 22 Dec 2009 17:22:24 -0500 Subject: [PATCH] Port small part of master's 11707b2b so future ports are easier. * data/lalr1.java (YYParser::yysyntax_error): Untabify. --- ChangeLog | 5 ++++ data/lalr1.java | 64 +++++++++++++++++++++++++++--------------------------- 2 files changed, 37 insertions(+), 32 deletions(-) diff --git a/ChangeLog b/ChangeLog index 518ec2a..fcd0fb2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2009-12-22 Joel E. Denny <[email protected]> + + Port small part of master's 11707b2b so future ports are easier. + * data/lalr1.java (YYParser::yysyntax_error): Untabify. + 2008-12-11 Akim Demaille <[email protected]> Simplify the i18n of the error messages. diff --git a/data/lalr1.java b/data/lalr1.java index 25bb1bd..8fe5953 100644 --- a/data/lalr1.java +++ b/data/lalr1.java @@ -686,38 +686,38 @@ m4_popdef([b4_at_dollar])])dnl int yyn = yypact_[yystate]; if (yypact_ninf_ < yyn && yyn <= yylast_) { - StringBuffer res; - - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. In other words, skip the first -YYN actions for this - state because they are default actions. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = yylast_ - yyn + 1; - int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_; - int count = 0; - for (int x = yyxbegin; x < yyxend; ++x) - if (yycheck_[x + yyn] == x && x != yyterror_ - && !yy_table_value_is_error_ (yytable_[x + yyn])) - ++count; - - // FIXME: This method of building the message is not compatible - // with internationalization. - res = new StringBuffer ("syntax error, unexpected "); - res.append (yytnamerr_ (yytname_[tok])); - if (count < 5) - { - count = 0; - for (int x = yyxbegin; x < yyxend; ++x) - if (yycheck_[x + yyn] == x && x != yyterror_ - && !yy_table_value_is_error_ (yytable_[x + yyn])) - { - res.append (count++ == 0 ? ", expecting " : " or "); - res.append (yytnamerr_ (yytname_[x])); - } - } - return res.toString (); + StringBuffer res; + + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. In other words, skip the first -YYN actions for this + state because they are default actions. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = yylast_ - yyn + 1; + int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_; + int count = 0; + for (int x = yyxbegin; x < yyxend; ++x) + if (yycheck_[x + yyn] == x && x != yyterror_ + && !yy_table_value_is_error_ (yytable_[x + yyn])) + ++count; + + // FIXME: This method of building the message is not compatible + // with internationalization. + res = new StringBuffer ("syntax error, unexpected "); + res.append (yytnamerr_ (yytname_[tok])); + if (count < 5) + { + count = 0; + for (int x = yyxbegin; x < yyxend; ++x) + if (yycheck_[x + yyn] == x && x != yyterror_ + && !yy_table_value_is_error_ (yytable_[x + yyn])) + { + res.append (count++ == 0 ? ", expecting " : " or "); + res.append (yytnamerr_ (yytname_[x])); + } + } + return res.toString (); } } -- 1.5.4.3 >From 157f8c0140e5877c3de90211813eea2e1358880b Mon Sep 17 00:00:00 2001 From: Akim Demaille <[email protected]> Date: Thu, 11 Dec 2008 09:37:40 +0100 Subject: [PATCH] Propagate i18n changes into glr.c. * data/glr.c (yyreportSyntaxError): Use "switch" instead of building the error message format dynamically. * data/lalr1.java: Formatting changes. (cherry picked from commit 2b008529edd233bac07a58d557869ae902be1818) Conflicts: TODO --- ChangeLog | 7 +++++++ data/glr.c | 51 ++++++++++++++++++++++++++++----------------------- data/lalr1.java | 2 +- 3 files changed, 36 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index fcd0fb2..4b428d1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-12-11 Akim Demaille <[email protected]> + + Propagate i18n changes into glr.c. + * data/glr.c (yyreportSyntaxError): Use "switch" instead of + building the error message format dynamically. + * data/lalr1.java: Formatting changes. + 2009-12-22 Joel E. Denny <[email protected]> Port small part of master's 11707b2b so future ports are easier. diff --git a/data/glr.c b/data/glr.c index c7779d2..60c3e40 100644 --- a/data/glr.c +++ b/data/glr.c @@ -2102,18 +2102,10 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[) yybool yysize_overflow = yyfalse; char* yymsg = NULL; enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; + /* Internationalized format string. */ + const char *yyformat = 0; + /* Arguments of yyformat. */ char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; - int yyx; - char *yyfmt; - char const *yyf; - static char const yyunexpected[] = "syntax error, unexpected %s"; - static char const yyexpecting[] = ", expecting %s"; - static char const yyor[] = " or %s"; - char yyformat[sizeof yyunexpected - + sizeof yyexpecting - 1 - + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2) - * (sizeof yyor - 1))]; - char const *yyprefix = yyexpecting; /* Start YYX at -YYN if negative to avoid negative indexes in YYCHECK. In other words, skip the first -YYN actions for this @@ -2123,10 +2115,13 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[) /* Stay within bounds of both yycheck and yytname. */ int yychecklim = YYLAST - yyn + 1; int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; - int yycount = 1; - yyarg[0] = yytokenName (yytoken); - yyfmt = yystpcpy (yyformat, yyunexpected); + /* Number of reported tokens (one for the "unexpected", one per + "expected"). */ + int yycount = 0; + int yyx; + + yyarg[yycount++] = yytokenName (yytoken); for (yyx = yyxbegin; yyx < yyxend; ++yyx) if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR @@ -2136,19 +2131,29 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[) { yycount = 1; yysize = yysize0; - yyformat[sizeof yyunexpected - 1] = '\0'; break; } yyarg[yycount++] = yytokenName (yyx); yysize1 = yysize + yytnamerr (NULL, yytokenName (yyx)); yysize_overflow |= yysize1 < yysize; yysize = yysize1; - yyfmt = yystpcpy (yyfmt, yyprefix); - yyprefix = yyor; } - yyf = YY_(yyformat); - yysize1 = yysize + strlen (yyf); + switch (yycount) + { +#define YYCASE_(N, S) \ + case N: \ + yyformat = S; \ + break + YYCASE_(1, YY_("syntax error, unexpected %s")); + YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); + YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); + YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); + YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); +#undef YYCASE_ + } + + yysize1 = yysize + strlen (yyformat); yysize_overflow |= yysize1 < yysize; yysize = yysize1; @@ -2159,17 +2164,17 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[) { char *yyp = yymsg; int yyi = 0; - while ((*yyp = *yyf)) + while ((*yyp = *yyformat)) { - if (*yyp == '%' && yyf[1] == 's' && yyi < yycount) + if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) { yyp += yytnamerr (yyp, yyarg[yyi++]); - yyf += 2; + yyformat += 2; } else { yyp++; - yyf++; + yyformat++; } } yyerror (]b4_lyyerror_args[yymsg); diff --git a/data/lalr1.java b/data/lalr1.java index 8fe5953..74fe39f 100644 --- a/data/lalr1.java +++ b/data/lalr1.java @@ -717,7 +717,7 @@ m4_popdef([b4_at_dollar])])dnl res.append (yytnamerr_ (yytname_[x])); } } - return res.toString (); + return res.toString (); } } -- 1.5.4.3
