From 5865c0c0c09423969cfa7b3d78254473c35ee701 Mon Sep 17 00:00:00 2001
From: Adela Vais <adela.vais99@gmail.com>
Date: Fri, 18 Dec 2020 19:46:02 +0200
Subject: [PATCH for Dlang support 8/9] d: create alias Value for
 YYSemanticType

* data/skeletons/d.m4: Here.
* data/skeletons/lalr1.d, examples/d/calc/calc.y, examples/d/simple/calc.y: Adjust.
* tests/calc.at, tests/d.at, tests/scanner.at: Test it.
---
 data/skeletons/d.m4      |  7 ++++---
 data/skeletons/lalr1.d   | 14 +++++++-------
 examples/d/calc/calc.y   |  4 ++--
 examples/d/simple/calc.y |  4 ++--
 tests/calc.at            |  4 ++--
 tests/d.at               |  4 ++--
 tests/scanner.at         |  4 ++--
 7 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/data/skeletons/d.m4 b/data/skeletons/d.m4
index 895ff31c..beb7d445 100644
--- a/data/skeletons/d.m4
+++ b/data/skeletons/d.m4
@@ -453,7 +453,8 @@ m4_define([b4_var_decl],
 # Depending on %define token_lex, may be output in the header or source file.
 m4_define([b4_public_types_declare],
 [[
-alias Symbol = ]b4_parser_class[.Symbol;]b4_locations_if([[
+alias Symbol = ]b4_parser_class[.Symbol;
+alias Value = ]b4_yystype[;]b4_locations_if([[
 alias Location = ]b4_location_type[;]])[
 ]])
 
@@ -469,7 +470,7 @@ m4_define([b4_symbol_type_define],
   struct Symbol
   {
     private SymbolKind kind;
-    private ]b4_yystype[ value_;]b4_locations_if([[
+    private Value value_;]b4_locations_if([[
     private Location location_;]])[
     this(TokenKind token]b4_locations_if([[, Location loc]])[)
     {
@@ -486,7 +487,7 @@ m4_define([b4_symbol_type_define],
       }
     }
     SymbolKind token() { return kind; }
-    ]b4_yystype[ value() { return value_; }]b4_locations_if([[
+    Value value() { return value_; }]b4_locations_if([[
     Location location() { return location_; }]])[
   }
 ]])
diff --git a/data/skeletons/lalr1.d b/data/skeletons/lalr1.d
index 65e183fa..23ec07cc 100644
--- a/data/skeletons/lalr1.d
+++ b/data/skeletons/lalr1.d
@@ -68,7 +68,7 @@ public interface Lexer
   /**
    * Method to retrieve the semantic value of the last scanned token.
    * @@return the semantic value of the last scanned token.  */
-  ]b4_yystype[ semanticVal ();
+  Value semanticVal ();
 
   /**
    * Entry point for the scanner.  Returns the token identifier corresponding
@@ -351,7 +351,7 @@ b4_user_union_members
 
   private int yyaction (int yyn, ref YYStack yystack, int yylen)
   {
-    ]b4_yystype[ yyval;]b4_locations_if([[
+    Value yyval;]b4_locations_if([[
     ]b4_location_type[ yyloc = yylloc_from_stack (yystack, yylen);]])[
 
     /* If YYLEN is nonzero, implement the default value of the action:
@@ -393,7 +393,7 @@ b4_user_union_members
   `--------------------------------*/
 
   private final void yy_symbol_print (string s, SymbolKind yykind,
-    ref ]b4_yystype[ yyvaluep]dnl
+    ref Value yyvaluep]dnl
 b4_locations_if([, ref ]b4_location_type[ yylocationp])[)
   {
     if (0 < yydebug)
@@ -442,7 +442,7 @@ b4_locations_if([, ref ]b4_location_type[ yylocationp])[)
     ]b4_location_type[ yyloc;]])[
 
     /// Semantic value of the lookahead.
-    ]b4_yystype[ yylval;
+    Value yylval;
 
     bool yyresult;]b4_lac_if([[
     // Discard the LAC context in case there still is one left from a
@@ -1088,7 +1088,7 @@ m4_popdef([b4_at_dollar])])dnl
 
   private final struct YYStackElement {
     int state;
-    ]b4_yystype[ value;]b4_locations_if(
+    Value value;]b4_locations_if(
     b4_location_type[[] location;])[
   }
 
@@ -1100,7 +1100,7 @@ m4_popdef([b4_at_dollar])])dnl
       return stack.length;
     }
 
-    public final void push (int state, ]b4_yystype[ value]dnl
+    public final void push (int state, Value value]dnl
   b4_locations_if([, ref ]b4_location_type[ loc])[)
     {
       stack ~= YYStackElement(state, value]b4_locations_if([, loc])[);
@@ -1127,7 +1127,7 @@ m4_popdef([b4_at_dollar])])dnl
       return stack[$-i-1].location;
     }]])[
 
-    public final ref ]b4_yystype[ valueAt (int i)
+    public final ref Value valueAt (int i)
     {
       return stack[$-i-1].value;
     }
diff --git a/examples/d/calc/calc.y b/examples/d/calc/calc.y
index 71c448ee..d8f3967c 100644
--- a/examples/d/calc/calc.y
+++ b/examples/d/calc/calc.y
@@ -108,9 +108,9 @@ if (isInputRange!R && is(ElementType!R : dchar))
     stderr.writeln(loc.toString(), ": ", s);
   }
 
-  YYSemanticType semanticVal_;
+  Value semanticVal_;
 
-  public final YYSemanticType semanticVal()
+  public final Value semanticVal()
   {
     return semanticVal_;
   }
diff --git a/examples/d/simple/calc.y b/examples/d/simple/calc.y
index de8da2a4..5fca647e 100644
--- a/examples/d/simple/calc.y
+++ b/examples/d/simple/calc.y
@@ -102,9 +102,9 @@ if (isInputRange!R && is(ElementType!R : dchar))
     stderr.writeln(s);
   }
 
-  YYSemanticType semanticVal_;
+  Value semanticVal_;
 
-  public final YYSemanticType semanticVal()
+  public final Value semanticVal()
   {
     return semanticVal_;
   }
diff --git a/tests/calc.at b/tests/calc.at
index 976cea0a..ebd5768f 100644
--- a/tests/calc.at
+++ b/tests/calc.at
@@ -559,7 +559,7 @@ class CalcLexer(R) : Lexer
 
   ]AT_YYERROR_DEFINE[
 
-  YYSemanticType semanticVal_;]AT_LOCATION_IF([[
+  Value semanticVal_;]AT_LOCATION_IF([[
   Location location;
 
   public final @property YYPosition startPos()
@@ -572,7 +572,7 @@ class CalcLexer(R) : Lexer
     return location.end;
   }
 ]])[
-  public final @property YYSemanticType semanticVal()
+  public final @property Value semanticVal()
   {
     return semanticVal_;
   }
diff --git a/tests/d.at b/tests/d.at
index 3e83a8af..07de11bc 100644
--- a/tests/d.at
+++ b/tests/d.at
@@ -78,8 +78,8 @@ class CalcLexer(R) : Lexer
 
   void yyerror(string s) {}
 
-  YYSemanticType semanticVal_;
-  YYSemanticType semanticVal() @property { return semanticVal_; }
+  Value semanticVal_;
+  Value semanticVal() @property { return semanticVal_; }
 
   Symbol yylex()
   {
diff --git a/tests/scanner.at b/tests/scanner.at
index d0d3f390..e55ad3b6 100644
--- a/tests/scanner.at
+++ b/tests/scanner.at
@@ -115,8 +115,8 @@ class YYLexer(R) : Lexer
 
   ]AT_YYERROR_DEFINE[
 
-  YYSemanticType semanticVal_;
-  public final @property YYSemanticType semanticVal ()
+  Value semanticVal_;
+  public final @property Value semanticVal ()
   {
     return semanticVal_;
   }
-- 
2.17.1

