[PATCH for Dlang support] d: support api.symbol.prefix and api.token.prefix

Adela Vais <[email protected]>
Newsgroups gmane.comp.parsers.bison.patches
Message-ID <[email protected]>
The D skeleton was not properly supporting them.

* data/skeletons/d.m4, data/skeletons/lalr1.d: Fix it.
* tests/calc.at: Check it.
---
 data/skeletons/d.m4    |  2 +-
 data/skeletons/lalr1.d |  8 ++++----
 tests/calc.at          | 32 +++++++++++++++++---------------
 3 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/data/skeletons/d.m4 b/data/skeletons/d.m4
index 9e4c4995..70264214 100644
--- a/data/skeletons/d.m4
+++ b/data/skeletons/d.m4
@@ -186,7 +186,7 @@ m4_define([b4_token_enum],
 m4_define([b4_token_enums],
 [/* Token kinds.  */
 public enum TokenKind {
-  ]b4_symbol_kind([-2])[ = -2,
+  ]b4_symbol(-2, id)[ = -2,
 b4_symbol_foreach([b4_token_enum])dnl
 }
 ])
diff --git a/data/skeletons/lalr1.d b/data/skeletons/lalr1.d
index 6d1bdfdd..e74b2e05 100644
--- a/data/skeletons/lalr1.d
+++ b/data/skeletons/lalr1.d
@@ -394,7 +394,7 @@ b4_locations_if([, ref ]b4_location_type[ yylocationp])[)
   public bool parse ()
   {
     // Lookahead token kind.
-    int yychar = TokenKind.YYEMPTY;
+    int yychar = TokenKind.]b4_symbol(-2, id)[;
     // Lookahead symbol kind.
     SymbolKind yytoken = ]b4_symbol(-2, kind)[;
 
@@ -459,7 +459,7 @@ m4_popdef([b4_at_dollar])])dnl
         }
 
         /* Read a lookahead token.  */
-        if (yychar == TokenKind.YYEMPTY)
+        if (yychar == TokenKind.]b4_symbol(-2, id)[)
         {]b4_parse_trace_if([[
           yycdebugln ("Reading a token");]])[
           yychar = yylex ();]b4_locations_if([[
@@ -511,7 +511,7 @@ m4_popdef([b4_at_dollar])])dnl
             yy_symbol_print ("Shifting", yytoken, yylval]b4_locations_if([, yylloc])[);]])[
 
             /* Discard the token being shifted.  */
-            yychar = TokenKind.YYEMPTY;
+            yychar = TokenKind.]b4_symbol(-2, id)[;
 
             /* Count tokens shifted since error; after three, turn off error
              * status.  */
@@ -571,7 +571,7 @@ m4_popdef([b4_at_dollar])])dnl
              return false;
           }
           else
-            yychar = TokenKind.YYEMPTY;
+            yychar = TokenKind.]b4_symbol(-2, id)[;
         }
 
         /* Else will try to reuse lookahead token after shifting the error
diff --git a/tests/calc.at b/tests/calc.at
index e44000a2..ec8723c9 100644
--- a/tests/calc.at
+++ b/tests/calc.at
@@ -606,13 +606,13 @@ class CalcLexer(R) : Lexer
 
     // EOF.
     if (input.empty)
-      return TokenKind.CALC_EOF;
+      return TokenKind.]AT_TOKEN_PREFIX[CALC_EOF;
 
     // Numbers.
     if (input.front.isNumber)
       {
         semanticVal_.ival = parseInt;
-        return TokenKind.NUM;
+        return TokenKind.]AT_TOKEN_PREFIX[NUM;
       }
 
     // Individual characters
@@ -630,22 +630,22 @@ class CalcLexer(R) : Lexer
     if (c == '#')
       {
         stderr.writeln (]AT_LOCATION_IF([location, ": ", ])["syntax error: invalid character: '#'");
-        return TokenKind.YYerror;
+        return TokenKind.]AT_TOKEN_PREFIX[YYerror;
       }
 
     switch (c)
     {
-      case '+':  return TokenKind.PLUS;
-      case '-':  return TokenKind.MINUS;
-      case '*':  return TokenKind.STAR;
-      case '/':  return TokenKind.SLASH;
-      case '(':  return TokenKind.LPAR;
-      case ')':  return TokenKind.RPAR;
-      case '\n': return TokenKind.EOL;
-      case '=':  return TokenKind.EQUAL;
-      case '^':  return TokenKind.POW;
-      case '!':  return TokenKind.NOT;
-      default:   return TokenKind.YYUNDEF;
+      case '+':  return TokenKind.]AT_TOKEN_PREFIX[PLUS;
+      case '-':  return TokenKind.]AT_TOKEN_PREFIX[MINUS;
+      case '*':  return TokenKind.]AT_TOKEN_PREFIX[STAR;
+      case '/':  return TokenKind.]AT_TOKEN_PREFIX[SLASH;
+      case '(':  return TokenKind.]AT_TOKEN_PREFIX[LPAR;
+      case ')':  return TokenKind.]AT_TOKEN_PREFIX[RPAR;
+      case '\n': return TokenKind.]AT_TOKEN_PREFIX[EOL;
+      case '=':  return TokenKind.]AT_TOKEN_PREFIX[EQUAL;
+      case '^':  return TokenKind.]AT_TOKEN_PREFIX[POW;
+      case '!':  return TokenKind.]AT_TOKEN_PREFIX[NOT;
+      default:   return TokenKind.]AT_TOKEN_PREFIX[YYUNDEF;
     }
   }
 }
@@ -1449,7 +1449,9 @@ AT_CHECK_CALC_LALR1_D([%define parse.error verbose %define api.prefix {calc} %ve
 AT_CHECK_CALC_LALR1_D([%debug])
 
 AT_CHECK_CALC_LALR1_D([%define parse.error verbose %debug %verbose])
-#AT_CHECK_CALC_LALR1_D([%define parse.error verbose %debug %define api.token.prefix {TOK_} %verbose])
+AT_CHECK_CALC_LALR1_D([%define parse.error verbose %debug %define api.token.prefix {TOK_} %verbose])
+AT_CHECK_CALC_LALR1_D([%define parse.error verbose %debug %define api.symbol.prefix {SYMB_} %verbose])
+AT_CHECK_CALC_LALR1_D([%define parse.error verbose %debug %define api.symbol.prefix {SYMB_} %define api.token.prefix {TOK_} %verbose])
 
 #AT_CHECK_CALC_LALR1_D([%locations %define parse.error verbose %debug %verbose %parse-param {semantic_value *result}{int *count}{int *nerrs}])
 #AT_CHECK_CALC_LALR1_D([%locations %define parse.error verbose %debug %define api.prefix {calc} %verbose %parse-param {semantic_value *result}{int *count}{int *nerrs}])
-- 
2.17.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.