Re: [PATCH for Dlang support] Push parser

Adela Vais <[email protected]> Sun, 18 Apr 2021 13:39:47 +0300
Newsgroups gmane.comp.parsers.bison.patches
Message-ID <CAPk8xGeVE0BdmDyydCwCvODEpomH_3N3bzCnk4K7YFvgAEM-KQ@mail.gmail.com>
Hello Akim,

I updated the 'calc' example to use token constructors.

Adela

În lun., 12 apr. 2021 la 07:46, Akim Demaille <[email protected]> a scris:

> Hi Adela,
>
> > Le 2 avr. 2021 à 01:23, Adela Vais <[email protected]> a écrit :
> >
> > În sâm., 27 mar. 2021 la 08:35, Akim Demaille <[email protected]> a
> scris:
> >
> >> I see that you have keep the possibility for the regular pull parser
> >> to use local variables.  Have you benchmarked if this is worth the
> >> effort?  Because it there's no measurable difference, you may just
> >> as well always use attributes of the parser object.  That would simplify
> >> the skeleton.
> >>
> >
> > I benchmarked it, and there is no measurable difference. I put the
> > variables as class attributes.
>
> Good!
>
> >> I don't think we need too many examples.  So I would go with keeping
> >> a super simple one, and have the other one grow with all the bells
> >> and whistles, a bit like what the bistromathic example does in C.
> >>
> >
> > I added the push parser to the 'calc' example.
>
> Perfect!  I would suggest that this example also use the token
> constructor functions.
>
> Installed.
>
> Cheers!
0001-d-demonstrate-the-token-constructors.patch (application/octet-stream, 2.2 KB)
From a9962987dafe839b8d917b767523fde7a4311118 Mon Sep 17 00:00:00 2001
From: Adela Vais <[email protected]>
Date: Sun, 18 Apr 2021 12:56:47 +0300
Subject: [PATCH for Dlang support] d: demonstrate the token constructors

* examples/d/calc/calc.y: Use the token constructors in the 'calc' example.
---
 examples/d/calc/calc.y | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/examples/d/calc/calc.y b/examples/d/calc/calc.y
index 6e062a69..7273d16c 100644
--- a/examples/d/calc/calc.y
+++ b/examples/d/calc/calc.y
@@ -23,6 +23,7 @@
 %define parse.error detailed
 %define parse.trace
 %define api.push-pull push
+%define api.token.constructor
 
 %locations
 
@@ -122,7 +123,7 @@ if (isInputRange!R && is(ElementType!R : dchar))
     location.step();
 
     if (input.empty)
-      return Symbol(TokenKind.YYEOF, location);
+      return Symbol.YYEOF(location);
 
     // Numbers.
     if (input.front.isNumber)
@@ -149,7 +150,7 @@ if (isInputRange!R && is(ElementType!R : dchar))
           copy.popFront;
         }
       }
-      return Symbol(TokenKind.NUM, ival, location);
+      return Symbol.NUM(ival, location);
     }
 
     // Individual characters
@@ -158,17 +159,17 @@ if (isInputRange!R && is(ElementType!R : dchar))
     location.end.column++;
     switch (ch)
     {
-      case '+':  return Symbol(TokenKind.PLUS, location);
-      case '-':  return Symbol(TokenKind.MINUS, location);
-      case '*':  return Symbol(TokenKind.STAR, location);
-      case '/':  return Symbol(TokenKind.SLASH, location);
-      case '(':  return Symbol(TokenKind.LPAR, location);
-      case ')':  return Symbol(TokenKind.RPAR, location);
+      case '+':  return Symbol.PLUS(location);
+      case '-':  return Symbol.MINUS(location);
+      case '*':  return Symbol.STAR(location);
+      case '/':  return Symbol.SLASH(location);
+      case '(':  return Symbol.LPAR(location);
+      case ')':  return Symbol.RPAR(location);
       case '\n':
       {
         location.end.line++;
         location.end.column = 1;
-        return Symbol(TokenKind.EOL, location);
+        return Symbol.EOL(location);
       }
       default: assert(0);
     }
-- 
2.25.1