[erlang-questions] Syntax highlight erlang code with erlang
Richard Carlsson
richardc@REDACTED
Wed May 23 12:32:06 CEST 2007
Petter Larsson XA (TN/EAB) wrote:
> I would actually prefer doing it in erlang code, soo I can create links
> fo other filer etc. when possible.
>
> Doesn't anyone have an example code of highligting erlang code with
> erl_syntax etc.
I don't have any example code at hand, but you can do it fairly easily,
the following way:
1. Traverse the syntax tree (use erl_syntax:subtrees/1) and add
annotations (erl_syntax:add_ann/2) on nodes of interest.
2. Use erl_prettypr:format/2 and pass it a hook function that adds
additional markup depending on the annotation. (See the
documentation for a trivial example.)
You might be able to put all the functionality directly in the hook,
but it's cleaner to separate the analysis and format phases like above.
(I've mainly used this to visualize the results of data flow analyses,
which typically just involved colouring certain subexpressions red. If
you write a larger example that could be useful for the general public,
it would be nice if you posted it here.)
/Richard
More information about the erlang-questions
mailing list