bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 0/7] Java: add support for parse.error custom|detailed


From: Akim Demaille
Subject: [PATCH 0/7] Java: add support for parse.error custom|detailed
Date: Sun, 9 Feb 2020 14:02:20 +0100

This is my proposal to add support for parse.error custom|detailed to
Java.  I'm no Java programmer, and I have absolutely no idea if this
is the proper way to do it (and push parsers must be checked too).
But at least it's a starting point from which to discuss.

To see it work, have a look at examples/java/calc:

    %define parse.error custom
    ...
    %code {
      static String _ (String s)
      {
        return s;
      }
    }
    %%
    class CalcLexer implements Calc.Lexer {
    ...
      public void yyreportSyntaxError (Calc.Context ctx)
      {
        final int ARGMAX = 10;
        int[] arg = new int[ARGMAX];
        int n = ctx.yysyntaxErrorArguments (arg, ARGMAX);
        System.err.print (ctx.yylocation + ": syntax error");
        for (int i = 1; i < n; ++i)
          System.err.print ((i == 1 ? ": expected " : " or ")
                            + ctx.yysymbolName (arg[i]));
        if (n != 0)
          System.err.print (" before " + ctx.yysymbolName (arg[0]));
        System.err.println ("");
      }
    ...

It is available online here: https://github.com/akimd/bison/pull/27.

Akim Demaille (7):
  m4: fix b4_token_format
  java: add support for parse.error=detailed
  java: introduce yyexpectedTokens
  java: make the syntax error format string translatable
  java: let the Context give access to yyntokens
  java: add support for parse.error custom
  java: provide Context with a more OO interface

 TODO                                      |  13 +
 data/skeletons/bison.m4                   |   6 +-
 data/skeletons/c.m4                       |   7 +
 data/skeletons/java.m4                    |  14 +
 data/skeletons/lalr1.java                 | 300 ++++++++++++++--------
 examples/c/bistromathic/bistromathic.test |   4 +-
 examples/c/bistromathic/parse.y           |   4 +-
 examples/java/calc/Calc.test              |   4 +-
 examples/java/calc/Calc.y                 |  26 +-
 src/output.c                              |  16 +-
 tests/calc.at                             |  20 +-
 tests/local.at                            |  23 ++
 12 files changed, 307 insertions(+), 130 deletions(-)

-- 
2.25.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]