From d03a7b220afbaa3bc461c246b4a20be3b1d739ca Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Thu, 16 Sep 2010 10:50:09 -0500 Subject: [PATCH] added docs for linebreaks parameter Adjusted implementation of linebreaking so that when there are linebreaks in a metafunction, the = signs line up together independent of the broken lines --- collects/redex/private/pict.rkt | 46 +++++++++++++++++++++------------ collects/redex/redex.scrbl | 12 ++++++++- 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/collects/redex/private/pict.rkt b/collects/redex/private/pict.rkt index b414a26a69..cc997fbf57 100644 --- a/collects/redex/private/pict.rkt +++ b/collects/redex/private/pict.rkt @@ -1,6 +1,7 @@ #lang scheme/base (require (lib "mrpict.ss" "texpict") (lib "utils.ss" "texpict") + racket/contract scheme/gui/base scheme/class scheme/match @@ -41,8 +42,6 @@ metafunction-font-size reduction-relation-rule-separation - linebreaks - just-before just-after @@ -54,6 +53,8 @@ compact-vertical-min-width extend-language-show-union set-arrow-pict!) +(provide/contract + [linebreaks (parameter/c (or/c #f (listof boolean?)))]) ; @@ -790,6 +791,11 @@ [eqns (select-cases all-eqns)] [lhss (select-cases all-lhss)] [rhss (map (lambda (eqn) (wrapper->pict (list-ref eqn 2))) eqns)] + [_ (unless (or (not current-linebreaks) + (= (length current-linebreaks) (length eqns))) + (error 'metafunction->pict "expected the current-linebreaks parameter to be a list whose length matches the number of cases in the metafunction (~a), but got ~s" + (length eqns) + current-linebreaks))] [linebreak-list (or current-linebreaks (map (lambda (x) #f) eqns))] [=-pict (make-=)] @@ -797,15 +803,18 @@ [max-line-w/pre-sc (apply max (map (lambda (lhs rhs linebreak?) - (max - (if (or linebreak? - (memq style '(up-down - up-down/vertical-side-conditions - up-down/compact-side-conditions))) - (max (pict-width lhs) - (+ (pict-width rhs) (pict-width =-pict))) - (+ (pict-width lhs) (pict-width rhs) (pict-width =-pict) - (* 2 sep))))) + (cond + [(and linebreak? (member #f linebreak-list)) + 0] + [(or linebreak? + (memq style '(up-down + up-down/vertical-side-conditions + up-down/compact-side-conditions))) + (max (pict-width lhs) + (+ (pict-width rhs) (pict-width =-pict)))] + [else + (+ (pict-width lhs) (pict-width rhs) (pict-width =-pict) + (* 2 sep))])) lhss rhss linebreak-list))] [scs (map (lambda (eqn) (let ([scs (reverse (list-ref eqn 1))]) @@ -838,11 +847,16 @@ (apply append (map (lambda (lhs sc rhs linebreak?) (append - (if linebreak? - (list lhs (blank) (blank)) - (if (and sc (eq? style 'left-right/beside-side-conditions)) - (list lhs =-pict (htl-append 10 rhs sc)) - (list lhs =-pict rhs))) + (cond + [(and linebreak? (member #f linebreak-list)) + (list (inset lhs 0 0 (- 5 (pict-width lhs)) 0) + (blank) + (blank))] + [linebreak? (list lhs (blank) (blank))] + [(and sc (eq? style 'left-right/beside-side-conditions)) + (list lhs =-pict (htl-append 10 rhs sc))] + [else + (list lhs =-pict rhs)]) (if linebreak? (let ([p rhs]) (list (htl-append sep diff --git a/collects/redex/redex.scrbl b/collects/redex/redex.scrbl index ff4f1b35db..7788775cd0 100644 --- a/collects/redex/redex.scrbl +++ b/collects/redex/redex.scrbl @@ -2018,7 +2018,17 @@ The @racket['left-right/beside-side-conditions] variant is like @racket['left-right], except it puts the side-conditions on the same line, instead of on a new line below the case.} - +@defparam[linebreaks breaks (or/c #f (listof boolean?))]{ + This parameter controls which cases in the metafunction + are rendered on two lines and which are rendered on one. + + If its value is a list, the length of the list must match + the number of cases and each boolean indicates if that + case has a linebreak or not. + + This influences the @racket['left/right] styles only. +} + @defparam[metafunction-cases cases (or/c #f (and/c (listof (and/c integer?