Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » xtext add cross reference in expression(xtext add cross reference in expression)
xtext add cross reference in expression [message #1742484] Fri, 02 September 2016 11:11 Go to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
Hi,

How to use cross reference of a method implementation in an expression in xtext?
Re: xtext add cross reference in expression [message #1742490 is a reply to message #1742484] Fri, 02 September 2016 11:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
What is your actual question. Please explain

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: xtext add cross reference in expression [message #1742495 is a reply to message #1742490] Fri, 02 September 2016 12:02 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
Hi,

I have to cross reference the methods using in expressions.

I have my grammar like :

Call: 'call' procRef=[Proc] callExp=CompleteExpression?;

Proc: ('string'|'double')? 'proc' name=ID procExp=CompleteExpression?;

Which works fine for

call test();

proc test()
{
}

But I want to cross reference the proc when call used in expression like abc = test();

For this I am using grammar like

Assignment: name=('math')? (precision=Precision)? (assignExp+=Expression) (=>'=' procRef=[Proc] assignExp+=Expression);

But no luck. If I make procRef optional in the grammar, cross reference is not working at all.

Re: xtext add cross reference in expression [message #1742496 is a reply to message #1742495] Fri, 02 September 2016 12:07 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Please try this with a hello world grammar

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: xtext add cross reference in expression [message #1742502 is a reply to message #1742496] Fri, 02 September 2016 13:03 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
Yes I tried. The result is same.
Re: xtext add cross reference in expression [message #1742504 is a reply to message #1742502] Fri, 02 September 2016 13:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Please share that minimal example.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: xtext add cross reference in expression [message #1742506 is a reply to message #1742504] Fri, 02 September 2016 13:25 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member

Call: 'call' procRef=[Proc] callExp=CompleteExpression?;

Proc: ('string'|'double')? 'proc' name=ID procExp=CompleteExpression?;

OpenAssignment: args+=Assignment ','?;

Assignment: name=('math')? (precision=Precision)? (assignExp+=Expression) (=>'=' assignExp+=Expression);

Precision: (width=NUMBER)|((width=NUMBER)?'.'(decimal_places=NUMBER));

ArrayDecl : {ArrayDecl} ('[' ']') | ('[' size=CompleteExpression ']');

Parenthesis : {Parenthesis} ('(' ')') | ('(' size=CompleteExpression ')');

Initialize : {Initialize} ('{' '}')|('{' args=CompleteExpression '}');

Expression:
LogicalOr
;
LogicalOr returns Expression:
BitwiseOr ({LogicalOr.left=current} '||' right=BitwiseOr)*
;
BitwiseOr returns Expression:
LogicalAnd ({BitwiseOr.left=current} '|' right=LogicalAnd)*
;
LogicalAnd returns Expression:
BitwiseAnd ({LogicalAnd.left=current} '&&' right=BitwiseAnd)*
;
BitwiseAnd returns Expression:
Equivalency ({BitwiseAnd.left=current} '&' right=Equivalency)*
;
Equivalency returns Expression:
Relational ({Equivalency.left=current} ('=='|'!=') right=Relational)*
;
Relational returns Expression:
PlusMinus ({Relational.left=current} ('>='|'<='|'>'|'<') right=PlusMinus)*
;
PlusMinus returns Expression:
DivMult ({PlusMinus.left=current} ('+'|'-') right=DivMult)*
//DivMult | ({PlusMinus} ('+'|'-') expr=DivMult)
;
DivMult returns Expression:
LogicalNot ({DivMult.left=current} ('/'|'*') right=LogicalNot)*
;
LogicalNot returns Expression:
//OnesComplement ({LogicalNot.left=current} ('!') right=LogicalNot)*
OnesComplement | ({LogicalNot} ('!') expr=OnesComplement)
;
OnesComplement returns Expression:
Exponentiation ({OnesComplement.left=current} ('~') right=Exponentiation)*
;
Exponentiation returns Expression:
ColonOperator ({Exponentialtion.left=current} '^' right=ColonOperator)*
;
ColonOperator returns Expression:
PercentOperator | ({ColonOperator} (':'('+')?) expr=PercentOperator)
;
PercentOperator returns Expression:
ArrowExpression | ({PercentOperator} ('%'|'%t'|'%.'|'%:') expr=ArrowExpression)
;
ArrowExpression returns Expression:
Concatenation ({ArrowExpression.left=current} '->' right=Concatenation)*
;
Concatenation returns Expression:
Primary ({Concatenation.left=current} '##' right=Primary)*
;
Primary returns Expression: {Expression}
('+'|'-')? name=NUMBER | name=STRING | name=ID (ArrayDecl=ArrayDecl? & Parenthesis=Parenthesis?) |
ArrayDecl=ArrayDecl | Parenthesis=Parenthesis | Initialize=Initialize | LibraryFunc=LibraryFunc
;
GSD returns Expression: name=ID {GSD.left=current} ('[' occurence=(NUMBER|STRING) ']')?('(' m=NUMBER (',' (n=NUMBER))? ')')? '->' right=ID;

CompleteExpression:
CompleteExpression+=Expression (','? CompleteExpression+=Expression)*
;

terminal DBMS: ('DBMS'|'Dbms'|'dbms') (('\\'((' '|'\t')* '\r'? '\n')) | !('\n' | '\r'))*;

terminal ID : ((':'('+')?)?|('+'|'-')?)('a'..'z'|'A'..'Z'|'$'|'.'|'@'|'_')('a'..'z'|'A'..'Z'|'$'|'.'|'0'..'9'|'@'|'*'|'_'|'!')*;

terminal STRING : '"' ( '\\'('"'|('\r'? '\n')) | !('\n'|'"') )* '"' |
"'" ( '\\'("'"|('\r'? '\n')) | !('\n'|"'") )* "'";

terminal SL_COMMENT: '//' !('\n' | '\r')*;

terminal HASH_COMMENT : ('#'('\r'? '\n')?) | ('#' !('#'|'\n'|'\r')+ ('\r'? '\n')?) | (('#''#''#') !('\n'|'\r')* ('\r'? '\n')?);

terminal WS : (' '|'\t'| ('\\'((' '|'\t')* '\r'? '\n')))+;

terminal NL : ('\r'? '\n')+;

terminal NUMBER: (OCTAL|FLOAT|INT|BINARY|HEX);

terminal OCTAL returns ecore::EInt: ('0') ('0'..'7')+;

terminal FLOAT returns ecore::EFloat: ('0'..'9' ('0'..'9')*) '.' ('0'..'9')*;

terminal INT returns ecore::EInt: '0'..'9' ('0'..'9')*;

terminal RANGE: '0'..'9' '..' ('0'..'9')*;

terminal BINARY returns ecore::EInt: ('0b'|'0B') ('0'|'1')+;

terminal HEX returns ecore::EInt:('0x'|'0X')('0'..'9'|'a'..'f'|'A'..'F')+;

[Updated on: Fri, 02 September 2016 13:26]

Report message to a moderator

Re: xtext add cross reference in expression [message #1742507 is a reply to message #1742506] Fri, 02 September 2016 13:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Sry that grammar is too big to give any support

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: xtext add cross reference in expression [message #1742701 is a reply to message #1742507] Tue, 06 September 2016 16:58 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
This is the minimal grammar to reproduce the problem.
Re: xtext add cross reference in expression [message #1742703 is a reply to message #1742701] Tue, 06 September 2016 17:01 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
it is not.

i e.g. do not understand why BitwiseAnd is in the "not minimal" grammar


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: xtext add cross reference in expression [message #1742757 is a reply to message #1742703] Wed, 07 September 2016 13:29 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
Oh Ok.

Is it fine?

Call: 'call' procRef=[Proc] callExp=Expression?;

Proc: ('string'|'double')? 'proc' name=ID procExp=Expression?;

OpenAssignment: args+=Assignment;

Assignment: name=('math')? (precision=Precision)? (assignExp+=Expression);

Precision: (width=NUMBER)|((width=NUMBER)?'.'(decimal_places=NUMBER));

ArrayDecl : {ArrayDecl} ('[' ']');

Parenthesis : {Parenthesis} ('(' ')');

Expression:
Equivalency
;
Equivalency returns Expression:
Primary ({Equivalency.left=current} ('=='|'!='|'=') right=Primary)*
;
Primary returns Expression: {Expression}
('+'|'-')? name=NUMBER | name=STRING | name=ID (ArrayDecl=ArrayDecl? & Parenthesis=Parenthesis?) |
ArrayDecl=ArrayDecl | Parenthesis=Parenthesis
;
Re: xtext add cross reference in expression [message #1742760 is a reply to message #1742757] Wed, 07 September 2016 13:35 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
My problem is I don't want to show warning if it not find cross reference in expression.

index.php/fa/26986/0/
  • Attachment: procref.png
    (Size: 5.98KB, Downloaded 278 times)
Re: xtext add cross reference in expression [message #1742762 is a reply to message #1742757] Wed, 07 September 2016 13:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
yes although the definition of number is missing. and a rule that builds the model file.

if i improvise like
Model:
(elements+=Call | elements+=Proc | elements+=OpenAssignment)+
;


i get a lot of warning regarding ambiguity.


so thus i need

(a) a small grammar
(b) a complete grammar
(c) a test model


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: xtext add cross reference in expression [message #1742763 is a reply to message #1742762] Wed, 07 September 2016 13:39 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
and about the warning or whatever: i already told you what to do

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: xtext add cross reference in expression [message #1742765 is a reply to message #1742763] Wed, 07 September 2016 13:44 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
I extended LinkingDiagnosticMessageProvider for warningmessage but I don't understand how to get type of rule at that particular context.

Can I get the complete text of that context?

[Updated on: Wed, 07 September 2016 13:46]

Report message to a moderator

Re: xtext add cross reference in expression [message #1742769 is a reply to message #1742765] Wed, 07 September 2016 13:51 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
see other question you asked

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Bidirectional imports
Next Topic:Confusion about terminals
Goto Forum:
  


Current Time: Thu Mar 28 20:31:40 GMT 2024

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

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

Back to the top