Re: [racket-users] Why are these @defthing blocks typeset incorrectly?

2020-09-24 Thread Sage Gerard
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 
 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 
>  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.


Re: [racket-users] Why are these @defthing blocks typeset incorrectly?

2020-09-23 Thread Philip McGrath
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
)
is to build up term for Scribble to typeset—the equivalent of what you do
here
,
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/01000174bd6f57cc-a40851c2-a167-4790-b636-b43d9cf21e97-00%40email.amazonses.com.


Re: [racket-users] Why are these @defthing blocks typeset incorrectly?

2020-09-23 Thread Sorawee Porncharoenwase
Caution: I haven’t tried your code yet.

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.

An idea I have (which might not work) is to use write / pretty-write on the
generated code to a string port, and then read-syntax it back. That way,
you get the source locations correctly.

On Wed, Sep 23, 2020 at 4:17 PM Sage Gerard  wrote:

> I attached an image showing the rendered output of
> https://github.com/zyrolasting/xiden/blob/master/docs/reference/settings.scrbl#L48
>
> I create an application to `(defthing)` as a datum due to circumstances
> in the surrounding code. The hacky part being `get-contract-datum`, which
> tries to produce a datum usable as a contract expression. I'm assuming that
> this leaves no whitespace to preserve, so how do I modify a syntax object
> to include space in desired spots?
>
> *~slg*
>
>
> --
> 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/ulye9ZNaZmcspsE7fqy6ctobuGcF21jQvGQ4-PG2Eynt09KBU9AbF_kP9UZ_OgouhcvBOF8JLbaCJpVbnve-6RF_E752tVqp-xR9Va3oRsE%3D%40sagegerard.com
> 
> .
>

-- 
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/CADcuegt9o08A1PV_f%3DKg2G_%3DAVYor5M%2BWm5pRJXA0Zdi_%2BMqHQ%40mail.gmail.com.


[racket-users] Why are these @defthing blocks typeset incorrectly?

2020-09-23 Thread Sage Gerard
I attached an image showing the rendered output of 
https://github.com/zyrolasting/xiden/blob/master/docs/reference/settings.scrbl#L48

I create an application to `(defthing)` as a datum due to circumstances in the 
surrounding code. The hacky part being `get-contract-datum`, which tries to 
produce a datum usable as a contract expression. I'm assuming that this leaves 
no whitespace to preserve, so how do I modify a syntax object to include space 
in desired spots?

~slg

-- 
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/ulye9ZNaZmcspsE7fqy6ctobuGcF21jQvGQ4-PG2Eynt09KBU9AbF_kP9UZ_OgouhcvBOF8JLbaCJpVbnve-6RF_E752tVqp-xR9Va3oRsE%3D%40sagegerard.com.