How to enable mark occurrences [message #729621] |
Mon, 26 September 2011 16:29 |
Wade Cooper 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 #730378 is a reply to message #729621] |
Wed, 28 September 2011 09:27 |
Jan Koehnlein Messages: 760 Registered: July 2009 Location: Hamburg |
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
---
Get professional support from the Xtext committers at www.typefox.io
|
|
|
Re: How to enable mark occurrences [message #730503 is a reply to message #730378] |
Wed, 28 September 2011 14:25 |
Wade Cooper 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 |
|
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
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
[Updated on: Wed, 28 September 2011 14:32] Report message to a moderator
|
|
|
|
Re: How to enable mark occurrences [message #730539 is a reply to message #730533] |
Wed, 28 September 2011 15:17 |
|
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
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04560 seconds