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

nanopass doesn't (accept|work with) syntax objects

Open dented42 opened this issue 6 years ago • 2 comments

Syntax objects in Racket have lots of lovely properties, it would be nice at some point for nanopass to be able to parse syntax objects.

Another goal that seems like a nice thing to have would be to have passes themselves be able to preserve the syntax scope and location information that syntax objects use throughout compilation. This would let the final compiled result be a syntax object that knows it's history.

I'm unsure how out-of-scope such a goal is with regards to the current road map. It does, however, seem to me like the following should, at some point in the future, work.

#lang nanopass

(define (nat-zero? x)
  (eq? x 'Z))

(define-language nats
  (terminals
   [nat-zero (Z)])
  (Nat (nat)
       Z
       (S nat)))

(define-parser parse-nats nats)

(parse-nats 'Z)
(parse-nats '(S (S Z)))

(parse-nats #'Z)
(parse-nats #'(S (S Z)))

dented42 avatar Oct 25 '17 20:10 dented42

Here is an example of parsing a syntax-object using nanopass.

https://github.com/soegaard/urlang/blob/master/compiler-rjs/compiler.rkt#L328

/Jens Axel

2017-10-25 22:51 GMT+02:00 dented42 [email protected]:

Syntax objects in Racket have lots of lovely properties, it would be nice at some point for nanopass to be able to parse syntax objects.

Another goal that seems like a nice thing to have would be to have passes themselves be able to preserve the syntax scope and location information that syntax objects use throughout compilation. This would let the final compiled result be a syntax object that knows it's history.

I'm unsure how out-of-scope such a goal is with regards to the current road map. It does, however, seem to me like the following should, at some point in the future, work.

#lang nanopass

(define (nat-zero? x) (eq? x 'Z))

(define-language nats (terminals [nat-zero (Z)]) (Nat (nat) Z (S nat)))

(define-parser parse-nats nats)

(parse-nats 'Z) (parse-nats '(S (S Z)))

(parse-nats #'Z) (parse-nats #'(S (S Z)))

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/nanopass/nanopass-framework-racket/issues/18, or mute the thread https://github.com/notifications/unsubscribe-auth/AAcLxSKHVP4ryRS1janHhjeRNUQfBSRPks5sv59MgaJpZM4QGpE3 .

--

Jens Axel Søgaard

soegaard avatar Oct 25 '17 21:10 soegaard

Does the take into account and preserve source location information? I can't quite tell from reading it.

dented42 avatar Jan 27 '20 05:01 dented42