Xtext content assist - [message #23834] |
Fri, 05 December 2008 11:22  |
Eclipse User |
|
|
|
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 #23915 is a reply to message #23834] |
Sat, 06 December 2008 15:28   |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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 #24204 is a reply to message #23834] |
Thu, 11 December 2008 07:25  |
Eclipse User |
|
|
|
(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.
|
|
|
Powered by
FUDForum. Page generated in 0.04323 seconds