takikawa / sweet-racket

A port of sweet expressions to Racket
http://pkg-build.racket-lang.org/doc/sweet/index.html
Other
47 stars 10 forks source link

provide 'sweet-exp-not-actual-parens syntax property #14

Closed AlexKnauth closed 9 years ago

AlexKnauth commented 9 years ago

The srcloc tests are failing on Travis CI, but they work fine when I run it in DrRacket or with command-line racket.

AlexKnauth commented 9 years ago

The reason I wanted to do this was so that if I'm making a macro that will be used like this:

my-cond
  #:if condition
    body ...+
  #:else
    body ...+

So it will read to this:

(my-cond
  #:if [condition
        body ...]
  #:else
    :body-or-bodys ; depending on how many expressions there were
  )

Where body-or-bodys is like this:

[pattern
 (~and bodys [body:expr ...+])
 #:when (syntax-property #'bodys 'sweet-exp-not-actual-parens)]
[pattern single-body #:with (body ...) #'(singe-body)]

But I don't what it to un-parenthesize things that actually were supposed to have parentheses, so I would want to look at the syntax-property to see whether those parens were put there by the user or by sweet-exp.

There's another problem with this as well, because if there is a single expression that was read as a sweet-exp, then it would un-parenthesize that, but I'm not sure there's a good way to solve that. The syntax-property could still be useful for other macros though.

AlexKnauth commented 9 years ago

I think a better way to solve problems like this would be to provide it as an extra option for the 'paren-shape syntax property, so I'm closing this.

If you, I, or someone else thinks providing it as a 'paren-shape property would be useful for something, then I'll make that a new pull request.