From a66d922e9fd1de570fa78914ad6630125017610a Mon Sep 17 00:00:00 2001
From: Adela Vais <adela.vais99@gmail.com>
Date: Tue, 19 Jan 2021 20:33:05 +0200
Subject: [PATCH for Dlang support 2/2] d: add api.value.type union support

---
 data/skeletons/d.m4    | 14 ++++++++++++--
 data/skeletons/lalr1.d |  5 +++--
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/data/skeletons/d.m4 b/data/skeletons/d.m4
index 0e5b0bda..44b022db 100644
--- a/data/skeletons/d.m4
+++ b/data/skeletons/d.m4
@@ -221,6 +221,16 @@ m4_define([_b4_token_maker_define_types],
 ])])
 
 
+# b4_union_define_types(SYMBOL-NUM)
+# ----------------------------------
+# Declare the union entry for SYMBOL-NUM values.
+m4_define([b4_union_define_types],
+[b4_token_visible_if([$1],
+  [b4_symbol_if([$1], [has_type],
+    [  ][b4_symbol([$1], [type])][ ][b4_symbol([$1], [id])][;], [dnl])
+])])
+
+
 # b4_token_constructor_define
 # ---------------------------
 # Define the overloaded versions of make_symbol for all the value types.
@@ -247,12 +257,12 @@ m4_define([b4_token_constructor_define],
         }
         else
         {]b4_locations_if([[
-          mixin("static auto " ~ member ~ "(typeof(YYSemanticType." ~
+          mixin("static auto " ~ member ~ "(]b4_variant_if([[]], [[typeof(YYSemanticType.]])[" ~
             visibleTokenTypes[mixin("TokenKind." ~ member)] ~ ") v, Location l)
           {
             return Symbol(TokenKind." ~ member ~ ", v, l);
           }");]], [[
-          mixin("static auto " ~ member ~ "(typeof(YYSemanticType." ~
+          mixin("static auto " ~ member ~ "(]b4_variant_if([[]], [[typeof(YYSemanticType.]])[" ~
              visibleTokenTypes[mixin("TokenKind." ~ member)] ~ ") v)
           {
             return Symbol(TokenKind." ~ member ~ ", v);
diff --git a/data/skeletons/lalr1.d b/data/skeletons/lalr1.d
index 62b12d1c..ff80490f 100644
--- a/data/skeletons/lalr1.d
+++ b/data/skeletons/lalr1.d
@@ -207,8 +207,9 @@ public struct ]b4_location_type[
 private immutable bool yy_location_is_class = false;
 
 ]])])m4_ifdef([b4_user_union_members], [private union YYSemanticType
-{
-b4_user_union_members
+{]b4_variant_if([[
+]b4_symbol_foreach([b4_union_define_types])[]],
+[[b4_user_union_members]])[
 };],
 [m4_if(b4_tag_seen_flag, 0,
 [[private alias int YYSemanticType;]])])[
-- 
2.17.1

