I opted for the read-syntax based solution. For those reading, it's convenient 
to use `replace-context` from `syntax/strip-context` to donate lexical info.

The form of the transformer I used is:

@(define-syntax (reformat stx)

(replace-context stx

(read-syntax #f (open-input-string (with-output-to-string
(lambda () (pretty-write `(begin . [...]))))))))

~slg

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Wednesday, September 23, 2020 8:07 PM, Philip McGrath 
<phi...@philipmcgrath.com> wrote:

> I have encountered this problem. I don't have a real solution, but maybe my 
> hacky solution will be good enough.
>
> On Wed, Sep 23, 2020 at 7:37 PM Sorawee Porncharoenwase 
> <sorawee.pw...@gmail.com> wrote:
>
>> I think Scribble uses source location equipped with syntax objects to figure 
>> out spacing. Since you generate stuff on the fly, there’s no source 
>> location, so the rendered text is screwed up.
>
> This is indeed the explanation. My hacky solution (you can see it 
> [here](https://github.com/DigitalRicoeur/pydrnlp/blob/666c1e00b67c0cc1ee6b5e3fbcfbec498b3173ac/support/python-lang/stx.rkt#L201-L208))
>  is to build up term for Scribble to typeset—the equivalent of what you do 
> [here](https://github.com/zyrolasting/xiden/blob/cb60c9d3ad06b60097b38e19d2d6f565ff9738c0/docs/reference/settings.scrbl#L37-L42),
>  I think—using `syntax` rather than `quasiquote`. IIRC (I haven't touched 
> this code in a while), it didn't work to use `quasisyntax`/`unsyntax`, so I 
> used `define/syntax-parse` to bind pattern variables to the generated 
> sub-terms. This way, Scribble picks up the source locations from the template 
> and uses spaces as it should.
>
> This is a hack, though: in my case, I'm building a `let*` expression with 
> potentially several binding pairs, and they will run off the margin of the 
> page. There are probably various other problems: I remember this code being a 
> bit annoying to write.
>
> -Philip

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CiSghugs88ldFptWHmfNDO0714NsRwS52CdG6Gmn8BowdGmT_q_xCdvBbGdzCPoHuxDvALOlqphQ8wnSWXvpLY9m5-m6dtFDOCYh5pOj1eQ%3D%40sagegerard.com.

Reply via email to