I would like to post some .java files on a web site. I would like the
source code to be displayed with syntax highlighting. Ideally I would have a
tag that included a .java file in a jsp page and handled syntax highlighting:
<highlighter:include>my_file.java</highlighter:include>
Other alternatives would be OK too. Is there such a beast available?
Out of curiosity, in case I end up implementing this myself, do most syntax
highlighting engines use regular expression substitutions, or do they actually
parse the language being highlighted? Is the extra effort involved in parsing
worth it?
Thanks,
- - --
Kenneth P. Turvey <kt-usenet@squeakydolphin.com>
http://kt.squeakydolphin.com (not much there yet)
Jabber IM: kpturvey@jabber.org
Phone: (314) 255-2199
Chris Smith - 14 Sep 2005 19:07 GMT
> Out of curiosity, in case I end up implementing this myself, do most syntax
> highlighting engines use regular expression substitutions, or do they actually
> parse the language being highlighted? Is the extra effort involved in parsing
> worth it?
The vast majority of syntax highlighter only do the lexical analysis
(which you can do with regular expressions). Parsing is definitely
harder and there's no core API to do it (Java 1.4 and later comes with a
regular expression matcher). Whether it's worth it is, of course, your
call... but for casual uses, I'd say no. Anyone doing serious work on
the code will copy it into a development tool anyway.

Signature
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Roedy Green - 14 Sep 2005 21:30 GMT
>Out of curiosity, in case I end up implementing this myself, do most syntax
>highlighting engines use regular expression substitutions, or do they actually
>parse the language being highlighted? Is the extra effort involved in parsing
>worth it?
I have written ones for Java, HTML, SQL and bat language for JDisplay.
You can see the results all over my website. The parsers have to work
for fragments of code and invalid syntax, so they can't be a standard
parsers. I did them with finite state automatons, not regexes. I
make distinctions between where a thing is defined and referenced.
My parsers run ahead of time and leave behind a file of compressed
tokens -- one token for each string that is in a given colour and
font.
For short snippets, these are expanded into HTML where CSS does the
colour and font assignment. For long snippets an Applet renders the
token file on a Canvas, possibly in a ScrollPane. The front end stuff
works in Java 1.2+ The backend is Java 1.5
See http://mindprod.com/projects/javapresenter.html

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
Roedy Green - 14 Sep 2005 23:46 GMT
>My parsers run ahead of time and leave behind a file of compressed
>tokens -- one token for each string that is in a given colour and
>font.
the token has no fields other than the text. The colour and font are
implicit in the token type which has instance methods for computing
them.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
Bryce - 14 Sep 2005 22:25 GMT
>I would like to post some .java files on a web site. I would like the
>source code to be displayed with syntax highlighting. Ideally I would have a
>tag that included a .java file in a jsp page and handled syntax highlighting:
http://www.java2html.de/
--
now with more cowbell
Roedy Green - 15 Sep 2005 00:11 GMT
>http://www.java2html.de/
I have a list of similar projects, though that one looks most
promising at http://mindprod.com/jgloss/pretty-printer.html

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.