[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 7/8] translate bison's own tokens
From: |
Akim Demaille |
Subject: |
[PATCH 7/8] translate bison's own tokens |
Date: |
Sat, 29 Dec 2018 17:30:26 +0100 |
As a test case, support translations in Bison itself.
* #: .
* #: .
---
src/parse-gram.y | 70 ++++++++++++++++++++++--------------------------
tests/input.at | 8 +++---
2 files changed, 36 insertions(+), 42 deletions(-)
diff --git a/src/parse-gram.y b/src/parse-gram.y
index f99cb052..24975d67 100644
--- a/src/parse-gram.y
+++ b/src/parse-gram.y
@@ -117,32 +117,27 @@
boundary_set (&@$.end, current_file, 1, 1);
}
-/* Define the tokens together with their human representation. */
-%token GRAM_EOF 0 "end of file"
-%token STRING "string"
- TSTRING "translatable string"
-
-%token PERCENT_TOKEN "%token"
-%token PERCENT_NTERM "%nterm"
+%token
+ GRAM_EOF 0 _("end of file")
+ STRING _("string")
+ TSTRING _("translatable string")
-%token PERCENT_TYPE "%type"
-%token PERCENT_DESTRUCTOR "%destructor"
-%token PERCENT_PRINTER "%printer"
+ PERCENT_TOKEN "%token"
+ PERCENT_NTERM "%nterm"
-%token PERCENT_LEFT "%left"
-%token PERCENT_RIGHT "%right"
-%token PERCENT_NONASSOC "%nonassoc"
-%token PERCENT_PRECEDENCE "%precedence"
+ PERCENT_TYPE "%type"
+ PERCENT_DESTRUCTOR "%destructor"
+ PERCENT_PRINTER "%printer"
-%token PERCENT_PREC "%prec"
-%token PERCENT_DPREC "%dprec"
-%token PERCENT_MERGE "%merge"
+ PERCENT_LEFT "%left"
+ PERCENT_RIGHT "%right"
+ PERCENT_NONASSOC "%nonassoc"
+ PERCENT_PRECEDENCE "%precedence"
-/*----------------------.
-| Global Declarations. |
-`----------------------*/
+ PERCENT_PREC "%prec"
+ PERCENT_DPREC "%dprec"
+ PERCENT_MERGE "%merge"
-%token
PERCENT_CODE "%code"
PERCENT_DEFAULT_PREC "%default-prec"
PERCENT_DEFINE "%define"
@@ -166,23 +161,22 @@
PERCENT_TOKEN_TABLE "%token-table"
PERCENT_VERBOSE "%verbose"
PERCENT_YACC "%yacc"
-;
-%token BRACED_CODE "{...}"
-%token BRACED_PREDICATE "%?{...}"
-%token BRACKETED_ID "[identifier]"
-%token CHAR "char"
-%token EPILOGUE "epilogue"
-%token EQUAL "="
-%token ID "identifier"
-%token ID_COLON "identifier:"
-%token PERCENT_PERCENT "%%"
-%token PIPE "|"
-%token PROLOGUE "%{...%}"
-%token SEMICOLON ";"
-%token TAG "<tag>"
-%token TAG_ANY "<*>"
-%token TAG_NONE "<>"
+ BRACED_CODE "{...}"
+ BRACED_PREDICATE "%?{...}"
+ BRACKETED_ID _("[identifier]")
+ CHAR _("character literal")
+ EPILOGUE _("epilogue")
+ EQUAL "="
+ ID _("identifier")
+ ID_COLON _("identifier:")
+ PERCENT_PERCENT "%%"
+ PIPE "|"
+ PROLOGUE "%{...%}"
+ SEMICOLON ";"
+ TAG _("<tag>")
+ TAG_ANY "<*>"
+ TAG_NONE "<>"
%type <unsigned char> CHAR
%printer { fputs (char_name ($$), yyo); } <unsigned char>
@@ -198,7 +192,7 @@
%printer { fprintf (yyo, "%%%s", $$); } PERCENT_FLAG
%printer { fprintf (yyo, "<%s>", $$); } TAG tag
-%token <int> INT "integer"
+%token <int> INT _("integer literal")
%printer { fprintf (yyo, "%d", $$); } <int>
%type <symbol*> id id_colon string_as_id symbol token_decl token_decl_for_prec
diff --git a/tests/input.at b/tests/input.at
index d8e9ee33..6e837e97 100644
--- a/tests/input.at
+++ b/tests/input.at
@@ -232,16 +232,16 @@ input.y:3.17-24: error: nonterminals cannot be given a
string alias
input.y:4.8-10: error: character literals cannot be nonterminals
%nterm '+' '*';
^^^
-input.y:5.8-15: error: syntax error, unexpected string, expecting char or
identifier or <tag>
+input.y:5.8-15: error: syntax error, unexpected string, expecting character
literal or identifier or <tag>
%nterm "number";
^^^^^^^^
-input.y:6.8-13: error: syntax error, unexpected string, expecting char or
identifier or <tag>
+input.y:6.8-13: error: syntax error, unexpected string, expecting character
literal or identifier or <tag>
%token "tok1" 1;
^^^^^^
-input.y:7.14: error: syntax error, unexpected integer
+input.y:7.14: error: syntax error, unexpected integer literal
%left "tok2" 2;
^
-input.y:8.14: error: syntax error, unexpected integer
+input.y:8.14: error: syntax error, unexpected integer literal
%type "tok3" 3;
^
]])
--
2.20.0
- [PATCH 0/8] Revamp the handling token string aliases in error messages, Akim Demaille, 2018/12/29
- [PATCH 6/8] tests: check that internationalization of token works, Akim Demaille, 2018/12/29
- [PATCH 7/8] translate bison's own tokens,
Akim Demaille <=
- [PATCH 4/8] parsers: don't double escape tnames, Akim Demaille, 2018/12/29
- [PATCH 2/8] parsers: revamp the interface of yytnamerr, Akim Demaille, 2018/12/29
- [PATCH 1/8] yacc.c: avoid negated if, Akim Demaille, 2018/12/29
- [PATCH 3/8] tests: no longer play with trigraphs, Akim Demaille, 2018/12/29
- [PATCH 5/8] parsers: support translatable token aliases, Akim Demaille, 2018/12/29
- [PATCH 8/8] regen, Akim Demaille, 2018/12/29