[Lazarus] Regex and Syntax Highlighting

Graeme Geldenhuys graemeg.lists at gmail.com
Wed May 26 10:37:20 CEST 2010


On 25 May 2010 20:23, Marco van de Voort wrote:
>
> Standard regex can't deal with nested structures like nesting of comments.

OK. Do you know of some complex code maybe included in Lazarus or FPC
that I could use as sample code to test?


> Since you already identified several editors with support for it, a quick
> test to see if it can fully parse such construct should give more comfort.

I installed jEdit yesterday. It supports a mammoth 177 different
syntax highlighter styles for all types of source code, text files
like xml/html/css, config files etc. They also use a combination of
regex and various code rules.

Interesting thing is that for all the different syntax styles they map
the colors back to a handful of hard-coded color keywords. eg:
KEYWORD1, KEYWORD2, OPERATOR, LITERAL1 etc. The editor component then
uses those color keywords to syntax highlight the text being viewed.
Attached is an example of such a color setup. For the Object Pascal
syntax they map for example Keywords to KEYWORD1
, Directives to KEYWORD2 etc. This this gives me a nice idea of how to
tie the syntax definition rules back into the editor component.

As for nested syntax etc.. jEdit handles LaTeX very well, and if you
ever tried to write a latex parser, you would know that LaTeX can be
very hard to work with. Yet jEdit managed to do it damn well - though
it's syntax rules was a lot more complex than most other language
(which was to be expected), but it did handle things like
\begin{verbatim} .... \end{verbatim} correctly and ignore highlighting
whatever syntax came between those tags.

Anyway, it seems like I am starting to collect some nice ideas and
getting more source code to look at to draw ideas from. Still no idea
how they execute the regex statements against the text, but hopefully
looking at the source code from jEdit, gEdit etc will reveal some
clues.

-- 
Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: jEdit_Syntax_Highlighting.png
Type: image/png
Size: 19536 bytes
Desc: not available
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20100526/83acf315/attachment-0004.png>


More information about the Lazarus mailing list