Higlo comes with a command line tool, higlo. It reads source code files and outputs this code syntactically highlighted. If no source code file is given on the command line, then standard input is read instead. The source language (the lexer used) and the output format can be specified on the command line. The default language is "ocaml" and default output format is "xml".

Compiled OCaml code can be loaded to add languages or output formats.

Synopsis

Usage:

higlo [options] [source files]
where options are:
  -v                          verbose mode
  -f <s>                      set output format to <s>; default is xml
  -l <s>                      set language to <s>; default is ocaml
  --pkg pkg1,pkg2,...         dynmically load the given packages
  --load file1.cm[xs|o|a],... dynmically load the given object files
  -help                       Display this list of options
  --help                      Display this list of options
mk-higlo

The mk-higlo script eases the creation of a custom executable, i.e. a higlo tool where additional code is already linked in.

Suppose we defined an additional printer in myprint.ml. The printer only prints the code in raw text. We do not forget to register the printer using Higlo.Printers.register_printer:

open Higlo.Lang

let token_to_string = function
| Bcomment (s,_)
| Constant (s,_)
| Directive (s,_)
| Escape (s,_)
| Id (s,_)
| Keyword (_, (s, _))
| Lcomment (s,_)
| Numeric (s,_)
| String (s,_)
| Symbol (_, (s, _))
| Text (s, _) -> s
;;

let printer tokens =
  List.iter (fun t -> print_string (token_to_string t)) tokens
;;

let () = Higlo.Printers.register_printer "raw" printer;;

We can create a new higlo tool already containing this module:

mk-higlo -o myhiglo myprint.ml

Now we can use the "raw" printer with the produced executable:

./myhiglo -f raw mycode.ml