module Higlo: sig
.. end
Syntax highligthing
type
token =
| |
of string |
| |
Constant of string |
| |
Directive of string |
| |
Escape of string |
| |
Id of string |
| |
Keyword of int * string |
| |
of string |
| |
Numeric of string |
| |
String of string |
| |
Symbol of int * string |
| |
Text of string |
Tokens read in the given code. These names are inspired from
the highlight
tool. Keyword
and Symbol
are parametrized by
an integer to be able to distinguish different families of keywords
and symbols, as kwa
, kwb
, ..., in highlight
.
val string_of_token : token -> string
For debug printing.
exception Unknown_lang of string
type
lexer = Ulexing.lexbuf -> token list
Lexers are based on Ulex. A lexer returns a list of tokens,
in the same order they appear in the read string.
Text
tokens are merged by the
Higlo.parse
function.
val get_lexer : string -> lexer
get_lexer lang
returns the lexer registered for the given language
lang
or raises
Higlo.Unknown_lang
if no such language was registered.
val register_lang : string -> lexer -> unit
If a lexer was registered for the same language, it is not
available any more.
val parse : lang:string -> string -> token list
parse ~lang code
gets the lexer associated to lang
and uses it to build a list of tokens. Consecutive Text
tokens are merged.
If no lexer is associated to the given language, then
the function returns Text code
.
type
classes = {
|
: string ; |
|
constant : string ; |
|
directive : string ; |
|
escape : string ; |
|
id : string ; |
|
keyword : int -> string ; |
|
: string ; |
|
numeric : string ; |
|
string : string ; |
|
symbol : int -> string ; |
|
text : string ; |
}
This structure defines the (X)HTML classes to use
when producing XML.
val default_classes : classes
Default X(HTML) classes.
val token_to_xtmpl : ?classes:classes -> token -> Xtmpl.tree
Map a token to an XML tree (just a <span class="...">code</span>
node).
classes
: is used to change the class names used in the generated
node.
val to_xtmpl : ?classes:classes -> lang:string -> string -> Xtmpl.tree list
to_xtmpl ~lang code
gets the lexer associated to the language
lang
,
uses it to retrieve a list of tokens (using the
Higlo.parse
function)
and maps these tokens to XML nodes. See
Higlo.token_to_xtmpl
about
the
classes
parameter.