Unparsers ignore the terminal

22 views
Skip to first unread message

Jens Axel Søgaard

unread,
Sep 19, 2015, 11:29:28 AM9/19/15
to nanopass-...@googlegroups.com
Hi All,

The output of the following program is:

    '(foo (prop a) (prop b))

I was hoping for:

    '(foo (id a) (prop b))

The problem is that a syntax object representing a symbol
can be both an identifier and a property. 

Since the nonterminal (foo x p) declares that the first x is an identifier
and p is a property, the unparser could pick the correct unparser.

/Jens Axel


#lang racket
(require nanopass/base)

(define id?              identifier?)
(define (unparse-id id)  (list 'id (syntax-e id)))

(define property?            identifier?)
(define (unparse-property p) (list 'prop (syntax-e p)))

(define-language L
  (entry Foo)
  (terminals ((id       (x)) . => . unparse-id)
             ((property (p)) . => . unparse-property))
  (Foo (f)
    (foo x p)))

(unparse-L
 (with-output-language (L Foo)
   `(foo ,#'a ,#'b)))



Andy Keep

unread,
Apr 30, 2016, 7:39:34 PM4/30/16
to nanopass-...@googlegroups.com, Jens Axel Søgaard
Yeah, this is definitely a bug.  The unparsers are written to be very permissive, so you can unparse any nonterminal or terminal, however, it is also lazy in that it just applies the top-level unparser to sub-parts instead of using the context to be smarter about it.

I’ve added an issue to both the racket and scheme versions of the project and assigned them to me, since I think these are probably going to be fairly similar changes (though it has been a while since I looked at the racket code, so it may have changed on me :)

Thanks for reporting this, I’ll try to fix this up soon!

-andy:)
--
You received this message because you are subscribed to the Google Groups "nanopass-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nanopass-framew...@googlegroups.com.
To post to this group, send email to nanopass-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nanopass-framework/CABefVgxVo0OpJHMePiKPDazyr2vwkZ8w1MAbArFE9DxRY--z5A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages