Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Matching start/end tags(Something like bracket matching)
Matching start/end tags [message #546157] Sun, 11 July 2010 21:28 Go to next message
Timotei Mising name is currently offline Timotei Mising nameFriend
Messages: 89
Registered: March 2010
Member
Hi!

I have the following parts of my grammar:

WMLTag:
start = WMLStartTag
( (Ttags += WMLTag)
| (Tkeys += WMLKey)
| (Tmacros += WMLMacro)
)*
end = WMLEndTag
;
WMLStartTag:
'[' tagname = ID ']'
;
WMLEndTag:
'[/' tagname = ID ']'
;

Now, I want to "highlight" the start/end tags. So when with the cursor is on startTag/EndTag, both of the tags to be highlighted. By highlighting I mean, get the: "" and "[/mytag]", be shaded/backgrounded/have their caracteristics modified. Maybe if I can "surround" them with a box like it's currently with bracket matching?

The highlighting will be easy done, with a HighlightingConfiguration (that is already in place).

The only question is, how can I get the current XtextEditor - so I can get current cursor's location/offset ?
Can this be done, "globally"? Or I need an instance of something before?

Currently I have this method that does the highlighting, can I use that resource to get the XTextEditor? :

public void provideHighlightingFor(XtextResource resource, IHighlightedPositionAcceptor acceptor)

Or, is there anyother method of highlighting the start/end tags, without this method of highlighting?

Thanks,
Timotei
Re: Matching start/end tags [message #546189 is a reply to message #546157] Mon, 12 July 2010 05:39 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

start digging at DefaultBracketMatcher (1.0.0, there is no framework
support for bracket matching in 0.7.2). The defautl implementation
allows you to configure "static" pairs of matching elements, which is
not what you want. But I guess, you could well override
computeMatchingRegion in order to highlight the matching tag.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Matching start/end tags [message #546219 is a reply to message #546189] Mon, 12 July 2010 08:23 Go to previous messageGo to next message
Timotei Mising name is currently offline Timotei Mising nameFriend
Messages: 89
Registered: March 2010
Member
Well, it doesn't work with "multiple" characters.
I tested this:
List<Pair<Keyword, Keyword>> pairs2 = grammarAccess.findKeywordPairs("[game]", "[/game]");

...

And when on [game] it doesn't work. Do I need to ... create anything else??

Timo

[Updated on: Mon, 12 July 2010 08:28]

Report message to a moderator

Re: Matching start/end tags [message #546226 is a reply to message #546219] Mon, 12 July 2010 08:35 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

> List<Pair<Keyword, Keyword>> pairs2 = grammarAccess.findKeywordPairs("",
> "[/portrait]");
Of course this will not work as your tags are not defined statically in
the grammar. There is no keyword [/portrait] in your grammar. This is
why I said, that you won't be able to use the default implementation (of
configuring the bracket matcher).

You will have to find the matches yourself and computeMatchingRegion is
a possible entry point, as there you get the Model and the current
offset. You check if there is a tag at that offset, search the matching
tag in your model, and create the region to highlgiht.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Matching start/end tags [message #546238 is a reply to message #546226] Mon, 12 July 2010 09:23 Go to previous messageGo to next message
Timotei Mising name is currently offline Timotei Mising nameFriend
Messages: 89
Registered: March 2010
Member
Wow. That was fast.

Ok. I'll try that and come back with results.

Timotei
Re: Matching start/end tags [message #546387 is a reply to message #546157] Mon, 12 July 2010 15:38 Go to previous messageGo to next message
Timotei Mising name is currently offline Timotei Mising nameFriend
Messages: 89
Registered: March 2010
Member
Hi!
I tried to "highlight" a region of more than 1 character. It seems It can't highlight (border) only 1 character. Is any way I can make it border more than 1 character? or that comes from the editor/ecplise. It's fine if I can get a starting point.

Thanks,
Timotei

[Updated on: Tue, 13 July 2010 14:23]

Report message to a moderator

Re: Matching start/end tags [message #546671 is a reply to message #546157] Tue, 13 July 2010 17:29 Go to previous messageGo to next message
Timotei Mising name is currently offline Timotei Mising nameFriend
Messages: 89
Registered: March 2010
Member
Hi again!

I just succesfully created the matching part. Right Now It seems I'm stuck at painting/bordering more than 1 character. That seems an jface issue.

Is there any way I can get the xtext editor from that: XtextResource state ?? Maybe I can paint it for myself if I can get access to the editor.

Thanks.
Re: Matching start/end tags [message #546685 is a reply to message #546671] Tue, 13 July 2010 18:20 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

there is at least the naive way of comparing the model's URI with the information you can obtain from the open editors about their inputs.

Alex
Re: Matching start/end tags [message #546845 is a reply to message #546157] Wed, 14 July 2010 12:40 Go to previous messageGo to next message
Timotei Mising name is currently offline Timotei Mising nameFriend
Messages: 89
Registered: March 2010
Member
I found it: it's in "EditorUtils.getActiveXtextEditor()"

Thanks for your help;)
Re: Matching start/end tags [message #697418 is a reply to message #546845] Sat, 16 July 2011 17:38 Go to previous message
Timotei Mising name is currently offline Timotei Mising nameFriend
Messages: 89
Registered: March 2010
Member
Hi!

I've reworked a bit my current way of highlighting the end/start. However, there is a weird problem happening.

If I click on a tag, it colors it. If I click on another tag, it might color that too (note, there should be just *1* colored at a time). This is not happening all the time.

What I use: I implement the DefaultCharacterPairMatcher, and I've implemented a separate method along with the default, that does the logic. When a tag is found in the tree, it adds a new adapter to it. This is taken in account in the ISemanticHighlightinCalculator.

I've checked manually to see what's happening, and it seems the it remains colored some of the file. Is there any way of getting the editor to refresh the *entire* (maybe just the visible) section ? I can have access just to the XtextResource, as it is seen in the following code:

http://pastebin.com/kWH4JAvz

LE: looking deeper in it, it seems that the semantic highlighter is called non-stop (making the processor 100%). If I remove the modify thingy, then it isn't called all the time. What could be the problem? Sad

Thanks,
Timo

[Updated on: Sat, 16 July 2011 17:50]

Report message to a moderator

Previous Topic:xtext models as ecore
Next Topic:handle affected file names in case of rename refactoring
Goto Forum:
  


Current Time: Thu Apr 25 23:10:48 GMT 2024

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

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

Back to the top