Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / September 2005

Tip: Looking for answers? Try searching our database.

Syntax highlighting servlet

Thread view: 
Kenneth Patrick Turvey - 14 Sep 2005 18:08 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:

<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.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.