[erlang-questions] Syntax highlight erlang code with erlang

Joe Armstrong <>
Fri May 25 14:53:06 CEST 2007


I have just written something that might be useful. It was rather
hacky so I'm not very proud
of it. To get the tagging correct is a bit of a pain. This is done in
several passes

1)
Modified the tokeniser (erl_scan.erl) to return the actual text in the tokens
- so, for example, when the original tokeniser returned {int, 6,  18}
(meaning the integer
18 on line 6) I now return {int,6,18,"16#12"} (suppose the integer was
written 16#12)
I also added all inter-token white space as {ws,Line,"..."} tokens and
retained the comments

In this stream of tokens the original source can be exactly
reconstructed by concatinating
all the strings in the tokens  - since I preserve everything.

2) Number each token 1,2,3,4

(This replaces the line number)

3) Keep a copy of this token list, and make a new token list that is
compatible with the parser

4) Modify the erlang parser. I took erl_parse.yrl and changed the RHS
to contain tagged
forms -

5) Merged the parse tree with the numbered-token list.

By this time I have a correct semantic tag for *everything* in the
source text (so keywords occurring
in strings won't causes accidental tagging errors (which would have
happened with a simple
-minded "regexp" approach).

The result is an abstract form which is easily turned in HTML or TeX
for printing.

I think the changes to the tokeniser should be folded into the main
OTP release - my version
involved "minimum changes" to the existing version, the result is a
mess which needs to be
rewritten.

This is part of a large project to produce *beautiful* documentation :-)

Cheers

/Joe






On 5/23/07, 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.
>
> /Petter
>
> > -----Original Message-----
> > From: 
> > [mailto:] On Behalf Of
> > Torbjorn Tornkvist
> > Sent: den 23 maj 2007 10:53
> > To: 
> > Subject: Re: [erlang-questions] Syntax highlight erlang code
> > with erlang
> >
> > Petter Larsson XA (TN/EAB) wrote:
> > > I have a file browser in yaws that I look at erlang code with.
> > > I would like to syntax highlight this code.
> > >
> > > What is the best way to view a erlang source code with syntax
> > > highlighting?
> > > I can parse the code with functions in Syntax_Tools I
> > guess, but does
> > > anyone have any example code for this?
> > >
> > > BR
> > > Petter Larsson
> > >
> >
> > Perhaps you could do it with Chili ?
> > Chili is the jQuery code highlighter plugin.
> >
> >  http://noteslog.com/chili/
> >
> > Would be nice if you could post the setup of Chili when
> > you're done... :-)
> >
> > --Tobbe
> >
> > _______________________________________________
> > erlang-questions mailing list
> > 
> > http://www.erlang.org/mailman/listinfo/erlang-questions
> >
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
>



More information about the erlang-questions mailing list