Hello Akim,

Here are the patches for the syntax error that appeared when using `%code
lexer` (issue 84) and the toString method of SymbolKind (issue 88).
I used the latest DMD public release, 2.100.2.

I used the proposed solutions created by ledaniel2. I'll let you handle the
author attribution for these patches.

I want to follow up with a test for the second patch, most probably next
week. I think that one possible test that could use the function can be
created through
https://github.com/adelavais/bison/blob/master/tests/regression.at#L1724 in
combination with functions from the local.at file, so I will look into this.

Thank you,
Adela
From fa6180c6f55764985130e6d7dd5122f151897476 Mon Sep 17 00:00:00 2001
From: Adela Vais <[email protected]>
Date: Mon, 19 Sep 2022 19:09:20 +0200
Subject: [PATCH 2/2] d: fix syntax error on SymbolKind.toString method

Reported by ledaniel2. Proposed solution by ledaniel2.
<akimd#88>

* data/skeletons/d.m4: Here.
---
 data/skeletons/d.m4 | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/data/skeletons/d.m4 b/data/skeletons/d.m4
index 9354b0fe..e82f87e5 100644
--- a/data/skeletons/d.m4
+++ b/data/skeletons/d.m4
@@ -284,8 +284,7 @@ m4_define([b4_declare_symbol_enum],
      that double-quoting is unnecessary unless the string contains an
      apostrophe, a comma, or backslash (other than backslash-backslash).
      YYSTR is taken from yytname.  */
-    final void toString(W)(W sink) const
-    if (isOutputRange!(W, char))
+    final void toString(void delegate(const(char)[]) sink) const
     {
       immutable string[] yy_sname = @{
   ]b4_symbol_names[
@@ -296,7 +295,7 @@ m4_define([b4_declare_symbol_enum],
   ]b4_translatable[
       @};]])[
 
-      put(sink, yy_sname[yycode_]);
+      sink.formattedWrite!"%s"(yy_sname[yycode_]);
     }
   }
 ]])
-- 
2.25.1

From 09abb8372e95cf91d6334ec611f68eedecb62d15 Mon Sep 17 00:00:00 2001
From: Adela Vais <[email protected]>
Date: Mon, 19 Sep 2022 15:12:39 +0200
Subject: [PATCH 1/2] d: fix interface syntax error

Fix syntax error regarding interface inheritance of the Lexer. It appeared when the %code lexer option was used.

Reported by ledaniel2. Proposed solution by ledaniel2. Test added by Adela Vais.
<akimd#84>

* data/skeletons/lalr1.d: Fix syntax.
* tests/d.at: Test it.
---
 data/skeletons/lalr1.d | 5 +++--
 tests/d.at             | 7 +++++++
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/data/skeletons/lalr1.d b/data/skeletons/lalr1.d
index 3195dbf8..01175325 100644
--- a/data/skeletons/lalr1.d
+++ b/data/skeletons/lalr1.d
@@ -269,9 +269,10 @@ b4_user_union_members
     }
   }]])[
 
-]b4_lexer_if([[  private class YYLexer implements Lexer {
+]b4_lexer_if([[private class YYLexer: Lexer
+{
 ]b4_percent_code_get([[lexer]])[
-  }
+}
 ]])[
   /** The object doing lexical analysis for us.  */
   private Lexer yylexer;
diff --git a/tests/d.at b/tests/d.at
index 6be53eef..347e868c 100644
--- a/tests/d.at
+++ b/tests/d.at
@@ -112,6 +112,13 @@ AT_CHECK_D_GREP([[class YYParser : BaseClass]])
 AT_CHECK_D_MINIMAL([%define api.parser.extends {Interface}], [], [], [interface Interface {}])
 AT_CHECK_D_GREP([[class YYParser : Interface]])
 
+AT_CHECK_D_MINIMAL([%code lexer
+{
+  Symbol yylex () {return Symbol();}
+  void yyerror (string s) {import std.stdio;writeln(s);}
+}], [], [], [])
+AT_CHECK_D_GREP([[private class YYLexer: Lexer]])
+
 AT_CHECK_D_MINIMAL(
 [%define api.parser.extends {BaseClass}
 %define api.parser.implements {Interface}], [], [],
-- 
2.25.1

Reply via email to