Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Xtext content assist -
Xtext content assist - [message #23834] Fri, 05 December 2008 11:22 Go to next message
Eclipse UserFriend
We are defining an expression language using Xtext M3 containing +, * and
function calls.

Expression
: left=factor ('+' right=Expression)?
;

factor returns Expression
: left=atom ('*' right=factor)?
;

atom returns Expression
: FunctionCall
| Number
;

FunctionCall
: name=ID '(' arguments+=Expression (',' arguments+=Expression)* ')'
;

Number : ...


We would like to customize content assist to suggest from some set of
built-in function names.

Where do we have to implement the customization? The documentation
describes that a method completeFunctionCallName(RuleCall, EObject,
String, IDocument, int) is called. However, in our case, this method is
not called. The method ProposalProviderInvoker.caseRuleCall(RuleCall) does
not invoke our method, because calledRule.getType() is null. What could be
the reason for that?
Re: Xtext content assist - [message #23874 is a reply to message #23834] Sat, 06 December 2008 15:21 Go to previous messageGo to next message
Eclipse UserFriend
hi,

i have tested you grammar and there seems to be an issue of content assist
in combination with the 'defaultRule' assumption ('Expression' in your
example instead of 'FunctionCall').

Could you pls declare the 'FunctionCall' rule as the first rule in your
grammar and reexamine the results until we have fixed this issue.

thx
michael
Re: Xtext content assist - [message #23915 is a reply to message #23834] Sat, 06 December 2008 15:28 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Sebastian.Zarnekow.gmail.com

Hello Aleksey,

this seems to be a bug. I think the following workaround might do the trick.
Please change your grammar and declare the return type for your FunctionCall
explicitly:
FunctionCall returns FunctionCall : ... ;
Furthermore I suspect the name of your method has to be "completeFunctionCall",
because you try to provide code completion for a rule with a custom return
type.

Another solution might be to override "completeFunctionCallName(Assignment
assignment, EObject model, String prefix, IDocument doc,int offset)".

I hope one of these will help - I had no chance to test them.

Sorry for inconvenience.

-Sebastian


> We are defining an expression language using Xtext M3 containing +, *
> and function calls.
>
> Expression
> : left=factor ('+' right=Expression)?
> ;
> factor returns Expression
> : left=atom ('*' right=factor)?
> ;
> atom returns Expression
> : FunctionCall
> | Number
> ;
> FunctionCall
> : name=ID '(' arguments+=Expression (',' arguments+=Expression)* ')'
> ;
> Number : ...
>
> We would like to customize content assist to suggest from some set of
> built-in function names.
>
> Where do we have to implement the customization? The documentation
> describes that a method completeFunctionCallName(RuleCall, EObject,
> String, IDocument, int) is called. However, in our case, this method
> is not called. The method
> ProposalProviderInvoker.caseRuleCall(RuleCall) does not invoke our
> method, because calledRule.getType() is null. What could be the reason
> for that?
>
Re: Xtext content assist - [message #23955 is a reply to message #23834] Sun, 07 December 2008 16:30 Go to previous messageGo to next message
Eclipse UserFriend
As an aside I'ld like to point you to the concept of "actions" we have
in TMF Xtext, which helps making your models and derived metamodels look
nice for expression like problems (i.e. normalizing left recursion).

With actions you could write your grammar like this:

Expression returns Expression:
Factor ({BinaryExpression.left=current} '+' right=Factor)*;

Factor returns Expression:
Atom ({BinaryExpression.left=current} '*' right=Atom)*;

Atom returns Expression:
FunctionCall |
Number |
'(' Expression ')';

FunctionCall returns FunctionCall :
name=ID '(' arguments+=Expression (',' arguments+=Expression)* ')';

Number :
val=INT;

I noticed that actions havn't yet been documented in the reference
documentation (http://wiki.eclipse.org/Xtext/Documentation).

So I'll explain them here briefly and update the wiki later.

An action is written like

{TypeName.feature = current}

Where current is the returnvalue of a rule.
It's initially null and get's assigned on
a) an assignment (for example in FunctionCall the instance of
FunctionCall is created on "name=ID"),
b) an unassigned rule call to another parser rule. Here the value
returned from the called rule is assigned.
c) an Action. {Foo.old=current} creates a new instance of Foo assignes
the old value of current to it'S feature 'old' and finally reassigns
current with the new instance.
In Java it would look like this:

Foo temp = new Foo();
temp.old = current;
current = temp;

Very short desription but hopefully you got it.
If not, please ask. It will definitely help in your case.

Cheers,
Sven

Aleksey schrieb:
> We are defining an expression language using Xtext M3 containing +, *
> and function calls.
>
> Expression
> : left=factor ('+' right=Expression)?
> ;
>
> factor returns Expression
> : left=atom ('*' right=factor)?
> ;
>
> atom returns Expression
> : FunctionCall
> | Number
> ;
>
> FunctionCall
> : name=ID '(' arguments+=Expression (',' arguments+=Expression)* ')'
> ;
>
> Number : ...
>
>
> We would like to customize content assist to suggest from some set of
> built-in function names.
>
> Where do we have to implement the customization? The documentation
> describes that a method completeFunctionCallName(RuleCall, EObject,
> String, IDocument, int) is called. However, in our case, this method is
> not called. The method ProposalProviderInvoker.caseRuleCall(RuleCall)
> does not invoke our method, because calledRule.getType() is null. What
> could be the reason for that?
>
>
Re: Xtext content assist - [message #24060 is a reply to message #23834] Mon, 08 December 2008 11:47 Go to previous messageGo to next message
Eclipse UserFriend
fixed in the latest version
(https://bugs.eclipse.org/bugs/show_bug.cgi?id=257940)

br
m
Re: Xtext content assist - [message #24204 is a reply to message #23834] Thu, 11 December 2008 07:25 Go to previous message
Eclipse UserFriend
(Aleksey and I are working together on that DSL)

Thank you all for your suggestions and help.

We tried to add explicit return types to all grammar rules. We tried to
re-order the grammar rules. Of course we used actions as described by
Sven. These approaches did not help - the completeFunctionCall[Name]
function is not called.

We did not try the bugfix until now - we will do the next days.
Previous Topic:how to install openarchitetureware 4.3 on ganymade 3.4
Next Topic:[TCS] TCS Version for Eclipse 3.2 (or others)?
Goto Forum:
  


Current Time: Tue Jul 15 00:24:10 EDT 2025

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

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

Back to the top