Hi Robby, I suppose a system that optionally annotated each alternative for a nonterminal with precedence and associativity would be the maximally featureful way to go here, with unannotated alternatives being parenthesized like today. Something akin to #:binding-forms, I guess. But I haven't dug enough into the current pict rendering to know if that would fit in nicely to the current customization system.
/David Den ons. 24. feb. 2021 kl. 20.38 skrev Robby Findler < [email protected]>: > Yeah, I've been meaning to integrate those parts of that library into > Redex proper but just haven't found the time. > > Also, I've thought it would be nice if Redex were able to look at the > context of a particular, say, "or" or "then" expression and figure out if > it needed parens. Sadly, for now you have to specialize the rewriting based > on specific examples you're rendering (or just have too many parens, sigh). > > Robby > > > On Wed, Feb 24, 2021 at 4:46 AM David Thrane Christiansen < > [email protected]> wrote: > >> Thanks Ryan! >> >> There's all sorts of nice goodies in that library, like >> current-atomic-rewriters and friends. >> >> David >> >> Den ons. 24. feb. 2021 kl. 11.29 skrev Ryan Culpepper < >> [email protected]>: >> >>> 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 < >>> [email protected]> 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 [email protected]. >>>> 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 [email protected]. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/racket-users/CAF_itEt9JUSZBUZ_09keQmXpUo0HJbYahN4dXD%2Bjp8jp9A2cXw%40mail.gmail.com >> <https://groups.google.com/d/msgid/racket-users/CAF_itEt9JUSZBUZ_09keQmXpUo0HJbYahN4dXD%2Bjp8jp9A2cXw%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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/CAF_itEs7f9MQ%2BrRjZx6N_6cNdbc7CsYyfc14HSpPJ3vKdOPzFg%40mail.gmail.com.

