diff options
author | Akim Demaille <akim.demaille@gmail.com> | 2020-02-08 14:19:03 +0100 |
---|---|---|
committer | Akim Demaille <akim.demaille@gmail.com> | 2020-02-08 16:03:50 +0100 |
commit | ef097719eaf5ca80c18c101f21d57741f8178be9 (patch) | |
tree | 46fcf499033b8fbae1456d94c4716aee5ca661a1 /tests | |
parent | 0c90c597950759573ec08fd6669425bd41083e5e (diff) | |
download | bison-ef097719eaf5ca80c18c101f21d57741f8178be9.tar.gz |
java: add support for parse.error custom
* data/skeletons/lalr1.java: Add support for custom parse errors.
(yyntokens_): Make it public. Under...
(yyntokens): this name.
(Context): Capture the location too.
* examples/c/bistromathic/parse.y,
* examples/c/bistromathic/bistromathic.test:
Improve error message.
* examples/java/calc/Calc.test, examples/java/calc/Calc.y: Use custom
error messages.
* tests/calc.at, tests/local.at: Check custom error messages.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/calc.at | 3 | ||||
-rw-r--r-- | tests/local.at | 23 |
2 files changed, 26 insertions, 0 deletions
diff --git a/tests/calc.at b/tests/calc.at index 25a1c806..1754b6f8 100644 --- a/tests/calc.at +++ b/tests/calc.at @@ -1185,8 +1185,11 @@ m4_define([AT_CHECK_CALC_LALR1_JAVA], [AT_CHECK_CALC([%language "Java" $1], [$2])]) AT_CHECK_CALC_LALR1_JAVA +AT_CHECK_CALC_LALR1_JAVA([%define parse.error custom]) AT_CHECK_CALC_LALR1_JAVA([%define parse.error detailed]) AT_CHECK_CALC_LALR1_JAVA([%define parse.error verbose]) +AT_CHECK_CALC_LALR1_JAVA([%locations %define parse.error custom]) +AT_CHECK_CALC_LALR1_JAVA([%locations %define parse.error detailed]) AT_CHECK_CALC_LALR1_JAVA([%locations %define parse.error verbose]) AT_CHECK_CALC_LALR1_JAVA([%define parse.trace %define parse.error verbose]) AT_CHECK_CALC_LALR1_JAVA([%define parse.trace %define parse.error verbose %locations %lex-param {InputStream is}]) diff --git a/tests/local.at b/tests/local.at index 9b6c203f..097197d5 100644 --- a/tests/local.at +++ b/tests/local.at @@ -908,6 +908,9 @@ class PositionReader extends BufferedReader { }]]) +# AT_YYERROR_DEFINE(java) +# ----------------------- +# FIXME: We should not hard-code "Calc". m4_define([AT_YYERROR_DEFINE(java)], [AT_LOCATION_IF([[public void yyerror (Calc.Location l, String m) {]m4_bmatch(m4_defn([AT_PARSE_PARAMS]), [nerrs],[[ @@ -925,6 +928,24 @@ m4_define([AT_YYERROR_DEFINE(java)], ++*nerrs;]])[ System.err.println (m); } +]])[ + +]AT_ERROR_CUSTOM_IF([[ + public void yyreportSyntaxError (Calc.Context ctx) + { + int[] arg = new int[ctx.yyntokens]; + int n = Calc.yysyntaxErrorArguments (ctx, arg, ctx.yyntokens); + System.err.print (]AT_LOCATION_IF([[ctx.yylocation + ": "]] + + )["syntax error on token @<:@" + Calc.yysymbolName(arg[0]) + "@:>@"); + if (1 < n) + { + System.err.print (" (expected:"); + for (int i = 1; i < n; ++i) + System.err.print (" @<:@" + Calc.yysymbolName (arg[i]) + "@:>@"); + System.err.print (")"); + } + System.err.println (""); + } ]]) ]) @@ -962,6 +983,8 @@ m4_define([AT_MAIN_DEFINE(java)], m4_define([AT_LANG_FOR_EACH_STD(java)], [$1]) + + ## --------------- ## ## Running Bison. ## ## --------------- ## |