Version: 5.1.3
Syntax Color: Utilities
The "syntax-color" collection provides the underlying data
structures and some helpful utilities for the color:text%
class of the Framework: Racket GUI Application Framework.
1 Parenthesis Matching
Parenthesis matching code built on top of token-tree%.
2 Scheme Lexer
The scheme-lexer function returns 5 values:
Either a string containing the matching text or the eof object.
Block comments and specials currently return an empty string.
This may change in the future to other string or non-string data.
A symbol in '(error comment sexp-comment white-space constant string no-color parenthesis other symbol eof).
A symbol in '(|(| |)| |[| |]| |{| |}|) or #f.
A number representing the starting position of the match (or #f if eof).
A number representing the ending position of the match (or #f if eof).
Like
scheme-lexer, but returns an extra value. The last
return value indicates whether the consumed token should count as a
datum, an opening parenthesis (or similar starting token to group
other tokens), a closing parenthesis (or similar), or a prefix (such
as whitespace) on a datum.
3 Default lexer
A lexer that only identifies (, ), [,
], {, and } built specifically for
color:text%.
default-lexer returns 5 values:
Either a string containing the matching text or the eof object.
Block specials currently return an empty string.
This may change in the future to other string or non-string data.
A symbol in '(comment white-space no-color eof).
A symbol in '(|(| |)| |[| |]| |{| |}|) or #f.
A number representing the starting position of the match (or #f if eof).
A number representing the ending position of the match (or #f if eof).
4 Module Lexer
The module-lexer function accepts an offset and lexer
mode, instead of just an input port.
In addition to the results of scheme-lexer,
module-lexer returns a backup distance and a new lexer
mode.
When mode is #f (indicating the start of the
stream), the lexer checks in for a #lang
specification.
If a #lang line is present but the specified
language does not exist, the entire in input is
consumed and colored as 'error.
If the language exists and the language provides a
get-info function, then it is called with
'color-lexer. If the result is not #f, then
it should be a lexer function for use with
color:text%. The result mode is the lexer—paired
with #f if the lexer is a procedure arity 3—so that
future calls will dispatch to the language-supplied lexer.
If the language is specified but it provides no
get-info or 'color-lexer result, then
scheme-lexer is returned as the mode.
When mode is a lexer procedure, the lexer is applied
to in. The lexer’s results are returned, plus the
lexer again as the mode.
When mode is a pair, then the lexer procedure in the
car is applied to in, offset, and the mode in the
cdr. The lexer’s results are returned, except that its
mode result is paired back with the lexer procedure.
5 Scribble Lexer
Like
scribble-lexer, but starting in “text” mode instead of
Scheme mode.
6 Splay Tree for Tokenization
A splay-tree class specifically geared for the task of on-the-fly
tokenization. Instead of keying nodes on values, each node has a
length, and they are found by finding a node that follows a certain
total length of preceding nodes.
FIXME: many methods are not yet documented.
Creates a token tree with a single element.
Returns the root node in the tree.
Splays, setting the root node to be the closest node to
offset key-position (i.e., making the total length of
the left tree at least key-position, if possible).
Inserts tree1 into tree2 as the first thing, setting
tree2’s root to #f.
Inserts tree1 into tree2 as the last thing, setting
tree2’s root to #f.