mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-21 10:13:03 +00:00
diagnostics: translate bison's own tokens
As a test case, support translations in Bison itself. * src/parse-gram.y: Mark the translatable tokens. While at it, use clearer names. * tests/input.at: Adjust expectations.
This commit is contained in:
@@ -140,32 +140,27 @@
|
|||||||
boundary_set (&@$.end, grammar_file, 1, 1, 1);
|
boundary_set (&@$.end, grammar_file, 1, 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 PERCENT_TYPE "%type"
|
|
||||||
%token PERCENT_DESTRUCTOR "%destructor"
|
|
||||||
%token PERCENT_PRINTER "%printer"
|
|
||||||
|
|
||||||
%token PERCENT_LEFT "%left"
|
|
||||||
%token PERCENT_RIGHT "%right"
|
|
||||||
%token PERCENT_NONASSOC "%nonassoc"
|
|
||||||
%token PERCENT_PRECEDENCE "%precedence"
|
|
||||||
|
|
||||||
%token PERCENT_PREC "%prec"
|
|
||||||
%token PERCENT_DPREC "%dprec"
|
|
||||||
%token PERCENT_MERGE "%merge"
|
|
||||||
|
|
||||||
/*----------------------.
|
|
||||||
| Global Declarations. |
|
|
||||||
`----------------------*/
|
|
||||||
|
|
||||||
%token
|
%token
|
||||||
|
GRAM_EOF 0 _("end of file")
|
||||||
|
STRING _("string")
|
||||||
|
TSTRING _("translatable string")
|
||||||
|
|
||||||
|
PERCENT_TOKEN "%token"
|
||||||
|
PERCENT_NTERM "%nterm"
|
||||||
|
|
||||||
|
PERCENT_TYPE "%type"
|
||||||
|
PERCENT_DESTRUCTOR "%destructor"
|
||||||
|
PERCENT_PRINTER "%printer"
|
||||||
|
|
||||||
|
PERCENT_LEFT "%left"
|
||||||
|
PERCENT_RIGHT "%right"
|
||||||
|
PERCENT_NONASSOC "%nonassoc"
|
||||||
|
PERCENT_PRECEDENCE "%precedence"
|
||||||
|
|
||||||
|
PERCENT_PREC "%prec"
|
||||||
|
PERCENT_DPREC "%dprec"
|
||||||
|
PERCENT_MERGE "%merge"
|
||||||
|
|
||||||
PERCENT_CODE "%code"
|
PERCENT_CODE "%code"
|
||||||
PERCENT_DEFAULT_PREC "%default-prec"
|
PERCENT_DEFAULT_PREC "%default-prec"
|
||||||
PERCENT_DEFINE "%define"
|
PERCENT_DEFINE "%define"
|
||||||
@@ -191,24 +186,23 @@
|
|||||||
PERCENT_TOKEN_TABLE "%token-table"
|
PERCENT_TOKEN_TABLE "%token-table"
|
||||||
PERCENT_VERBOSE "%verbose"
|
PERCENT_VERBOSE "%verbose"
|
||||||
PERCENT_YACC "%yacc"
|
PERCENT_YACC "%yacc"
|
||||||
;
|
|
||||||
|
|
||||||
%token BRACED_CODE "{...}"
|
BRACED_CODE "{...}"
|
||||||
%token BRACED_PREDICATE "%?{...}"
|
BRACED_PREDICATE "%?{...}"
|
||||||
%token BRACKETED_ID "[identifier]"
|
BRACKETED_ID _("[identifier]")
|
||||||
%token CHAR "character literal"
|
CHAR _("character literal")
|
||||||
%token COLON ":"
|
COLON ":"
|
||||||
%token EPILOGUE "epilogue"
|
EPILOGUE _("epilogue")
|
||||||
%token EQUAL "="
|
EQUAL "="
|
||||||
%token ID "identifier"
|
ID _("identifier")
|
||||||
%token ID_COLON "identifier:"
|
ID_COLON _("identifier:")
|
||||||
%token PERCENT_PERCENT "%%"
|
PERCENT_PERCENT "%%"
|
||||||
%token PIPE "|"
|
PIPE "|"
|
||||||
%token PROLOGUE "%{...%}"
|
PROLOGUE "%{...%}"
|
||||||
%token SEMICOLON ";"
|
SEMICOLON ";"
|
||||||
%token TAG "<tag>"
|
TAG _("<tag>")
|
||||||
%token TAG_ANY "<*>"
|
TAG_ANY "<*>"
|
||||||
%token TAG_NONE "<>"
|
TAG_NONE "<>"
|
||||||
|
|
||||||
/* Experimental feature, don't rely on it. */
|
/* Experimental feature, don't rely on it. */
|
||||||
%code pre-printer {tron (yyo);}
|
%code pre-printer {tron (yyo);}
|
||||||
@@ -231,7 +225,7 @@
|
|||||||
%printer { fprintf (yyo, "%%%s", $$); } PERCENT_FLAG
|
%printer { fprintf (yyo, "%%%s", $$); } PERCENT_FLAG
|
||||||
%printer { fprintf (yyo, "<%s>", $$); } TAG tag
|
%printer { fprintf (yyo, "<%s>", $$); } TAG tag
|
||||||
|
|
||||||
%token <int> INT "integer"
|
%token <int> INT _("integer literal")
|
||||||
%printer { fprintf (yyo, "%d", $$); } <int>
|
%printer { fprintf (yyo, "%d", $$); } <int>
|
||||||
|
|
||||||
%type <symbol*> id id_colon string_as_id symbol token_decl token_decl_for_prec
|
%type <symbol*> id id_colon string_as_id symbol token_decl token_decl_for_prec
|
||||||
|
|||||||
@@ -287,10 +287,10 @@ input.y:5.8-15: error: syntax error, unexpected string, expecting character lite
|
|||||||
input.y:6.8-13: error: syntax error, unexpected string, expecting character literal or identifier or <tag>
|
input.y:6.8-13: error: syntax error, unexpected string, expecting character literal or identifier or <tag>
|
||||||
6 | %token "tok1" 1;
|
6 | %token "tok1" 1;
|
||||||
| ^~~~~~
|
| ^~~~~~
|
||||||
input.y:7.14: error: syntax error, unexpected integer
|
input.y:7.14: error: syntax error, unexpected integer literal
|
||||||
7 | %left "tok2" 2;
|
7 | %left "tok2" 2;
|
||||||
| ^
|
| ^
|
||||||
input.y:8.14: error: syntax error, unexpected integer
|
input.y:8.14: error: syntax error, unexpected integer literal
|
||||||
8 | %type "tok3" 3;
|
8 | %type "tok3" 3;
|
||||||
| ^
|
| ^
|
||||||
]])
|
]])
|
||||||
|
|||||||
Reference in New Issue
Block a user