From e96d9460fd58ccf4ac8a044bda269b241cf4b9ef Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Sat, 29 Jan 2011 12:26:59 -0600 Subject: [PATCH] added a color:text method get-token-range and then used that to improve how f1 in drracket works Please include this commit on the release branch original commit: 4090eabacb8d7b32900b4df18da06f14f1def40f --- collects/framework/private/color.rkt | 18 ++++++++++++++---- collects/scribblings/framework/color.scrbl | 12 +++++++++++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/collects/framework/private/color.rkt b/collects/framework/private/color.rkt index f7be4ce5..08ef4f5e 100644 --- a/collects/framework/private/color.rkt +++ b/collects/framework/private/color.rkt @@ -817,16 +817,26 @@ added get-regions ;; Determines whether a position is a 'comment, 'string, etc. (define/public (classify-position position) + (define tokens (get-tokens-at-position 'classify-position position)) + (and tokens + (let ([root-data (send tokens get-root-data)]) + (and root-data + (data-type root-data))))) + + (define/public (get-token-range position) + (define tokens (get-tokens-at-position 'get-token-range position)) + (values (and tokens (send tokens get-root-start-position)) + (and tokens (send tokens get-root-end-position)))) + + (define/private (get-tokens-at-position who position) (when stopped? - (error 'classify-position "called on a color:text<%> whose colorer is stopped.")) + (error who "called on a color:text<%> whose colorer is stopped.")) (let ([ls (find-ls position)]) (and ls (let ([tokens (lexer-state-tokens ls)]) (tokenize-to-pos ls position) (send tokens search! (- position (lexer-state-start-pos ls))) - (let ([root-data (send tokens get-root-data)]) - (and root-data - (data-type root-data))))))) + tokens)))) (define/private (tokenize-to-pos ls position) (when (and (not (lexer-state-up-to-date? ls)) diff --git a/collects/scribblings/framework/color.scrbl b/collects/scribblings/framework/color.scrbl index 979155fa..2dd561e6 100644 --- a/collects/scribblings/framework/color.scrbl +++ b/collects/scribblings/framework/color.scrbl @@ -212,7 +212,7 @@ right kind. If @scheme[flash?] is true, the matching open parenthesis will be flashed. } - @defmethod*[(((classify-position (position natural-number?)) symbol?))]{ + @defmethod*[(((classify-position (position exact-nonnegative-integer?)) symbol?))]{ Return a symbol for the lexer-determined token type for the token that @@ -221,6 +221,16 @@ Must only be called while the tokenizer is started. } + @defmethod[(get-token-range [position exact-nonnegative-integer?]) + (values (or/c #f exact-nonnegative-integer?) + (or/c #f exact-nonnegative-integer?))]{ + + Returns the range of the token surrounding @racket[position], if there is a token there. + + This method must be called only when the tokenizer is started. + + } + @defmethod[#:mode augment (on-lexer-valid [valid? boolean?]) any]{ This method is an observer for when the lexer is working. It is called when the lexer's state changes from valid to invalid (and back).