[erlang-questions] Syntax highlight erlang code with erlang

Tamas Nagy lestat@REDACTED
Wed May 23 14:09:57 CEST 2007


On Wed, 2007-05-23 at 13:41 +0200, Petter Larsson XA (TN/EAB) wrote:
> > 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.
> 
> How do I get this syntax tree in the first place, if I use
> epp_dogder:parse_file all comments in the file is lost. What is the
> correct function to create a full syntax tree from a source code?

{ok, Form1} = epp_dodger:parse_file(File),
Comments = erl_comment_scan:file(File),
Form2 = erl_recomment:recomment_forms(Form1, Comments),
Form3 = erl_syntax:flatten_form_list(Form2)

And in Form3 you get the whole AST with comments.
There are seperate comment nodes, and comment nodes attached to other
nodes (pre- and postcomments)


%%This will be a seperate comment

%%This will be a precomment of the function node
f()-> 3.
%%This will be a postcomment of the function node.

%%This will be another separate comment.


	Tamas
> 
> /Petter
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list