Skip to main content
GameDev.net gamedev.net
🔒 Locked

syntax highlight

Started by thecrow21 Jan 23, 2005 at 11:39 AM 5 replies 1.1k views
Original Post
thecrow21
thecrow21
does anybody know where can I find some sample code on syntax highlighting? I want to write an editor for my own scripting language and I definitely want to support syntax coloring. A highly customizable editor would be good, but I prefer one of my own. Where can I find docs or methods on the specific subject? thanks!
thecrow21
thecrow21
no reply yet? why?
JohnBolton
JohnBolton
If your editor runs in Windows, try The Code Project. That's a great source for Windows application programming.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
doynax
doynax
Why not try adapting the compiler's own lexer instead? Just integerate it into some editing widget and map each token class onto a color.
That way you don't have to write and maintain multiple parsers, nor restort to hacking togheter a set of regexps that only works half the time.

Might be a bit slow since you'd have to reparse the file all the time, but if it's good enough for nedit..
onebeer
onebeer
Your best bet is to find an editor widget that does what you want. Our application is written in Delphi with a Basic-like scripting language. We found an editor component with source that allowed us to extend it as well as use the existing syntax hilighting.

What language are you using?
onebeer
thecrow21
thecrow21
I have designed one of my own using flex/bison. Actually, I was planning to use my lexer in order to take each token's class, but the 'parse the whole file' thing is what I'm worrying about. I believe I just have to parse the last word typed in order for the highlighter to be fast enough, but its a bit complicated. that's why I would like to see an example first.

[Edited by - thecrow21 on January 23, 2005 3:31:09 PM]
doynax
doynax
Quote:
Original post by thecrow21
but the 'parse the whole file' thing is what I'm worrying about. I believe I just have to parse the last word typed in order for the highlighter to be fast enough, but its a bit complicated. that's why I would like to see an example first.
Well, nedit is an example of an editor that uses the inefficient way. Why not download it and see for yourself if the method is fast enough?

I guess it depends on your language's syntax. If you don't have any constructs that can span multiple lines it should be fine, otherwise you'll have to rely on complicated and/or imprecise parsing methods.
In the worst case you could always set a limit on how far back you begin the parsing. However that approach is bound to screw up the parsing of gigantic c-style comments.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.