nanopass-framework-scheme icon indicating copy to clipboard operation
nanopass-framework-scheme copied to clipboard

unparser should take context into account.

Open akeep opened this issue 8 years ago • 0 comments

Right now the unparser simply recurs to the top-level unparser on sub-parts. This means that if more than one terminal has the same domain, e.g., if we use symbols to represent both variables and constant symbols, differentiated by context, we will see all of them printed out the same way, even if the language specifies different unparsers for these two terminals.

One caveat to note with this is that if the unparser is called directly on one of these terminals, there is no way to determine which one it is (since the only way it can differentiate these things is using the terminal predicate, and two predicates will return true for the same actual terminal.)

Originally reported by @soegaard on nanopass framework google group with the following test program (in Racket):

#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)))

akeep avatar Apr 30 '16 23:04 akeep