JvmTypeReference and XExpression error [message #991465] |
Wed, 19 December 2012 11:00 |
|
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:
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 #991476 is a reply to message #991471] |
Wed, 19 December 2012 12:20 |
|
Christian Dietrich wrote on Wed, 19 December 2012 12:22Hi
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 #991495 is a reply to message #991479] |
Wed, 19 December 2012 14:18 |
|
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 #991505 is a reply to message #991504] |
Wed, 19 December 2012 15:24 |
|
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 |
|
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 |
|
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 #991874 is a reply to message #991542] |
Thu, 20 December 2012 11:45 |
|
Christian Dietrich wrote on Wed, 19 December 2012 18:01Hi what does the exception say
Exception was for external reason, sorry.
Christian Dietrich wrote on Wed, 19 December 2012 18:43P.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.
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05243 seconds