Lexer Listings
This library implements something similar to scribble/manual module’s codeblock, codeblock0, code, and typeset-code. However, the typesetting forms and functions here assume foreign code, and no #lang to specify the language used. Instead, one must explicitly specify a color lexer function to use, one with the same signature as that of default-lexer and racket-lexer.
This package presently includes only one lexer, namely the cxx-lexer in the lexer-listings/cxx module.
1 Language-Agnostic API
(require lexer-listings) | package: lexer-listings |
The lexcodeblock, lexcodeblock0, lexcode, and typeset-lexcode forms are used for typesetting foreign code, with a lexer explicitly specified as the first argument.
For example,
This is @lexcode[cxx-lexer]{1 + 2}.
produces the typeset result:
This is 1 + 2.
syntax
(lexcodeblock lexer-expr str-expr ...+)
str-expr : string?
For example,
@lexcodeblock[cxx-lexer]|{ int f(int const& x) { if (f <= 1) return 1; else return x*f(x-1); } }|
produces the typeset result:
int f(int const& x) { if (f <= 1) return 1; else return x*f(x-1); }
syntax
(lexcodeblock0 lexer-expr option ... str-expr ...+)
procedure
(typeset-lexcode strs ...) → block?
strs : string?
value
value
value
When rendering a document, the styles translate as FrgKw, FrgName, and FrgSym. If tokens of the associated types are emitted, definitions for those style classes must then be provided in a renderer-specific way. See Manual CSS Style Classes for a list of Racket manual style classes, which can serve as examples for providing definitions for FrgKw, etc. See this package’s "style.css" for an example definition for CSS.
2 Acknowledgements
This document and parts of the software are based on Leif Andersen’s work on the r-lexer package. The rest of the software is based on code from Racket’s scribble-lib package.