From fd59f01723a21edfc396c02120c67cbf3f8022ca Mon Sep 17 00:00:00 2001
From: Adela Vais <adela.vais99@gmail.com>
Date: Mon, 21 Dec 2020 15:49:27 +0200
Subject: [PATCH for Dlang support 3/3] d: remove unnecessary methods from the
 Lexer interface

The complete symbol approach in yylex removes the need for the methods
semanticVal, startPos and endPos, which were used when the values were
reported separately.

* data/skeletons/lalr1.d: Here.
* doc/bison.texi: Remove sections about the three methods.
* examples/d/calc/calc.y, examples/d/simple/calc.y: Remove the unused methods.
* tests/calc.at, tests/d.at, tests/scanner.at: Test it.
---
 data/skeletons/lalr1.d   | 18 +-----------------
 doc/bison.texi           | 10 ----------
 examples/d/calc/calc.y   | 15 ---------------
 examples/d/simple/calc.y |  7 -------
 tests/calc.at            | 15 ---------------
 tests/d.at               |  1 -
 tests/scanner.at         |  4 ----
 7 files changed, 1 insertion(+), 69 deletions(-)

diff --git a/data/skeletons/lalr1.d b/data/skeletons/lalr1.d
index 7fe656d3..fd0038d6 100644
--- a/data/skeletons/lalr1.d
+++ b/data/skeletons/lalr1.d
@@ -53,23 +53,7 @@ import std.format;
  * parser <tt>]b4_parser_class[</tt>.
  */
 public interface Lexer
-{]b4_locations_if([[
-  /**
-   * Method to retrieve the beginning position of the last scanned token.
-   * @@return the position at which the last scanned token starts.  */
-  Position startPos ();
-
-  /**
-   * Method to retrieve the ending position of the last scanned token.
-   * @@return the first position beyond the last scanned token.  */
-  Position endPos ();
-
-]])[
-  /**
-   * Method to retrieve the semantic value of the last scanned token.
-   * @@return the semantic value of the last scanned token.  */
-  Value semanticVal ();
-
+{
   /**
    * Entry point for the scanner.  Returns the token identifier corresponding
    * to the next token and prepares to return the semantic value
diff --git a/doc/bison.texi b/doc/bison.texi
index df169517..a272b387 100644
--- a/doc/bison.texi
+++ b/doc/bison.texi
@@ -14016,16 +14016,6 @@ Return the next token. The return value is of type @code{Symbol}, which
 binds together the kind, the semantic value and the location.
 @end deftypemethod
 
-@deftypemethod {Lexer} {Position} getStartPos()
-@deftypemethodx {Lexer} {Position} getEndPos()
-Return respectively the first position of the last token that @code{yylex}
-returned, and the first position beyond it.  These methods are not needed
-unless location tracking is active.
-
-They should return new objects for each call, to avoid that all the symbol
-share the same Position boundaries.
-@end deftypemethod
-
 @deftypemethod {Lexer} {void} reportSyntaxError(@code{YYParser.Context} @var{ctx})
 If you invoke @samp{%define parse.error custom} (@pxref{Bison
 Declarations}), then the parser no longer passes syntax error messages to
diff --git a/examples/d/calc/calc.y b/examples/d/calc/calc.y
index 9599501f..2c79c158 100644
--- a/examples/d/calc/calc.y
+++ b/examples/d/calc/calc.y
@@ -108,11 +108,6 @@ if (isInputRange!R && is(ElementType!R : dchar))
 
   Value semanticVal_;
 
-  public final Value semanticVal()
-  {
-    return semanticVal_;
-  }
-
   Symbol yylex()
   {
     import std.uni : isWhite, isNumber;
@@ -167,16 +162,6 @@ if (isInputRange!R && is(ElementType!R : dchar))
       default: assert(0);
     }
   }
-
-  Position startPos() const
-  {
-    return location.begin;
-  }
-
-  Position endPos() const
-  {
-    return location.end;
-  }
 }
 
 int main()
diff --git a/examples/d/simple/calc.y b/examples/d/simple/calc.y
index 5fca647e..58f1d020 100644
--- a/examples/d/simple/calc.y
+++ b/examples/d/simple/calc.y
@@ -102,13 +102,6 @@ if (isInputRange!R && is(ElementType!R : dchar))
     stderr.writeln(s);
   }
 
-  Value semanticVal_;
-
-  public final Value semanticVal()
-  {
-    return semanticVal_;
-  }
-
   Symbol yylex()
   {
     import std.uni : isWhite, isNumber;
diff --git a/tests/calc.at b/tests/calc.at
index 75b64e10..de85f04d 100644
--- a/tests/calc.at
+++ b/tests/calc.at
@@ -561,22 +561,7 @@ class CalcLexer(R) : Lexer
 
   Value semanticVal_;]AT_LOCATION_IF([[
   Location location;
-
-  public final @property Position startPos()
-  {
-    return location.begin;
-  }
-
-  public final @property Position endPos()
-  {
-    return location.end;
-  }
 ]])[
-  public final @property Value semanticVal()
-  {
-    return semanticVal_;
-  }
-
   int parseInt ()
   {
     auto res = 0;
diff --git a/tests/d.at b/tests/d.at
index 07de11bc..f268b820 100644
--- a/tests/d.at
+++ b/tests/d.at
@@ -79,7 +79,6 @@ class CalcLexer(R) : Lexer
   void yyerror(string s) {}
 
   Value semanticVal_;
-  Value semanticVal() @property { return semanticVal_; }
 
   Symbol yylex()
   {
diff --git a/tests/scanner.at b/tests/scanner.at
index e55ad3b6..46a20116 100644
--- a/tests/scanner.at
+++ b/tests/scanner.at
@@ -116,10 +116,6 @@ class YYLexer(R) : Lexer
   ]AT_YYERROR_DEFINE[
 
   Value semanticVal_;
-  public final @property Value semanticVal ()
-  {
-    return semanticVal_;
-  }
 
   Symbol yylex ()
   {
-- 
2.17.1

