bison-patches
[Top][All Lists]
Advanced

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

[PATCH 2/4] java: clean up the definition of token kinds


From: Akim Demaille
Subject: [PATCH 2/4] java: clean up the definition of token kinds
Date: Tue, 28 Apr 2020 08:49:20 +0200

From

    public interface Lexer {
      /* Token kinds.  */
      /** Token number, to be returned by the scanner.  */
      static final int YYEOF = 0;
      /** Token number, to be returned by the scanner.  */
      static final int YYERRCODE = 256;
      /** Token number, to be returned by the scanner.  */
      static final int YYUNDEF = 257;
      /** Token number, to be returned by the scanner.  */
      static final int BANG = 258;
    ...
      /** Deprecated, use b4_symbol(0, id) instead.  */
      public static final int EOF = YYEOF;

to

    public interface Lexer {
      /* Token kinds.  */
      /** Token "end of file", to be returned by the scanner.  */
      static final int YYEOF = 0;
      /** Token error, to be returned by the scanner.  */
      static final int YYerror = 256;
      /** Token "invalid token", to be returned by the scanner.  */
      static final int YYUNDEF = 257;
      /** Token "!", to be returned by the scanner.  */
      static final int BANG = 258;
    ...
      /** Deprecated, use YYEOF instead.  */
      public static final int EOF = YYEOF;

* data/skeletons/java.m4 (b4_token_enum): Display the symbol's tag in
comment.
* data/skeletons/lalr1.java: Address overquotation issue.
* examples/java/calc/Calc.y, examples/java/simple/Calc.y: Use YYEOF,
not EOF.
---
 TODO                        |  4 ++++
 data/skeletons/java.m4      | 11 ++++++++---
 data/skeletons/lalr1.java   |  2 +-
 examples/java/calc/Calc.y   |  2 +-
 examples/java/simple/Calc.y |  2 +-
 tests/calc.at               |  2 +-
 6 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/TODO b/TODO
index 5407311e..7556b20a 100644
--- a/TODO
+++ b/TODO
@@ -84,6 +84,10 @@ Also do it in data/skeletons.
 Don't rename in Bison 3.6 (it would be logical to do so) because that
 would probably create many conflicts in Vincent's work (see previous point).
 
+** A dev warning for b4_
+Maybe we should check for m4_ and b4_ leaking out of the m4 processing, as
+Autoconf does.  It would have caught overquotation issues.
+
 * Bison 3.8
 ** Unit rules / Injection rules (Akim Demaille)
 Maybe we could expand unit rules (or "injections", see
diff --git a/data/skeletons/java.m4 b/data/skeletons/java.m4
index afc5419e..0b09579c 100644
--- a/data/skeletons/java.m4
+++ b/data/skeletons/java.m4
@@ -137,9 +137,14 @@ m4_define([b4_integral_parser_table_define],
 # ------------------------
 # Output the definition of this token as an enum.
 m4_define([b4_token_enum],
-[b4_token_format([    /** Token number, to be returned by the scanner.  */
-    static final int %s = %s;
-], [$1])])
+[b4_token_visible_if([$1],
+    [m4_format([[    /** Token %s, to be returned by the scanner.  */
+    static final int %s = %s%s;
+]],
+               b4_symbol([$1], [tag]),
+               b4_symbol([$1], [id]),
+               b4_symbol([$1], b4_api_token_raw_if([[number]], 
[[user_number]])))])])
+
 
 # b4_token_enums
 # --------------
diff --git a/data/skeletons/lalr1.java b/data/skeletons/lalr1.java
index 844461e0..e2d4bcad 100644
--- a/data/skeletons/lalr1.java
+++ b/data/skeletons/lalr1.java
@@ -180,7 +180,7 @@ import java.text.MessageFormat;
    */
   public interface Lexer {
 ]b4_token_enums[
-    /** Deprecated, use b4_symbol(0, id) instead.  */
+    /** Deprecated, use ]b4_symbol(0, id)[ instead.  */
     public static final int EOF = ]b4_symbol(0, id)[;
 
 ]b4_locations_if([[
diff --git a/examples/java/calc/Calc.y b/examples/java/calc/Calc.y
index 8070e0c1..d0b507f3 100644
--- a/examples/java/calc/Calc.y
+++ b/examples/java/calc/Calc.y
@@ -150,7 +150,7 @@ class CalcLexer implements Calc.Lexer {
     end.set(reader.getPosition());
     switch (ttype) {
     case StreamTokenizer.TT_EOF:
-      return EOF;
+      return YYEOF;
     case StreamTokenizer.TT_EOL:
       end.line += 1;
       end.column = 0;
diff --git a/examples/java/simple/Calc.y b/examples/java/simple/Calc.y
index 59df5758..7f6dacd7 100644
--- a/examples/java/simple/Calc.y
+++ b/examples/java/simple/Calc.y
@@ -93,7 +93,7 @@ class CalcLexer implements Calc.Lexer {
     int ttype = st.nextToken();
     switch (ttype) {
     case StreamTokenizer.TT_EOF:
-      return EOF;
+      return YYEOF;
     case StreamTokenizer.TT_EOL:
       return (int) '\n';
     case StreamTokenizer.TT_WORD:
diff --git a/tests/calc.at b/tests/calc.at
index 4a9eaa73..34fa9bab 100644
--- a/tests/calc.at
+++ b/tests/calc.at
@@ -392,7 +392,7 @@ m4_define([AT_CALC_YYLEX(java)],
     switch (tkind)
       {
       case StreamTokenizer.TT_EOF:
-        return EOF;
+        return CALC_EOF;
       case StreamTokenizer.TT_EOL:;]AT_LOCATION_IF([[
         end.line += 1;
         end.column = 0;]])[
-- 
2.26.2




reply via email to

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