Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to enable mark occurrences (How to enable mark occurrences)
How to enable mark occurrences [message #729621] Mon, 26 September 2011 16:29 Go to next message
Wade Cooper is currently offline Wade CooperFriend
Messages: 9
Registered: February 2011
Junior Member
How do you enable the mark occurrences feature in Xtext 2.0? I did a search for mark occurrences in the documentation, but didn't have any hits, and searching the forum or online turned up limited information.

Should it work on any text string that is identical in a language's editor, or is there a specific syntax in the grammar .xtext file needed to make it work (e.g. all variables need be declared as name=ID?)?

In my language i'd like any string that is the same (even that represented by the terminal STRING in the grammar file) to be highlighted via the mark occurrences feature, but nothing else highlights when I select text with repeats. For example, here is a simple grammar case where I have two sections where there can be any string text in each section, and I want any text that is the same in either section to be highlighted with mark occurrences:



Model:
(elements+=Type)*;

Type:
SECTION1 |
SECTION2;

SECTION1:
name='SECTION1'
(statement+=Statement)*;

SECTION2:
name='SECTION2'
(statement+=Statement)*;

Statement:
STRING |
ID |
INT ;


Generating this grammar, launching the plugin, and making a file with the extension, I can create the two sections and put whatever text I want in there, but if I have any of the same text in the two different sections, I cannot select text in one and have it highlighted in the other.

Any suggestions on how to get the mark occurrences enabled would be much appreciated.
Re: How to enable mark occurrences [message #729638 is a reply to message #729621] Mon, 26 September 2011 17:02 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6550
Registered: July 2009
Senior Member
Hi,

isn't this a feature for "cross references". at least a look at the default impl DefaultOccurrenceComputer indicates that.

~Christian
Re: How to enable mark occurrences [message #730026 is a reply to message #729638] Tue, 27 September 2011 14:14 Go to previous messageGo to next message
Wade Cooper is currently offline Wade CooperFriend
Messages: 9
Registered: February 2011
Junior Member
Hi Christian,

Thanks for the suggestion.

Do you have a simple example for how to use cross references to achieve the mark occurrences (grammar, implementations I need to use?)? I played around a little with the grammar file using the example in the xtext documentation, and looked at the DefaultOccurrenceComputer, but since i'm new to xtext and dsl's, i'm not sure how to proceed with using cross references.


Re: How to enable mark occurrences [message #730039 is a reply to message #730026] Tue, 27 September 2011 14:17 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6550
Registered: July 2009
Senior Member
Hi cross references are a std. feature in Xtext. Reading the docs and
doing the tutorial should give you the chance to come across them.
Regards Christian
Re: How to enable mark occurrences [message #730378 is a reply to message #729621] Wed, 28 September 2011 09:27 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 658
Registered: July 2009
Senior Member
There is a button in the action bar of your editor...

Did I miss the question?

Am 26.09.11 18:29, schrieb Wade Cooper:
> How do you enable the mark occurrences feature in Xtext 2.0? I did a
> search for mark occurrences in the documentation, but didn't have any
> hits, and searching the forum or online turned up limited information.
>
> Should it work on any text string that is identical in a language's
> editor, or is there a specific syntax in the grammar .xtext file needed
> to make it work (e.g. all variables need be declared as name=ID?)?
> In my language i'd like any string that is the same (even that
> represented by the terminal STRING in the grammar file) to be
> highlighted via the mark occurrences feature, but nothing else
> highlights when I select text with repeats. For example, here is a
> simple grammar case where I have two sections where there can be any
> string text in each section, and I want any text that is the same in
> either section to be highlighted with mark occurrences:
>
>
> Model:
> (elements+=Type)*;
>
> Type:
> SECTION1 |
> SECTION2;
> SECTION1:
> name='SECTION1'
> (statement+=Statement)*;
>
> SECTION2:
> name='SECTION2'
> (statement+=Statement)*;
>
> Statement:
> STRING |
> ID |
> INT ;
>
>
> Generating this grammar, launching the plugin, and making a file with
> the extension, I can create the two sections and put whatever text I
> want in there, but if I have any of the same text in the two different
> sections, I cannot select text in one and have it highlighted in the other.
> Any suggestions on how to get the mark occurrences enabled would be much
> appreciated.


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Re: How to enable mark occurrences [message #730503 is a reply to message #730378] Wed, 28 September 2011 14:25 Go to previous messageGo to next message
Wade Cooper is currently offline Wade CooperFriend
Messages: 9
Registered: February 2011
Junior Member
Jan,

Thanks for the reply. Yes, I know about the button (first thing i tried when upgrading to xText 2.0), and use mark occurrences quite a bit in other tools. My problem is I don't know how to make it work correctly with my xText grammar file.

Despite following along some of the online tutorials and xtext documentation, I haven't put it all together to get mark occurrences working. If I manually toggle on the mark occurrences button, it does not work as i'd like, and I can see different behaviors depending on how I write the grammar file (e.g., sometimes nothing will be highlighted, sometimes the grammar model entity that the term I select is nested within will highlight). Christian's suggestion that the feature is related to cross references has set me to more reading but no luck yet (e.g., when I try to implement a cross reference in the grammar, I get an error in the editor when launched "Couldn't resolve reference to Variable 'x'"). I've been trying to implement something simple just to see how the grammar works, e.g. for the text:

Section1
double x
double y

Section2
x=1+1
y=2*2


But my attempts at the grammar have not been successful, e.g.:


Model:
(elements+=Type)*;

Type:
SECTION1 |
SECTION2;

SECTION1:
name='Section1' (varDecl+=VarDeclare)*;

SECTION2:
name='Section2' (op+=Operation)*;

VarDeclare:
'double' Variable;

Variable:
name=ID;

Operation:
name=[Variable] '=' (INT | MathOps)*;

terminal MathOps:
('*'|'+'|'-'|'/');

Here I get the error in the text editor "Couldn't resolve reference to Variable 'x'". Anyone have any thoughts?
Re: How to enable mark occurrences [message #730506 is a reply to message #730503] Wed, 28 September 2011 14:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6550
Registered: July 2009
Senior Member
Hi,

name='Section1' gives the vars the FQN Section1.y and Section1.y so change the grammar or provide a custom iqualifiednameprovider that fixes this

Model:
(elements+=Type)*;

Type:
SECTION1 |
SECTION2; 

SECTION1:
{SECTION1}'Section1' (varDecl+=VarDeclare)*;

SECTION2:
{SECTION2}'Section2' (op+=Operation)*;

VarDeclare:
'double' var=Variable;

Variable:
name=ID;

Operation:
name=[Variable] '=' (INT | MathOps)*;

terminal MathOps:
('*'|'+'|'-'|'/');


~Christian

[Updated on: Wed, 28 September 2011 14:32]

Report message to a moderator

Re: How to enable mark occurrences [message #730533 is a reply to message #730506] Wed, 28 September 2011 15:09 Go to previous messageGo to next message
Wade Cooper is currently offline Wade CooperFriend
Messages: 9
Registered: February 2011
Junior Member
Thanks Christian, that worked.

Regarding multiple cross references within an entity, if I wanted to type the text:

x=y+1

where there are two cross references within a single line, how would I construct the grammar to reference both x and y? Any combination i've tried has given an error or warning in the grammar file. E.g.,

Operation:
name=[Variable] '=' (INT | MathOps | name=[Variable])*;

Throws a warning "this assignment will possible override the assignment of feature 'name'"

Thanks.
Re: How to enable mark occurrences [message #730539 is a reply to message #730533] Wed, 28 September 2011 15:17 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6550
Registered: July 2009
Senior Member
Hi,

please note: in xtext you do not only describe the concrete syntax of your dsl but the construction and the structure of the ast as well.
so if you assign the name more then one it will of course be overriden.
a search for xtext and expressions will help you to build "clean" expressions.
here the short version

Operation:
name=[Variable] '=' expression=Addition;

Addition returns Expression:
 Multiplication ({Addition.left=current} op=('+'|'-') right=Multiplication)*;

Multiplication returns Expression:
 Primary ({Multiplication.left=current} op=('*'|'/') right=Primary)*;

Primary returns Expression:
 NumberLiteral |
 VariableReference |
 '(' Addition ')';

VariableReference:
	ref=[Variable]
;

NumberLiteral: value=INT;


~Christian
Re: How to enable mark occurrences [message #730545 is a reply to message #730539] Wed, 28 September 2011 15:31 Go to previous messageGo to next message
Wade Cooper is currently offline Wade CooperFriend
Messages: 9
Registered: February 2011
Junior Member
Thanks Christian,

I appreciate your insights and help. A quick search turned up some useful posts indeed! Much to learn...

Re: How to enable mark occurrences [message #754695 is a reply to message #730545] Thu, 03 November 2011 21:32 Go to previous messageGo to next message
Andrey Mising name is currently offline Andrey Mising nameFriend
Messages: 26
Registered: September 2011
Junior Member
Hi Wade,

can you please give an example of your implementation of "mark occurrences"?

Thank you,
Andrey
Re: How to enable mark occurrences [message #754696 is a reply to message #754695] Thu, 03 November 2011 21:40 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6550
Registered: July 2009
Senior Member
Hi,

i guess Wade did not implement anything. he just uses cross refs in the grammar and pressed the toggle mark occurrences button in the editor

~Christian
Re: How to enable mark occurrences [message #754697 is a reply to message #754696] Thu, 03 November 2011 21:46 Go to previous messageGo to next message
Andrey Mising name is currently offline Andrey Mising nameFriend
Messages: 26
Registered: September 2011
Junior Member
Hi Christian,

thank you for the answer. Is it possible to make the "mark occurrences" as it is in java (double click and it shows all variables in the code)?

Regards,
Andrey
Re: How to enable mark occurrences [message #754699 is a reply to message #754697] Thu, 03 November 2011 21:54 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6550
Registered: July 2009
Senior Member
Hi,

it works out of the box. so you do not have to do anything but hit the button.
and then SINGLE click Wink

~Christian
Re: How to enable mark occurrences [message #754702 is a reply to message #754699] Thu, 03 November 2011 22:00 Go to previous messageGo to next message
Andrey Mising name is currently offline Andrey Mising nameFriend
Messages: 26
Registered: September 2011
Junior Member
Sorry, Christian

perhaps i don't understand something. I took the example of grammar from Wade and i write the following code:

Section1
double myvar
double myvar2

Section2

myvar = 12 + 23
myvar2 = myvar + 4

so if i choose the first "myvar", chech "Occurrences" and push "Next Annotation" it should jump to the next "myvar", is that right?

Thank you,
Andrey
Re: How to enable mark occurrences [message #754704 is a reply to message #754702] Thu, 03 November 2011 22:06 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6550
Registered: July 2009
Senior Member
Hi,

isnt the next previous annotation button for annotations e.g. error markers

~Christian
Re: How to enable mark occurrences [message #754705 is a reply to message #754704] Thu, 03 November 2011 22:13 Go to previous messageGo to next message
Andrey Mising name is currently offline Andrey Mising nameFriend
Messages: 26
Registered: September 2011
Junior Member
Hi Christian,

sorry, stupid of me Smile. Found it, thank you.

Regargs,
Andrey
Re: How to enable mark occurrences [message #792814 is a reply to message #729621] Tue, 07 February 2012 12:48 Go to previous messageGo to next message
Jorn Hertsig is currently offline Jorn HertsigFriend
Messages: 3
Registered: February 2012
Junior Member
Hi,

I'm trying to get my xtext editor to mark other uses for certain items. I've managed to get the QualifiedNameProvide to return the correct qualified name, but it still isn't marking occurrences (with the button turned on, of course). The current item is highlighted, but other items with the same QualifiedName are not.
I'll try to post a piece of my grammar but it's a bit too large to post in its entirety Smile

Thanks for the help,
Jorn
Re: How to enable mark occurrences [message #792858 is a reply to message #792814] Tue, 07 February 2012 13:58 Go to previous message
Jorn Hertsig is currently offline Jorn HertsigFriend
Messages: 3
Registered: February 2012
Junior Member
I've managed to get it to work using the
name=[ReferredType|Rule]
syntax. However, since I can't get at items imported from other files, is it possible to not give an error if the referred item isn't found, and simply not hilight the referred item?

[Updated on: Tue, 07 February 2012 13:58]

Report message to a moderator

Previous Topic:Debug grammar generation gives error but seems to work
Next Topic:XText parsing expressions with non-binary AST structure
Goto Forum:
  


Current Time: Sun Dec 21 03:21:11 GMT 2014

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

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