From d5bb6030ec95f49a3172ef34bf9ca27ebed593c0 Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Tue, 23 Dec 2014 13:12:47 -0600 Subject: [PATCH] tweak the way ellipses are inserted into contract names to avoid bottoming out with an ellpisis when the ellipsis is replacing a simple thing --- .../racket/contract/private/arr-util.rkt | 41 +++++++++++++------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/racket/collects/racket/contract/private/arr-util.rkt b/racket/collects/racket/contract/private/arr-util.rkt index 6e8005f763..bb05215900 100644 --- a/racket/collects/racket/contract/private/arr-util.rkt +++ b/racket/collects/racket/contract/private/arr-util.rkt @@ -9,10 +9,36 @@ (define (compute-quoted-src-expression stx) (define max-depth 4) (define max-width 5) + (define max-str/kwd/sym-length 20) + (define number-bound 1000000) + + (define (simple? ele) + (or (and (symbol? ele) + (< (string-length (symbol->string ele) + max-str/kwd/sym-length))) + (and (keyword? ele) + (< (string-length (keyword->string ele) + max-str/kwd/sym-length))) + (boolean? ele) + (char? ele) + (null? ele) + (and (string? ele) + (< (string-length ele) max-str/kwd/sym-length)) + (and (number? ele) + (simple-rational? (real-part ele)) + (simple-rational? (imag-part ele))))) + + (define (simple-rational? ele) + (or (inexact? ele) + (<= (- number-bound) (numerator ele) number-bound) + (<= (denominator ele) number-bound))) + (let loop ([stx stx] [depth max-depth]) (cond - [(zero? depth) '...] + [(zero? depth) + (define ele (syntax-e stx)) + (if (simple? ele) ele '...)] [else (define lst (syntax->list stx)) (cond @@ -26,18 +52,7 @@ '(...)))] [else (define ele (syntax-e stx)) - (cond - [(or (symbol? ele) - (boolean? ele) - (char? ele) - (number? ele)) - ele] - [(string? ele) - (if (< (string-length ele) max-width) - ele - '...)] - [else - '...])])]))) + (if (simple? ele) ele '...)])]))) ;; split-doms : syntax identifier syntax -> syntax ;; given a sequence of keywords interpersed with other