Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » What's wrong with this cross-reference(I'm new to Xtext and ran into a problem)
What's wrong with this cross-reference [message #988709] Sat, 01 December 2012 18:51 Go to next message
Julian Dax is currently offline Julian DaxFriend
Messages: 3
Registered: December 2012
Junior Member
Hi,

I'm writing a DSL for a state machine. In order to keep the number of events from growing to rapidly my events have parameters. The following example shows how I'd like my DSL to work:
event LocationUpdate {
	lon : float
	lat : float
}

state s1 {
	LocationUpdate: lon = 20 -> s2
}

state s2 {
	LocationUpdate -> s1
}





Unfortunately I get the following error: "Description Resource Path Location Type Couldn't resolve reference to ParemeterDefinition 'lon'."

The problem is the cross-reference in the "Condition" rule of my grammar (I think), but I don't know how to fix it. Here is the whole thing:

grammar de.unisiegen.StatesLanguage with org.eclipse.xtext.common.Terminals

generate statesLanguage "http://www.eclipse.org/StatesLanguage"

StatesList :
    states += State* &
    actions += Action* &
    events += Event*
;

State:
    ('state'|'startstate') name = ID '{'
        actions += ActionInvocation* &
        transitions += StateTransition+ 
    '}'
;

StateTransition:
    EventInvocation '->' state = [State]
;

ActionInvocation:
    (percent = Number '%')? action = [Action] val += Value*
;
Action:
    'action' name = ID '{'
        params+= ParemeterDefinition*
    '}'
;

Event:
    'event' name = ID '{'
        params += ParemeterDefinition*
    '}'
;


ParemeterDefinition:
    name = ID ':' type = DATATYPE 
;

EventInvocation:
    eventName = [Event] (':' condition = Condition  (logicalOperators+= LOGICALBINARYOPERATOR conditions+= Condition)* )?
;

Condition:
    parameter = [ParemeterDefinition] 
    eqoperator = EQUALITYOPERATOR 
    val = Value 
;

Value:
    BOOL | STRING | Number 
;
Number:
    FLOAT | INT
;

enum DATATYPE:
    int|float|string|bool
;

terminal EQUALITYOPERATOR:
    "=" | ">" | "<" | ">=" | "<=" | "!=" 
;

enum LOGICALBINARYOPERATOR:
    and | or
;

terminal BOOL:
    "true"|"false"
;

terminal FLOAT:
    INT'.'INT
;



If you can spot anything else, which seems odd or wrong to you besides the problem I described, feel free to tell me. I've never written a DSL before and take any advice I can get.

Thanks
Re: What's wrong with this cross-reference [message #988722 is a reply to message #988709] Sun, 02 December 2012 03:41 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
Guessing here...
Think it is because ID simple names are used everywhere, but I think the
"lon" item will get a qualified name of "LocationUpdate.lon" in the index.

Not exactly sure what you need to do; if you want to use the short name
"lon" you need to do something with scoping to make it visible at the
point where you are trying to reference it. Or you need to use FQN and
enter the reference as LocationUpdate.lon intead of just lon.

Hope that helps as a starting point for further reading.

- henrik

On 2012-02-12 2:25, Julian Dax wrote:
> Hi,
>
> I'm writing a DSL for a state machine. In order to keep the number of
> events from growing to rapidly my events have parameters. The following
> example shows how I'd like my DSL to work:
>
> event LocationUpdate {
> lon : float
> lat : float
> }
>
> state s1 {
> LocationUpdate: lon = 20 -> s2
> }
>
> state s2 {
> LocationUpdate -> s1
> }
>
>
>
>
>
> Unfortunately I get the following error: "Description Resource
> Path Location Type Couldn't resolve reference to
> ParemeterDefinition 'lon'."
>
> The problem is the cross-reference in the "Condition" rule of my grammar
> (I think), but I don't know how to fix it. Here is the whole thing:
>
>
> grammar de.unisiegen.StatesLanguage with org.eclipse.xtext.common.Terminals
>
> generate statesLanguage "http://www.eclipse.org/StatesLanguage"
>
> StatesList :
> states += State* &
> actions += Action* &
> events += Event*
> ;
>
> State:
> ('state'|'startstate') name = ID '{'
> actions += ActionInvocation* &
> transitions += StateTransition+ '}'
> ;
>
> StateTransition:
> EventInvocation '->' state = [State]
> ;
>
> ActionInvocation:
> (percent = Number '%')? action = [Action] val += Value*
> ;
> Action:
> 'action' name = ID '{'
> params+= ParemeterDefinition*
> '}'
> ;
>
> Event:
> 'event' name = ID '{'
> params += ParemeterDefinition*
> '}'
> ;
>
>
> ParemeterDefinition:
> name = ID ':' type = DATATYPE ;
>
> EventInvocation:
> eventName = [Event] (':' condition = Condition (logicalOperators+=
> LOGICALBINARYOPERATOR conditions+= Condition)* )?
> ;
>
> Condition:
> parameter = [ParemeterDefinition] eqoperator = EQUALITYOPERATOR
> val = Value ;
>
> Value:
> BOOL | STRING | Number ;
> Number:
> FLOAT | INT
> ;
>
> enum DATATYPE:
> int|float|string|bool
> ;
>
> terminal EQUALITYOPERATOR:
> "=" | ">" | "<" | ">=" | "<=" | "!=" ;
>
> enum LOGICALBINARYOPERATOR:
> and | or
> ;
>
> terminal BOOL:
> "true"|"false"
> ;
>
> terminal FLOAT:
> INT'.'INT
> ;
>
>
>
> If you can spot anything else, which seems odd or wrong to you besides
> the problem I described, feel free to tell me. I've never written a DSL
> before and take any advice I can get.
> Thanks
Re: What's wrong with this cross-reference [message #988875 is a reply to message #988709] Mon, 03 December 2012 14:14 Go to previous messageGo to next message
Julian Dax is currently offline Julian DaxFriend
Messages: 3
Registered: December 2012
Junior Member
Thanks Henrik,
I've implemented the getScope method and now I don't get the error anymore. However autocompletion does not work. Is there anything wrong with this method or do I need to implement anything else?

public class StatesLanguageScopeProvider extends AbstractDeclarativeScopeProvider {

	@Override
	public IScope getScope(EObject context, EReference reference) {
		
		if(context.eContainer() instanceof EventInvocationImpl){
			EventInvocationImpl eventInvocation = (EventInvocationImpl) context.eContainer();
			return Scopes.scopeFor(eventInvocation.getEventName().getParams());
		}
		IScope scope = super.getScope(context, reference);
		return scope;
	}
}

[Updated on: Mon, 03 December 2012 14:36]

Report message to a moderator

Re: What's wrong with this cross-reference [message #988900 is a reply to message #988875] Mon, 03 December 2012 16:00 Go to previous message
Julian Dax is currently offline Julian DaxFriend
Messages: 3
Registered: December 2012
Junior Member
Never mind I think i found out how to to it. (using ProposalProvider)
Previous Topic:Migration from Xtext 1.0 to Xtext 2.31
Next Topic:Proposal - Adding internalization support to Xtext
Goto Forum:
  


Current Time: Mon Sep 23 18:36:57 GMT 2024

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

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

Back to the top