Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » How to do semantic-based highlighting?
How to do semantic-based highlighting? [message #225713] Sat, 10 April 2004 04:55 Go to next message
Eclipse UserFriend
I'm looking for an example (or tutorial) how to do semantic-based
highlighting for a text editor. All examples I found only use a rule
based approach.

Let's assume I'd like to highlight this piece of code

class ... def ... end ... end

and I'd like to color the matching class/end pair in one color and the
matching def/end pair in another color.

I created my own ITokenScanner which is able to distinguish the "end"
tokens based on its own internal state. This works quite well, although
I need to parse the whole partition not only the the modified part.

Now I tried to partion the document into code and comment regions.
Unfortunately, now matching tokens may be part of different partitions
and my highlighting approach fails.

What's the right way to do this?


bye
--
Stefan Matthias Aust // "Zweifel sind der Ansporn des Denkens..." -U
Re: How to do semantic-based highlighting? [message #227420 is a reply to message #225713] Tue, 13 April 2004 04:56 Go to previous messageGo to next message
Eclipse UserFriend
Not a solution, but a general remark:

Depending on the complexity of your (highlighting) grammar, you will
need to reparse more or less of your document. For example, keyword
highlighting in Java only needs local information, but semantic
highlighting (different colors for static, final etc. fields) needs
information about the entire file, basically an AST, which is hard to
update incrementally.

So, depending on your grammar, updating the highlighting in sync with
typing may not be possible or fast enough - in the Java editor,
highlighting that needs an AST (mark occurences etc.) is done in a
background thread.

-tom

Stefan Matthias Aust wrote:
> I'm looking for an example (or tutorial) how to do semantic-based
> highlighting for a text editor. All examples I found only use a rule
> based approach.
>
> Let's assume I'd like to highlight this piece of code
>
> class ... def ... end ... end
>
> and I'd like to color the matching class/end pair in one color and the
> matching def/end pair in another color.
>
> I created my own ITokenScanner which is able to distinguish the "end"
> tokens based on its own internal state. This works quite well, although
> I need to parse the whole partition not only the the modified part.
>
> Now I tried to partion the document into code and comment regions.
> Unfortunately, now matching tokens may be part of different partitions
> and my highlighting approach fails.
>
> What's the right way to do this?
>
>
> bye
Re: How to do semantic-based highlighting? [message #230625 is a reply to message #227420] Sun, 18 April 2004 03:40 Go to previous message
Eclipse UserFriend
Tom Eicher wrote:

> Not a solution, but a general remark:
> [Parse whole file, use background thread]

Thanks for your answer. I was already afraid that it would be along
that lines. I'll try to understand how the Java editor does the
background reconciling and analysis then...


bye
--
Stefan Matthias Aust // "Zweifel sind der Ansporn des Denkens..." -U
Previous Topic:jboss3.2.3 and eclipse ???
Next Topic:Launching a run-time workbench with org.eclipse plugin projects opened
Goto Forum:
  


Current Time: Thu Jun 05 17:00:53 EDT 2025

Powered by FUDForum. Page generated in 0.02217 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top