bison-patches
[Top][All Lists]
Advanced

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

java: don't expose the Context's members


From: Akim Demaille
Subject: java: don't expose the Context's members
Date: Tue, 11 Feb 2020 19:56:32 +0100

commit 126252333d367d1bb03c9fbfa82b6a14d00d738d
Author: Akim Demaille <address@hidden>
Date:   Tue Feb 11 08:14:03 2020 +0100

   java: don't expose the Context's members

   * data/skeletons/lalr1.java (Context): Make data members private.
   (Context.getLocation): New.
   * examples/java/calc/Calc.y, tests/java.at, tests/local.at: Adjust.

diff --git a/data/skeletons/lalr1.java b/data/skeletons/lalr1.java
index 3b476ff8..1d9bc765 100644
--- a/data/skeletons/lalr1.java
+++ b/data/skeletons/lalr1.java
@@ -339,8 +339,7 @@ import java.text.MessageFormat;
    public int size = 16;
    public int height = -1;

-    public final void push (int state, ]b4_yystype[ value]dnl
-                            b4_locations_if([, ]b4_location_type[ loc])[) {
+    public final void push (int state, ]b4_yystype[ value]b4_locations_if([, 
]b4_location_type[ loc])[) {
      height++;
      if (size == height)
        {
@@ -860,12 +859,20 @@ b4_dollar_popdef[]dnl
  }
]])[

+  /**
+   * Information needed to get the list of expected tokens and to forge
+   * a syntax error diagnostic.
+   */
  public static final class Context
  {
-    public YYStack yystack;
-    public int yytoken;]b4_locations_if([[
-    public ]b4_location_type[ yylocation;]])[
-    public static final int yyntokens = ]b4_parser_class[.yyntokens_;
+    private YYStack yystack;
+    private int yytoken;]b4_locations_if([[
+    public ]b4_location_type[ getLocation ()
+    {
+      return yylocation;
+    }
+    private ]b4_location_type[ yylocation;]])[
+    static final int yyntokens = ]b4_parser_class[.yyntokens_;

    /* Put in YYARG at most YYARGN of the expected tokens given the
       current YYCTX, and return the number of tokens stored in YYARG.  If
diff --git a/examples/java/calc/Calc.y b/examples/java/calc/Calc.y
index b1d21ac7..df86fb76 100644
--- a/examples/java/calc/Calc.y
+++ b/examples/java/calc/Calc.y
@@ -111,7 +111,7 @@ class CalcLexer implements Calc.Lexer {
    final int ARGMAX = 10;
    int[] arg = new int[ARGMAX];
    int n = ctx.yysyntaxErrorArguments (arg, ARGMAX);
-    System.err.print (ctx.yylocation + ": syntax error");
+    System.err.print (ctx.getLocation () + ": syntax error");
    for (int i = 1; i < n; ++i)
      System.err.print ((i == 1 ? ": expected " : " or ")
                        + ctx.yysymbolName (arg[i]));
diff --git a/tests/java.at b/tests/java.at
index 0b33f227..97420ff8 100644
--- a/tests/java.at
+++ b/tests/java.at
@@ -478,8 +478,8 @@ AT_CHECK_JAVA_MINIMAL([[
%define api.position.type {MyPos}
%code { class MyPos {} }]], [[$$ = $<java.awt.Color>1;]], [[MyPos]])
AT_CHECK([[grep 'java.awt.Color' YYParser.java]], [0], [ignore])
-AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep 'Position']], [1], [ignore])
-AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep 'Location']], [1], [ignore])
+AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep -w 'Position']], [1], 
[ignore])
+AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep -w 'Location']], [1], 
[ignore])

AT_CHECK_JAVA_MINIMAL_W_LEXER([[
%define api.value.type {java.awt.Color}
@@ -490,8 +490,8 @@ AT_CHECK_JAVA_MINIMAL_W_LEXER([[
[[$$ = $<java.awt.Color>1;]],
[[java.awt.Color]], [[MyPos]], [[MyLoc]])
AT_CHECK([[grep 'java.awt.Color' YYParser.java]], [0], [ignore])
-AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep 'Position']], [1], [ignore])
-AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep 'Location']], [1], [ignore])
+AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep -w 'Position']], [1], 
[ignore])
+AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep -w 'Location']], [1], 
[ignore])

AT_CLEANUP

diff --git a/tests/local.at b/tests/local.at
index d35bbf68..94c8853b 100644
--- a/tests/local.at
+++ b/tests/local.at
@@ -935,7 +935,7 @@ m4_define([AT_YYERROR_DEFINE(java)],
  {
    int[] arg = new int[ctx.yyntokens];
    int n = ctx.yysyntaxErrorArguments (arg, ctx.yyntokens);
-    System.err.print (]AT_LOCATION_IF([[ctx.yylocation + ": "]]
+    System.err.print (]AT_LOCATION_IF([[ctx.getLocation () + ": "]]
                      + )["syntax error on token @<:@" + ctx.yysymbolName 
(arg[0]) + "@:>@");
    if (1 < n)
      {




reply via email to

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