Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dented42 opened this issue Oct 25, 2017 · 3 comments
Open

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

dented42 opened this issue Oct 25, 2017 · 3 comments

Comments

@dented42
Copy link

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)))
@soegaard
Copy link

soegaard commented Oct 25, 2017 via email

@dented42
Copy link
Author

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

@soegaard
Copy link

Yes it does.

Consider how variables are represented:

 Representation of variables during compilation.

(struct variable (id) #:transparent)

(define (unparse-variable x)
  (syntax->datum (variable-id x)))

The id held by a variable struct is a syntax object representing a symbol.
In order to get nice printout, we need to use a "prettifier" in the language specification.

This looks like:

(define-language LFE    ; FE = Fully Expanded
  (entry TopLevelForm)
  (terminals
   ((variable    (x xd)) . => . unparse-variable)
   etc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants