Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » JvmTypeReference and XExpression error
JvmTypeReference and XExpression error [message #991465] Wed, 19 December 2012 11:00 Go to next message
Tommaso De Sica is currently offline Tommaso De SicaFriend
Messages: 131
Registered: March 2012
Location: Italy
Senior Member

I've tryed to do something like this (application of Xtext doc par. 10.5):
Variable:
	type=JvmTypeReference name=ID ';'
;

Condition:
	condition=XExpression
;

IfStatement:
	'IF''('condition=Condition')''{'
	'}'
;


but, when I write this:
        boolean v2;
	IF(v2){
	}

I receive this compile error:
Quote:
Couldn't resolve reference to JvmIdentifiableElement 'v2'.


I've also added "xbase.lib" in required plug-in.

Very thank you.
Re: JvmTypeReference and XExpression error [message #991471 is a reply to message #991465] Wed, 19 December 2012 11:22 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi

How shall base know your semantics/visibility rules

you have do do things in scoping as well. The best way to do that is
to reuse xbase concepts (if expression) or to map your construct to
something from java using the jvmmodelinferrer

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: JvmTypeReference and XExpression error [message #991476 is a reply to message #991471] Wed, 19 December 2012 12:20 Go to previous messageGo to next message
Tommaso De Sica is currently offline Tommaso De SicaFriend
Messages: 131
Registered: March 2012
Location: Italy
Senior Member

Christian Dietrich wrote on Wed, 19 December 2012 12:22
Hi

How shall base know your semantics/visibility rules

you have do do things in scoping as well. The best way to do that is
to reuse xbase concepts (if expression) or to map your construct to
something from java using the jvmmodelinferrer


I think I can't reuse xbase concepts because my grammar doesn't expect Xbase instructions inside IF body, but some other constructs. In fact, real IF rule is this:
IfStatement:
	'IF''('condition=Condition')''{'
		statements+=Statement*
	'}'
;

where "statements" are described with other rules.

But I've not idea on how can use jvmmodelinferrer to model if statement. Can you give me an idea of solution (the "initial kickass")?

Very thank you.
Re: JvmTypeReference and XExpression error [message #991479 is a reply to message #991476] Wed, 19 December 2012 12:33 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

this is not what i thought of,

i thought of something like

or you digg into xbase scopeprovider and make that xtext does for if yourt your if too.
(1) create a class
(2) make a field for vars
(3) make a method of the if


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: JvmTypeReference and XExpression error [message #991495 is a reply to message #991479] Wed, 19 December 2012 14:18 Go to previous messageGo to next message
Tommaso De Sica is currently offline Tommaso De SicaFriend
Messages: 131
Registered: March 2012
Location: Italy
Senior Member

Sorry, I don't understand where I have to create that class with those methods.

Meanwhile, I've tryed to create my custom scope for my local variables, but it doesn't work.
ublic class TestgrammarScopeProvider extends XbaseScopeProvider {
	
	@Override
    protected IScope createLocalVarScope(IScope parentScope,
            LocalVariableScopeContext scopeContext) {
        if (scopeContext != null && scopeContext.getContext() != null) {
            EObject context = scopeContext.getContext();
            if (context instanceof Program) {
            	Program program = (Program) context;
                return Scopes.scopeFor(program.getDeclarations());
            }
        }
 
        return super.createLocalVarScope(parentScope, scopeContext);
    }

}

(Program is main rule, where definitions have been made)
@Override
    public Class<? extends IScopeProvider> bindIScopeProvider() {
        return TestgrammarScopeProvider.class;
    }

[Updated on: Wed, 19 December 2012 14:19]

Report message to a moderator

Re: JvmTypeReference and XExpression error [message #991504 is a reply to message #991495] Wed, 19 December 2012 15:02 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

can you share a complete grammar. i will see if i find time do try it myself.
btw with the inferrer i meant
infer a class from your Program meta element and so on in the precreated JvmmModelInferrer.
P.S: Did you have a look at the seven languages tutorials.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: JvmTypeReference and XExpression error [message #991505 is a reply to message #991504] Wed, 19 December 2012 15:24 Go to previous messageGo to next message
Tommaso De Sica is currently offline Tommaso De SicaFriend
Messages: 131
Registered: March 2012
Location: Italy
Senior Member

Codes that I've posted are simpler version of my grammar, real one is this:

Program:
	'PROGRAM' name=ID '{'
		statements+=StatementBlock*
	'}'
;

StatementBlock:
	declarations+=Variable*
	statement=Statement
;

Statement:
	Sequence | Function | IfStatement
;

Sequence:
	'SEQ' name=ID '{'
		statements+=StatementBlock*
	'}'
;

Function:
	'FUNCTION' name=ID ':' type=Type
;

Type:
	Bool | Math
;

Bool:
	'BOOL'
;

Math:
	'MATH'
;

Variable:
	variable=XVariableDeclaration
;

Condition:
	condition=XExpression
;

IfStatement:
	'IF''('condition=Condition')''{'
		statements+=StatementBlock*
	'}'
;
Re: JvmTypeReference and XExpression error [message #991508 is a reply to message #991505] Wed, 19 December 2012 15:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
JUst saw that you have to do more than simply localvarscope.

you have to fit into the typesystem of xbase

e.g.

@Singleton
public class MyDslTypeProvider extends XbaseTypeProvider {
	
	@Override
	protected JvmTypeReference typeForIdentifiable(
			JvmIdentifiableElement identifiable, boolean rawType) {
		if (identifiable instanceof Variable) {
			return ((Variable)identifiable).getType();
		}
		return super.typeForIdentifiable(identifiable, rawType);
	}

}


Variable returns types::JvmIdentifiableElement:
	{Variable}type=JvmTypeReference name=ID ';'
;


public class MyDslScopeProvider extends XbaseScopeProvider {
	
	@Override
	protected IScope createLocalVarScope(IScope parentScope,
			LocalVariableScopeContext scopeContext) {
		if (EcoreUtil2.getContainerOfType(scopeContext.getContext(), Condition.class )!= null) {
			Model m = EcoreUtil2.getContainerOfType(scopeContext.getContext(), Model.class );
			if (m != null) {
				return Scopes.scopeFor(m.getVar(),super.createLocalVarScope(parentScope, scopeContext) );
			}
		}
		return super.createLocalVarScope(parentScope, scopeContext);
	}

}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: JvmTypeReference and XExpression error [message #991528 is a reply to message #991508] Wed, 19 December 2012 16:59 Go to previous messageGo to next message
Tommaso De Sica is currently offline Tommaso De SicaFriend
Messages: 131
Registered: March 2012
Location: Italy
Senior Member

I've tryed to add TypeProvider (can it stay in *.jvmodel package, right?) and changed Variable definition.

I've also added scope method (but I haven't got Model in my dsl, I used StatementBlock which contains variables).

But I receive an IllegalArgumentException.

@Singleton
public class TestgrammarTypeProvider extends XbaseTypeProvider {
	
	@SuppressWarnings("restriction")
	@Override
	protected JvmTypeReference typeForIdentifiable(
			JvmIdentifiableElement identifiable, boolean rawType) {
		if (identifiable instanceof Variable) {
			return ((Variable)identifiable).getType();
		}
		return super.typeForIdentifiable(identifiable, rawType);
	}

}

@Override
	protected IScope createLocalVarScope(IScope parentScope,
			LocalVariableScopeContext scopeContext) {
		if (EcoreUtil2.getContainerOfType(scopeContext.getContext(), Condition.class )!= null) {
			StatementBlock m = EcoreUtil2.getContainerOfType(scopeContext.getContext(), StatementBlock.class );
			if (m != null) {
				return Scopes.scopeFor(m.getDeclarations(),super.createLocalVarScope(parentScope, scopeContext) );
			}
		}
		return super.createLocalVarScope(parentScope, scopeContext);
	}

@Override
    public Class<? extends IScopeProvider> bindIScopeProvider() {
        return TestgrammarScopeProvider.class;
    }

Variable returns jvmTypes::JvmIdentifiableElement:
	{Variable}type=JvmTypeReference name=ID ';'
;


Christian very very thanks for your help.
Re: JvmTypeReference and XExpression error [message #991531 is a reply to message #991528] Wed, 19 December 2012 17:01 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi what does the exception say

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: JvmTypeReference and XExpression error [message #991542 is a reply to message #991531] Wed, 19 December 2012 17:43 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
P.S: did you bind the typeprovider too?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: JvmTypeReference and XExpression error [message #991874 is a reply to message #991542] Thu, 20 December 2012 11:45 Go to previous messageGo to next message
Tommaso De Sica is currently offline Tommaso De SicaFriend
Messages: 131
Registered: March 2012
Location: Italy
Senior Member

Christian Dietrich wrote on Wed, 19 December 2012 18:01
Hi what does the exception say

Exception was for external reason, sorry.

Christian Dietrich wrote on Wed, 19 December 2012 18:43
P.S: did you bind the typeprovider too?


Yes, I did.

I've changed my grammar:

// Rimetti con sequenza ROOT
Program:
	'PROGRAM' name=ID '{'
		statements+=Statement*
	'}'
;

Statement:
	Sequence | Function | IfStatement
;

Sequence:
	'SEQ' name=ID '{'
		declarations+=Variable*
		statements+=Statement*
	'}'
;

Function:
	'FUNCTION' name=ID ':' type=Type
;

Type:
	Bool | Math
;

Bool:
	'BOOL'
;

Math:
	'MATH'
;

Variable returns jvmTypes::JvmIdentifiableElement:
	{Variable}type=JvmTypeReference name=ID ';'
;

Condition:
	condition=XExpression
;

IfStatement:
	'IF''('condition=Condition')''{'
		statements+=Statement*
	'}'
;


Now I have Sequence that can define local variables and function, if or other sub-sequences. The problem is this: I want all sequences can refer their local variables and all local variables in super-sequeces, but with my provider it isn't possible.
Re: JvmTypeReference and XExpression error [message #991877 is a reply to message #991874] Thu, 20 December 2012 11:53 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Sorry i fear I cannot do your work aka dig into xbase code yourself.

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: JvmTypeReference and XExpression error [message #991982 is a reply to message #991465] Thu, 20 December 2012 15:42 Go to previous message
Tommaso De Sica is currently offline Tommaso De SicaFriend
Messages: 131
Registered: March 2012
Location: Italy
Senior Member

I used global variables and scope for those.
Very thank you for support.

Just a little question:
is it possible to check if an XExpression is a Boolean condition?
Previous Topic:problem with testing the editor as Eclipse Application
Next Topic:Unexpected error when parsing input
Goto Forum:
  


Current Time: Thu Mar 28 11:38:33 GMT 2024

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

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

Back to the top