mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-17 16:23:04 +00:00
java: make yysyntaxErrorArguments a private detail
* data/skeletons/lalr1.java (yysyntaxErrorArguments): Move it from the context, to the parser object. Generate only for detailed and verbose error messages. * tests/local.at (AT_YYERROR_DEFINE(java)): Use yyexpectedTokens instead.
This commit is contained in:
@@ -933,46 +933,49 @@ b4_dollar_popdef[]dnl
|
|||||||
{
|
{
|
||||||
return ]b4_parser_class[.yysymbolName (yysymbol);
|
return ]b4_parser_class[.yysymbolName (yysymbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
int yysyntaxErrorArguments (int[] yyarg, int yyargn)
|
|
||||||
{
|
|
||||||
/* There are many possibilities here to consider:
|
|
||||||
- If this state is a consistent state with a default action,
|
|
||||||
then the only way this function was invoked is if the
|
|
||||||
default action is an error action. In that case, don't
|
|
||||||
check for expected tokens because there are none.
|
|
||||||
- The only way there can be no lookahead present (in tok) is
|
|
||||||
if this state is a consistent state with a default action.
|
|
||||||
Thus, detecting the absence of a lookahead is sufficient to
|
|
||||||
determine that there is no unexpected or expected token to
|
|
||||||
report. In that case, just report a simple "syntax error".
|
|
||||||
- Don't assume there isn't a lookahead just because this
|
|
||||||
state is a consistent state with a default action. There
|
|
||||||
might have been a previous inconsistent state, consistent
|
|
||||||
state with a non-default action, or user semantic action
|
|
||||||
that manipulated yychar. (However, yychar is currently out
|
|
||||||
of scope during semantic actions.)
|
|
||||||
- Of course, the expected token list depends on states to
|
|
||||||
have correct lookahead information, and it depends on the
|
|
||||||
parser not to perform extra reductions after fetching a
|
|
||||||
lookahead from the scanner and before detecting a syntax
|
|
||||||
error. Thus, state merging (from LALR or IELR) and default
|
|
||||||
reductions corrupt the expected token list. However, the
|
|
||||||
list is correct for canonical LR with one exception: it
|
|
||||||
will still contain any token that will not be accepted due
|
|
||||||
to an error action in a later state.
|
|
||||||
*/
|
|
||||||
int yycount = 0;
|
|
||||||
if (this.yytoken != yyempty_)
|
|
||||||
{
|
|
||||||
yyarg[yycount++] = this.yytoken;
|
|
||||||
yycount += this.yyexpectedTokens (yyarg, 1, yyargn);
|
|
||||||
}
|
|
||||||
return yycount;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
]b4_parse_error_bmatch(
|
||||||
|
[detailed\|verbose], [[
|
||||||
|
private int yysyntaxErrorArguments (Context yyctx, int[] yyarg, int yyargn)
|
||||||
|
{
|
||||||
|
/* There are many possibilities here to consider:
|
||||||
|
- If this state is a consistent state with a default action,
|
||||||
|
then the only way this function was invoked is if the
|
||||||
|
default action is an error action. In that case, don't
|
||||||
|
check for expected tokens because there are none.
|
||||||
|
- The only way there can be no lookahead present (in tok) is
|
||||||
|
if this state is a consistent state with a default action.
|
||||||
|
Thus, detecting the absence of a lookahead is sufficient to
|
||||||
|
determine that there is no unexpected or expected token to
|
||||||
|
report. In that case, just report a simple "syntax error".
|
||||||
|
- Don't assume there isn't a lookahead just because this
|
||||||
|
state is a consistent state with a default action. There
|
||||||
|
might have been a previous inconsistent state, consistent
|
||||||
|
state with a non-default action, or user semantic action
|
||||||
|
that manipulated yychar. (However, yychar is currently out
|
||||||
|
of scope during semantic actions.)
|
||||||
|
- Of course, the expected token list depends on states to
|
||||||
|
have correct lookahead information, and it depends on the
|
||||||
|
parser not to perform extra reductions after fetching a
|
||||||
|
lookahead from the scanner and before detecting a syntax
|
||||||
|
error. Thus, state merging (from LALR or IELR) and default
|
||||||
|
reductions corrupt the expected token list. However, the
|
||||||
|
list is correct for canonical LR with one exception: it
|
||||||
|
will still contain any token that will not be accepted due
|
||||||
|
to an error action in a later state.
|
||||||
|
*/
|
||||||
|
int yycount = 0;
|
||||||
|
if (yyctx.getToken () != yyempty_)
|
||||||
|
{
|
||||||
|
yyarg[yycount++] = yyctx.getToken ();
|
||||||
|
yycount += yyctx.yyexpectedTokens (yyarg, 1, yyargn);
|
||||||
|
}
|
||||||
|
return yycount;
|
||||||
|
}
|
||||||
|
]])[
|
||||||
|
|
||||||
|
/**
|
||||||
* Report a syntax error.
|
* Report a syntax error.
|
||||||
*/
|
*/
|
||||||
private void yyreportSyntaxError (Context yyctx)
|
private void yyreportSyntaxError (Context yyctx)
|
||||||
@@ -984,7 +987,7 @@ b4_dollar_popdef[]dnl
|
|||||||
{
|
{
|
||||||
final int argmax = 5;
|
final int argmax = 5;
|
||||||
int[] yyarg = new int[argmax];
|
int[] yyarg = new int[argmax];
|
||||||
int yycount = yyctx.yysyntaxErrorArguments (yyarg, argmax);
|
int yycount = yysyntaxErrorArguments (yyctx, yyarg, argmax);
|
||||||
String[] yystr = new String[yycount];
|
String[] yystr = new String[yycount];
|
||||||
for (int yyi = 0; yyi < yycount; ++yyi)
|
for (int yyi = 0; yyi < yycount; ++yyi)
|
||||||
yystr[yyi] = yysymbolName (yyarg[yyi]);
|
yystr[yyi] = yysymbolName (yyarg[yyi]);
|
||||||
|
|||||||
@@ -972,17 +972,24 @@ m4_define([AT_YYERROR_DEFINE(java)],
|
|||||||
]AT_ERROR_CUSTOM_IF([[
|
]AT_ERROR_CUSTOM_IF([[
|
||||||
public void yyreportSyntaxError (Calc.Context ctx)
|
public void yyreportSyntaxError (Calc.Context ctx)
|
||||||
{
|
{
|
||||||
int[] arg = new int[ctx.NTOKENS];
|
|
||||||
int n = ctx.yysyntaxErrorArguments (arg, ctx.NTOKENS);
|
|
||||||
System.err.print (]AT_LOCATION_IF([[ctx.getLocation () + ": "]]
|
System.err.print (]AT_LOCATION_IF([[ctx.getLocation () + ": "]]
|
||||||
+ )["syntax error on token @<:@" + ctx.yysymbolName (arg[0]) + "@:>@");
|
+ )["syntax error");
|
||||||
if (1 < n)
|
{
|
||||||
{
|
int token = ctx.getToken ();
|
||||||
System.err.print (" (expected:");
|
if (token != ctx.EMPTY)
|
||||||
for (int i = 1; i < n; ++i)
|
System.err.print (" on token @<:@" + ctx.yysymbolName (token) + "@:>@");
|
||||||
System.err.print (" @<:@" + ctx.yysymbolName (arg[i]) + "@:>@");
|
}
|
||||||
System.err.print (")");
|
{
|
||||||
}
|
int[] arg = new int[ctx.NTOKENS];
|
||||||
|
int n = ctx.yyexpectedTokens (arg, ctx.NTOKENS);
|
||||||
|
if (0 < n)
|
||||||
|
{
|
||||||
|
System.err.print (" (expected:");
|
||||||
|
for (int i = 0; i < n; ++i)
|
||||||
|
System.err.print (" @<:@" + ctx.yysymbolName (arg[i]) + "@:>@");
|
||||||
|
System.err.print (")");
|
||||||
|
}
|
||||||
|
}
|
||||||
System.err.println ("");
|
System.err.println ("");
|
||||||
}
|
}
|
||||||
]])
|
]])
|
||||||
|
|||||||
Reference in New Issue
Block a user