Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » my last problem with typing
my last problem with typing [message #626321] Wed, 22 September 2010 14:19 Go to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
Embarrassed
i cannot resolve this problem... i don't know what i need... but i searched on line and i found anything...

if someone impemented something similar to this can give me a suggestion...

i would to obtain a grammar like a java declaration method...

in my model i would to declare :

int x;
string hello="h";
...

public fun(int x , string s, string f){....}

and typing fun( ...

to receive the completion of declared variables in the correct order...i mean ...in second position receive only declared string and so on....

snippets of my grammar is made so:

Parameter: cpars=StringParameter|apras=intParameter|rpars=doubleParamet er;

StringParameter :"string" name=ID;
intParameter :"int" name=ID ;
doubleParameter :"double" name=ID ;

Argument:CArgument|AArgument|RArgument;

stringArgument:{CArgument}'string' parameter=[StringParameter] "=" value=[ecore::EString];
intArgument: {AArgument}'int' parameter=[intParameter] "=" value=[ecore::EInteger];

CALL: ref=[Operation]
('('
(arguments+=Argument)
( ',' arguments+=Argument)*
')')
;
Operation: "def Operation" name=ID
('(' (params+=Parameter (',' params+=Parameter)*)? ')' )? "{"
...
"}"
;
===========

in the scope i declared this:

public IScope scope_stringArgument_parameter(CALL c, EReference r) {

System.out.println("arg");


return Scopes.scopeFor(((Operation)c.getRef()).getParams());
}
in this way I obtain the list of parameter but i don't know how to obtain the position of the parameter that i'm declaring to provide the type to the completion....

i tried to see xbase but i'm not advanced and i don't know where to start Smile

i think someone with a lot of experience can give me some suggestions...maybe...
@Christian and sebastian sorry for the next request but i'm new with xtext and i developed all my grammar without problems but here i can find a solution.... be patient Very Happy

[Updated on: Wed, 22 September 2010 14:20]

Report message to a moderator

Re: my last problem with typing [message #626933 is a reply to message #626321] Wed, 22 September 2010 18:55 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
Quick (and possibly incomplete/unhelpful) answer: fire up the debugger, set a breakpoint at scope_stringArgument_parameter and try to see whether the objects which are passed to it give you any hint as to how to determine the index of the parameter (which would be the context) in its eContainer -you might have to do some casting to get access to the right methods.

In any case, you're probably better off doing this with validation since restricting the scoping causes "reference to X could not be resolved" type errors instead of something meaningful like "argument 3 must be of type ...".


Re: my last problem with typing [message #627178 is a reply to message #626321] Wed, 22 September 2010 21:55 Go to previous messageGo to next message
Benjamin Schwertfeger is currently offline Benjamin SchwertfegerFriend
Messages: 53
Registered: July 2009
Member
Hello Chuck,
I had a very similar problem in my grammar, because I needed to get a List of elements, like the dot-notation in Java. After each dot the context of the element before is relevant. Your grammar would allow to write the dots and the elements, but the context is not clear at each position. Additionally the position for scoping is not clear, because you can go back later and try to change the first reference, if all afterwards are present.

I used something like
CALL: ref=[Operation]
('('
arguments=ARGUMENTS?
')')
;

ARGUMENTS:
arguments=Argument( ',' ARGUMENTS)?
to parse the arguments with the scope provider.

If you like to go on with the list, you could take a look at the ProposalProvider to get the current position.

Hope this helps,
Benjamin
Re: my last problem with typing [message #627886 is a reply to message #626321] Thu, 23 September 2010 06:42 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

don't try to solve this problem via scoping. Rather allow any visible (this is not the same as valid) type in the scope, write validation rules and customise code completion. Why?
An error "could not resolve reference to..." is not very helpful to the user, as the type may in fact exist. Via validation you can give helpful error messages ("Type X is not allowed at this position").
In the code completion code you have easy access to the position in the list via the context.

Alex
Re: my last problem with typing [message #627993 is a reply to message #627886] Thu, 23 September 2010 08:14 Go to previous message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
interesting.... can you give me some hints on how to realize this?
many thx to all!
Previous Topic:Couldn't resolve reference to EPackage with plug-ins in different folders
Next Topic:Reusing xbase
Goto Forum:
  


Current Time: Fri Apr 19 19:42:34 GMT 2024

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

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

Back to the top