Text Highlighting Algorithms

I’m working on something I think I’ll call ‘SuperPad’ or ‘MongoPad’ (taking name ideas!). One of the features I think I’ll include in some version (It’s a long list!) is text highlighting. Does anyone know a highlighting algorithm for their favorite language?

I’m thinking a rule based system (Things higher in the list take presedence over items farther down).

If you search around for “syntax highlighting”, you will find several algorithms for various languages.

If you know Java, you can check out the implementation used in Ostermiller.Syntax from http://ostermiller.org/syntax/. Source code is available form the download link.

Thanx! (Google)

(Ok, after going through google I’m a little frustrated: it’s all language specific! does anyone know algorithms that are in psuedo code? )

[quote=“Astronouth7303”]
Thanx! (Google)

(Ok, after going through google I’m a little frustrated: it’s all language specific! does anyone know algorithms that are in psuedo code? *)
*

Pseudocode coming up:


make an array of the rules
make an array "colors" of RGB values with length equal to length of code
for each rule in the array
- for each range of strings in the code that match this rule
- - set the range of values in "colors" to the color matching the rule
- end for
end for
change the color of each character according to the colors array

When you’re done could you add the code to the repository?[/quote]

What kind of highlighting are you talking about? You mean a user can select a certain language and it would highlight text specific to that? (Presumably where a user could specify a custom highlighting scheme with custom rules?) Sounds complicated … be wary of the many exceptions. Some food for thought: ignore keywords in between quotes, bearing in mind escape characters, which in general can be a pain … ignore keywords between comments, bearing in mind that in C, anyway, you can’t nest the /**/-style (C-style) comments. And, of course, more caveats abound! I suggest you take a look at Syntax::Highlight::Perl – I can’t think of a more complicated case to come up with syntax highlihgting for, where a single symbol (possibly multiple characters) can have more context and different results for each context! I don’t know if you are familiar with perl, but if you take a gander at CPAN you’ll find a lot of useful modules that could assist in this (particularly to parse documents based on rules, not to mention that perl has some pretty powerful text handling ability … granted, that can quickly turn into text mangling ability if you aren’t careful. ;)) Also, you might want to check out emacs for general edification (if you haven’t already).

Jamie,

I think there is already a SuperPad editor.

Edit:

This site says that "Source code for SuperPad is delivered with Microsoft’s Visual C++

Oh. I did have a long list of possible names (It started out as ‘Tabbed Notepad’, but the feature list got too long for that). However, currently, it’s only framework. But when I finish the first version, I’ll send it to anyone who wants it!

I ment for a particular language. Setting up the structure isn’t hard, filling it in is.

And yes. when I make a working version, I will upload it. I’m still on Alpha 0.0.000.