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
This commit is contained in:
parent
f8149ed985
commit
e96d9460fd
|
@ -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))
|
||||
|
|
|
@ -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).
|
||||
|
|
Loading…
Reference in New Issue
Block a user