mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
doc: java: SymbolKind, etc.
Why didn't I think about this before??? symbolName should be a method of SymbolKind. * data/skeletons/lalr1.java (YYParser::yysymbolName): Move as... * data/skeletons/java.m4 (SymbolKind::getName): this. Make the table a static final table, not a local variable. Adjust dependencies. * doc/bison.texi (Java Parser Interface): Document i18n. (Java Parser Context Interface): Document SymbolKind. * examples/java/calc/Calc.y, tests/local.at: Adjust.
This commit is contained in:
@@ -174,10 +174,10 @@ m4_define([b4_declare_symbol_enum],
|
||||
{
|
||||
]b4_symbol_foreach([b4_symbol_enum])[
|
||||
|
||||
private final int code_;
|
||||
private final int yycode_;
|
||||
|
||||
SymbolKind (int n) {
|
||||
this.code_ = n;
|
||||
this.yycode_ = n;
|
||||
}
|
||||
|
||||
private static final SymbolKind[] values_ = {
|
||||
@@ -185,13 +185,66 @@ m4_define([b4_declare_symbol_enum],
|
||||
], b4_symbol_numbers)[
|
||||
};
|
||||
|
||||
static final SymbolKind get (int code) {
|
||||
static final SymbolKind get(int code) {
|
||||
return values_[code];
|
||||
}
|
||||
|
||||
public final int getCode () {
|
||||
return this.code_;
|
||||
public final int getCode() {
|
||||
return this.yycode_;
|
||||
}
|
||||
|
||||
]b4_parse_error_bmatch(
|
||||
[simple\|verbose],
|
||||
[[ /* Return YYSTR after stripping away unnecessary quotes and
|
||||
backslashes, so that it's suitable for yyerror. The heuristic is
|
||||
that double-quoting is unnecessary unless the string contains an
|
||||
apostrophe, a comma, or backslash (other than backslash-backslash).
|
||||
YYSTR is taken from yytname. */
|
||||
private static String yytnamerr_(String yystr)
|
||||
{
|
||||
if (yystr.charAt (0) == '"')
|
||||
{
|
||||
StringBuffer yyr = new StringBuffer();
|
||||
strip_quotes: for (int i = 1; i < yystr.length(); i++)
|
||||
switch (yystr.charAt(i))
|
||||
{
|
||||
case '\'':
|
||||
case ',':
|
||||
break strip_quotes;
|
||||
|
||||
case '\\':
|
||||
if (yystr.charAt(++i) != '\\')
|
||||
break strip_quotes;
|
||||
/* Fall through. */
|
||||
default:
|
||||
yyr.append(yystr.charAt(i));
|
||||
break;
|
||||
|
||||
case '"':
|
||||
return yyr.toString();
|
||||
}
|
||||
}
|
||||
return yystr;
|
||||
}
|
||||
|
||||
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
|
||||
First, the terminals, then, starting at \a YYNTOKENS_, nonterminals. */
|
||||
]b4_typed_parser_table_define([String], [tname], [b4_tname])[
|
||||
|
||||
/* The user-facing name of this symbol. */
|
||||
public final String getName() {
|
||||
return yytnamerr_(yytname_[yycode_]);
|
||||
}
|
||||
]],
|
||||
[custom\|detailed],
|
||||
[[ /* YYNAMES_[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
|
||||
First, the terminals, then, starting at \a YYNTOKENS_, nonterminals. */
|
||||
]b4_typed_parser_table_define([String], [names], [b4_symbol_names])[
|
||||
|
||||
/* The user-facing name of this symbol. */
|
||||
public final String getName() {
|
||||
return yynames_[yycode_];
|
||||
}]])[
|
||||
};
|
||||
]])])
|
||||
|
||||
|
||||
@@ -507,7 +507,7 @@ import java.text.MessageFormat;
|
||||
b4_locations_if([, Object yylocationp])[)
|
||||
{
|
||||
yycdebug (s + (yykind.getCode () < YYNTOKENS_ ? " token " : " nterm ")
|
||||
+ yysymbolName (yykind) + " ("]b4_locations_if([
|
||||
+ yykind.getName() + " ("]b4_locations_if([
|
||||
+ yylocationp + ": "])[
|
||||
+ (yyvaluep == null ? "(null)" : yyvaluep.toString ()) + ")");
|
||||
}]])[
|
||||
@@ -880,7 +880,7 @@ b4_dollar_popdef[]dnl
|
||||
/**
|
||||
* The symbol kind of the lookahead token.
|
||||
*/
|
||||
public SymbolKind getToken ()
|
||||
public final SymbolKind getToken ()
|
||||
{
|
||||
return yytoken;
|
||||
}
|
||||
@@ -890,7 +890,7 @@ b4_dollar_popdef[]dnl
|
||||
/**
|
||||
* The location of the lookahead.
|
||||
*/
|
||||
public ]b4_location_type[ getLocation ()
|
||||
public final ]b4_location_type[ getLocation ()
|
||||
{
|
||||
return yylocation;
|
||||
}
|
||||
@@ -937,15 +937,6 @@ b4_dollar_popdef[]dnl
|
||||
}
|
||||
return yycount - yyoffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* The user-facing name of the symbol whose (internal) number is
|
||||
* YYSYMBOL. No bounds checking.
|
||||
*/
|
||||
static String yysymbolName (SymbolKind yysymbol)
|
||||
{
|
||||
return ]b4_parser_class[.yysymbolName (yysymbol);
|
||||
}
|
||||
}
|
||||
|
||||
]b4_parse_error_bmatch(
|
||||
@@ -1005,7 +996,7 @@ b4_dollar_popdef[]dnl
|
||||
int yycount = yysyntaxErrorArguments (yyctx, yyarg, argmax);
|
||||
String[] yystr = new String[yycount];
|
||||
for (int yyi = 0; yyi < yycount; ++yyi)
|
||||
yystr[yyi] = yysymbolName (yyarg[yyi]);
|
||||
yystr[yyi] = yyarg[yyi].getName();
|
||||
String yyformat;
|
||||
switch (yycount)
|
||||
{
|
||||
@@ -1049,63 +1040,6 @@ b4_dollar_popdef[]dnl
|
||||
|
||||
]b4_parser_tables_define[
|
||||
|
||||
]b4_parse_error_bmatch(
|
||||
[simple\|verbose],
|
||||
[[ /* Return YYSTR after stripping away unnecessary quotes and
|
||||
backslashes, so that it's suitable for yyerror. The heuristic is
|
||||
that double-quoting is unnecessary unless the string contains an
|
||||
apostrophe, a comma, or backslash (other than backslash-backslash).
|
||||
YYSTR is taken from yytname. */
|
||||
private static String yytnamerr_ (String yystr)
|
||||
{
|
||||
if (yystr.charAt (0) == '"')
|
||||
{
|
||||
StringBuffer yyr = new StringBuffer ();
|
||||
strip_quotes: for (int i = 1; i < yystr.length (); i++)
|
||||
switch (yystr.charAt (i))
|
||||
{
|
||||
case '\'':
|
||||
case ',':
|
||||
break strip_quotes;
|
||||
|
||||
case '\\':
|
||||
if (yystr.charAt(++i) != '\\')
|
||||
break strip_quotes;
|
||||
/* Fall through. */
|
||||
default:
|
||||
yyr.append (yystr.charAt (i));
|
||||
break;
|
||||
|
||||
case '"':
|
||||
return yyr.toString ();
|
||||
}
|
||||
}
|
||||
return yystr;
|
||||
}
|
||||
|
||||
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
|
||||
First, the terminals, then, starting at \a YYNTOKENS_, nonterminals. */
|
||||
]b4_typed_parser_table_define([String], [tname], [b4_tname])[
|
||||
|
||||
/* The user-facing name of the symbol whose (internal) number is
|
||||
YYSYMBOL. No bounds checking. */
|
||||
static String yysymbolName (SymbolKind yysymbol)
|
||||
{
|
||||
return yytnamerr_ (yytname_[yysymbol.getCode ()]);
|
||||
}
|
||||
]],
|
||||
[custom\|detailed],
|
||||
[[ /* The user-facing name of the symbol whose (internal) number is
|
||||
YYSYMBOL. No bounds checking. */
|
||||
static String yysymbolName (SymbolKind yysymbol)
|
||||
{
|
||||
String[] yy_sname =
|
||||
{
|
||||
]b4_symbol_names[
|
||||
};
|
||||
return yy_sname[yysymbol.getCode ()];
|
||||
}]])[
|
||||
|
||||
]b4_parse_trace_if([[
|
||||
]b4_integral_parser_table_define([rline], [b4_rline],
|
||||
[[YYRLINE[YYN] -- Source line where rule number YYN was defined.]])[
|
||||
|
||||
Reference in New Issue
Block a user