java: lac: check it

* tests/calc.at: Add tests for LAC in pull and push parsers.
Skip LAC: line from the logs.
* tests/local.at (reportSyntaxError): Output the error message in a
single call, to avoid having the error message on stderr be
interrupted by the debug traces of LAC in getExpectedTokens.
This commit is contained in:
Akim Demaille
2020-11-01 17:36:21 +01:00
parent c223baee63
commit 1995d9e2f2
2 changed files with 26 additions and 17 deletions

View File

@@ -1007,24 +1007,25 @@ m4_define([AT_YYERROR_DEFINE(java)],
]AT_ERROR_CUSTOM_IF([[
public void reportSyntaxError(Calc.Context ctx) {
System.err.print(]AT_LOCATION_IF([[ctx.getLocation() + ": "
+ ]])["syntax error");
// Buffer and print the message at the end, to avoid being intertwined
// with debug traces from getExpectedTokens.
String msg = ]AT_LOCATION_IF([[ctx.getLocation() + ": " + ]])["syntax error";
{
Calc.SymbolKind token = ctx.getToken();
if (token != null)
System.err.print(" on token @<:@" + token.getName() + "@:>@");
msg += " on token @<:@" + token.getName() + "@:>@";
}
{
Calc.SymbolKind[] arg = new Calc.SymbolKind[ctx.NTOKENS];
int n = ctx.getExpectedTokens(arg, ctx.NTOKENS);
if (0 < n) {
System.err.print(" (expected:");
msg += " (expected:";
for (int i = 0; i < n; ++i)
System.err.print(" @<:@" + arg[i].getName() + "@:>@");
System.err.print(")");
msg += " @<:@" + arg[i].getName() + "@:>@";
msg += ")";
}
}
System.err.println("");
System.err.println(msg);
}
]])
])