The `binary-rw` function from unstable/gui/redex library has some support for optionally parenthesizing its arguments.
Ryan On Wed, Feb 24, 2021 at 11:07 AM David Thrane Christiansen < da...@davidchristiansen.dk> wrote: > Hello all, > > I'm working on coding up a little language model in Redex, and I'd like to > get it to render things in the form that my colleagues are used to. This > means some infix operators as well as dealing with parenthesizing based on > operator precedence. > > Here's a boiled-down sample of what I'm up to: > > #lang racket > > (require redex pict) > > (define-language L > (C success (then C C) (or C C))) > > (with-compound-rewriters > (['or (match-lambda [(list _ _ x y _) (list "" x " or " y "")])] > ['then (match-lambda [(list _ _ x y _) (list "" x " then " y "")])]) > (vl-append > 20 > (render-language L) > (render-term L (then (or success success) success)))) > > I've attached the result. The resulting rendering of L looks appropriate, > but the nesting of then and or in the rendered term does not indicate the > nesting. I'd like to be able to specify precedence and associativity and > have parentheses inserted appropriately; failing that, a reasonable backup > would be parenthesizing sub-expressions that are not atomic. > > Can anyone point me at the right resource to use to figure out how to do > this? > > Thank you! > > David > > -- > 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/CAF_itEtHuJP6i%3DR3_ggKTn1%3DRDmswZfCiFMYJqBwcHqpXB7fpw%40mail.gmail.com > <https://groups.google.com/d/msgid/racket-users/CAF_itEtHuJP6i%3DR3_ggKTn1%3DRDmswZfCiFMYJqBwcHqpXB7fpw%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- 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/CANy33qmAv_KzhBj_%2B3NezyXgt6vAzL_M6dF0J9S%3DRZkQyA1HSQ%40mail.gmail.com.