Skip to main content



      Home
Home » Modeling » TMF (Xtext) » XBase : How to strip "var/val" in XVariableDeclaration
icon3.gif  XBase : How to strip "var/val" in XVariableDeclaration [message #1363858] Sun, 18 May 2014 03:49 Go to next message
Eclipse UserFriend
Hi. I want to to extend XVariableDeclaration and Strip out the "writeable" Feature (in the grammar this would be either "val" or "var" as a literal bound to a boolean feature. Naturally, antlr tells me that this would lead to ambiguous results are both XExpression and XVariableDeclaration would now match leading to unpredictable recursion.

Could anybody give me a hint how to implement a XVariableDeclaration without the "val/var" bit?

Cheers, Heinrich
Re: XBase : How to strip "var/val" in XVariableDeclaration [message #1364705 is a reply to message #1363858] Sun, 18 May 2014 12:29 Go to previous messageGo to next message
Eclipse UserFriend
What about keeping either var or val depending in what you want to
have
Re: XBase : How to strip "var/val" in XVariableDeclaration [message #1367262 is a reply to message #1364705] Mon, 19 May 2014 14:10 Go to previous messageGo to next message
Eclipse UserFriend
Perhaps I was a bit unclear:

I want to override the rule like this:

XVariableDeclaration returns XExpression:
	{XVariableDeclaration}
	(writeable?='var'|'val') (=>(type=JvmTypeReference name=ValidID) | name=ValidID) ('=' right=XExpression)?;


I want to get rid of the mandatory val or var.
The result would be like this:
String str = null;

instead of
val String str = null;


The Problem is that an XEXpression which would be also available in this scope could
also be just like an XVariableDeclaration and this would be ambiguous.

XExpression returns XExpression :
	XAssignment;

XAssignment returns XExpression :
	{XAssignment} feature=[types::JvmIdentifiableElement|FeatureCallID] '=' value=XAssignment ...


Leaving that part in wouldn't be possible as we have a lot of models of our DSL that
would need to be changed according to this rule.

Any ideas?

Cheers.

[Updated on: Mon, 19 May 2014 14:14] by Moderator

Re: XBase : How to strip "var/val" in XVariableDeclaration [message #1367389 is a reply to message #1367262] Mon, 19 May 2014 15:20 Go to previous messageGo to next message
Eclipse UserFriend
Am 19.05.14 20:10, schrieb Heinrich Müller:
> Perhaps I was a bit unclear:
>
> I want to override the rule like this:
>
>
> XVariableDeclaration returns XExpression:
> {XVariableDeclaration}
> (writeable?='var'|'val') (=>(type=JvmTypeReference name=ValidID) |
> name=ValidID) ('=' right=XExpression)?;
>
>
> I want to get rid of the mandatory val or var.
> The result would be like this:
> String str = null;
> instead of
> val String str = null;
>
> The Problem is that an XEXpression which would be also available in this
> scope could
> also be just like an XVariableDeclaration and this would be ambiguous.
>
>
> XExpression returns XExpression :
> XAssignment;
>
> XAssignment returns XExpression :
> {XAssignment} feature=[types::JvmIdentifiableElement|FeatureCallID]
> '=' value=XAssignment ...
>
>
> Any ideas?
>
> Cheers.

Hi Heinrich,

I'm afraid that this is not possible without mandatory semicolons to
indicate 'statements'. E.g., the following expressions would be
completely ambiguous to the parser if you skip val or var, even if you
make the type mandatory in the variable declaration:

String s = null

Is basically the token sequence ID ID '=' 'null' which could either be a
variable declaration or an assignment after a simple feature call. If
you really want to make compromises there, you could use a syntactic
predicate to force the parser into one direction, e.g.

XVariableDeclaration returns XExpression:
=>(
{XVariableDeclaration}
type=JvmTypeReference name=ValidID) ('=' right=XExpression)?;

but this would basically require a semicolon in every block expression
that has adjacent simple feature calls.

Please note that there's no way to keep type inference and skip the val
/ var keywords for local vars, since a plain assignment would just look
like a variable declaration and vice versa.

Hope that helps,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com
Re: XBase : How to strip "var/val" in XVariableDeclaration [message #1367406 is a reply to message #1367389] Mon, 19 May 2014 15:34 Go to previous messageGo to next message
Eclipse UserFriend
Using semicolons to separate Statements would be OK for us. Tried it and worked like a charm. Thanks, Sebastian Very Happy
Re: XBase : How to strip "var/val" in XVariableDeclaration [message #1391993 is a reply to message #1367406] Tue, 01 July 2014 14:18 Go to previous messageGo to next message
Eclipse UserFriend
Hi again.

The semantic predicate worked for this case, but now I'm running into different issues.
We have the following rule defined in our DSL:

Statement:
target= [types::JvmIdentifiableElement|QualifiedName] '.' 'getValue' '(' value=[Value|QualifiedName] ')' ';'
;

which leads to errors like this:

warning(200): Decision can match input such as "RULE_ID" using multiple alternatives: 2, 3
Semantic predicates were present but were hidden by actions.


where 2 is XExpression and 3 is 'Statement'

Any ideas?

Cheers, Heinrich

[Updated on: Tue, 01 July 2014 16:51] by Moderator

Re: XBase : How to strip "var/val" in XVariableDeclaration [message #1425864 is a reply to message #1391993] Wed, 17 September 2014 19:56 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

I have similar issue as Heinrich, I would like to have local vars in XBlockExpression without val /var. I tried next:

Operation:
'op' name=ValidID
'('(params+=FullJvmFormalParameter
(',' params+=FullJvmFormalParameter)*)?')'
':' type=JvmTypeReference
body=Script;


Script returns XBlockExpression:
{Script}
=>(expressions+=XVariableDeclaration ';'?)*
;

XVariableDeclaration returns XExpression:
=>(
{XVariableDeclaration}
type=JvmTypeReference name=ValidID) ('=' right=XExpression)?;

but there is bug (error2.png in attach)

does anyone know what is the problem?

Thank you in advance,

Marko
  • Attachment: error2.png
    (Size: 99.18KB, Downloaded 163 times)
Re: XBase : How to strip "var/val" in XVariableDeclaration [message #1426061 is a reply to message #1425864] Thu, 18 September 2014 03:27 Go to previous messageGo to next message
Eclipse UserFriend
Hi Marko,

how does the header of your grammar look like? Which version of Xtext do
you use?
Do you have org.eclipse.xtext.xbase and org.eclipse.xtext.common.types
in your dependency list?

Regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 18.09.14 01:57, schrieb Marko Markovic:
> Hi,
>
> I have similar issue as Heinrich, I would like to have local vars in XBlockExpression without val /var. I tried next:
>
> Operation:
> 'op' name=ValidID
> '('(params+=FullJvmFormalParameter
> (',' params+=FullJvmFormalParameter)*)?')'
> ':' type=JvmTypeReference
> body=Script;
>
>
> Script returns XBlockExpression:
> {Script}
> =>(expressions+=XVariableDeclaration ';'?)*
> ;
>
> XVariableDeclaration returns XExpression:
> =>(
> {XVariableDeclaration}
> type=JvmTypeReference name=ValidID) ('=' right=XExpression)?;
>
> but there is bug (error2.png in attach)
>
> does anyone know what is the problem?
>
> Thank you in advance,
>
> Marko
>
Re: XBase : How to strip "var/val" in XVariableDeclaration [message #1426313 is a reply to message #1426061] Thu, 18 September 2014 10:59 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

Thank you Sebastian for your answer, I use xtext 2.6, I have xtend library on build path of project (it contain org.eclipse.xtext.xbase and org.eclipse.xtext.common.types)
Xtext grammar:

grammar org.xtext.scripting.Scripting with org.eclipse.xtext.xbase.Xbase

generate scripting "http://www.xtext.org/scripting/Scripting"
import "http://www.eclipse.org/xtext/xbase/Xbase"


Domainmodel:
importSection=XImportSection?
elements+=AbstractElement*;

AbstractElement:
PackageDeclaration | Entity;

PackageDeclaration:
'package' name=QualifiedName '{'
elements+=AbstractElement*
'}';

Entity:
'entity' name=ValidID
('extends' superType=JvmTypeReference)? '{'
features+=Feature*
'}';

Feature:
Property | Operation;

Property:
type=JvmTypeReference name=ValidID;

Operation:
'op' name=ValidID
'('(params+=FullJvmFormalParameter
(',' params+=FullJvmFormalParameter)*)?')'
':' type=JvmTypeReference
body=Script;


Script returns XBlockExpression:
{Script}
=>(expressions+=XVariableDeclaration ';'?)*
;

XExpressionOrVarDeclaration returns XExpression:
=>(
{XVariableDeclaration}
type=JvmTypeReference name=ValidID) ('=' right=XExpression)?;

Best regards,
Marko
Re: XBase : How to strip "var/val" in XVariableDeclaration [message #1426348 is a reply to message #1426313] Thu, 18 September 2014 12:02 Go to previous messageGo to next message
Eclipse UserFriend
Could you try to add another import:
import "http://www.eclipse.org/xtext/common/JavaVMTypes" as types

Any chance to try 2.7.x? If that doesn't work, please file a ticket.

Regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 18.09.14 16:59, schrieb Marko Markovic:
> Hi,
>
> Thank you Sebastian for your answer, I use xtext 2.6, I have xtend
> library on build path of project (it contain org.eclipse.xtext.xbase
> and org.eclipse.xtext.common.types)
> Xtext grammar:
>
> grammar org.xtext.scripting.Scripting with org.eclipse.xtext.xbase.Xbase
>
> generate scripting "http://www.xtext.org/scripting/Scripting"
> import "http://www.eclipse.org/xtext/xbase/Xbase"
>
>
> Domainmodel:
> importSection=XImportSection?
> elements+=AbstractElement*;
>
> AbstractElement:
> PackageDeclaration | Entity;
>
> PackageDeclaration:
> 'package' name=QualifiedName '{'
> elements+=AbstractElement*
> '}';
>
> Entity:
> 'entity' name=ValidID ('extends' superType=JvmTypeReference)? '{'
> features+=Feature*
> '}';
>
> Feature:
> Property | Operation;
>
> Property:
> type=JvmTypeReference name=ValidID;
>
> Operation:
> 'op' name=ValidID '('(params+=FullJvmFormalParameter (','
> params+=FullJvmFormalParameter)*)?')'
> ':' type=JvmTypeReference
> body=Script;
>
>
> Script returns XBlockExpression:
> {Script}
> =>(expressions+=XVariableDeclaration ';'?)*
> ;
>
> XExpressionOrVarDeclaration returns XExpression:
> =>(
> {XVariableDeclaration}
> type=JvmTypeReference name=ValidID) ('=' right=XExpression)?;
>
> Best regards,
> Marko
Re: XBase : How to strip "var/val" in XVariableDeclaration [message #1429418 is a reply to message #1426348] Tue, 23 September 2014 03:53 Go to previous messageGo to next message
Eclipse UserFriend
Hi Sebastian,

Thank you very much and sorry for delay of my answer.

It works, I can write int a = 5 without val/var in XBlockExpression.

but, I have one more question,
Is possible write next in XBlockExpression?
{
int c = 5
move(c)
}

I tried next:

Operation:
'op' name=ValidID
'('(params+=FullJvmFormalParameter
(',' params+=FullJvmFormalParameter)*)?')'
':' type=JvmTypeReference
body = XBlockExpression
;

XVariableDeclaration returns XExpression:
=>({XVariableDeclaration}type=JvmTypeReference name=ValidID) ('=' right=XExpression)?;

XExpression returns XExpression :
XAssignment | Move;

Move:
{Move}
'move' '(' (expression+=XExpression)? ')'
;

but in editor I have error: The TypeResolutionStateAdapter was removed while resolving - See error log for details (error1.png in attach)

Do I change grammar or something else?

Thank you in advance,

Marko
  • Attachment: Error1.png
    (Size: 146.87KB, Downloaded 140 times)
Re: XBase : How to strip "var/val" in XVariableDec [message #1429467 is a reply to message #1429418] Tue, 23 September 2014 05:04 Go to previous messageGo to next message
Eclipse UserFriend
Hi Marko,

you introduced a new keyword 'move'. If you want to use that from within
expressions as an Identifier, your have to specialize the parser rule
ValidID.

Regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 23.09.14 09:53, schrieb Marko Markovic:
> Hi Sebastian,
>
> Thank you very much and sorry for delay of my answer.
>
> It works, I can write int a = 5 without val/var in XBlockExpression.
>
> but, I have one more question,
> Is possible write next in XBlockExpression?
> {
> int c = 5
> move(c)
> }
>
> I tried next:
>
> Operation:
> 'op' name=ValidID
> '('(params+=FullJvmFormalParameter
> (',' params+=FullJvmFormalParameter)*)?')'
> ':' type=JvmTypeReference
> body = XBlockExpression
> ;
>
> XVariableDeclaration returns XExpression:
> =>({XVariableDeclaration}type=JvmTypeReference name=ValidID) ('=' right=XExpression)?;
>
> XExpression returns XExpression :
> XAssignment | Move;
>
> Move:
> {Move}
> 'move' '(' (expression+=XExpression)? ')'
> ;
>
> but in editor I have error: The TypeResolutionStateAdapter was removed while resolving - See error log for details (error1.png in attach)
>
> Do I change grammar or something else?
>
> Thank you in advance,
>
> Marko
>
Re: XBase : How to strip "var/val" in XVariableDec [message #1429470 is a reply to message #1429418] Tue, 23 September 2014 05:06 Go to previous messageGo to next message
Eclipse UserFriend
Sorry, I misread you post.
Looks like you tried to introduce a new expression type but did not
implement the necessary services (thats what's indicated by the error at
least).
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 23.09.14 09:53, schrieb Marko Markovic:
> Hi Sebastian,
>
> Thank you very much and sorry for delay of my answer.
>
> It works, I can write int a = 5 without val/var in XBlockExpression.
>
> but, I have one more question,
> Is possible write next in XBlockExpression?
> {
> int c = 5
> move(c)
> }
>
> I tried next:
>
> Operation:
> 'op' name=ValidID
> '('(params+=FullJvmFormalParameter
> (',' params+=FullJvmFormalParameter)*)?')'
> ':' type=JvmTypeReference
> body = XBlockExpression
> ;
>
> XVariableDeclaration returns XExpression:
> =>({XVariableDeclaration}type=JvmTypeReference name=ValidID) ('=' right=XExpression)?;
>
> XExpression returns XExpression :
> XAssignment | Move;
>
> Move:
> {Move}
> 'move' '(' (expression+=XExpression)? ')'
> ;
>
> but in editor I have error: The TypeResolutionStateAdapter was removed while resolving - See error log for details (error1.png in attach)
>
> Do I change grammar or something else?
>
> Thank you in advance,
>
> Marko
>
Re: XBase : How to strip "var/val" in XVariableDec [message #1429890 is a reply to message #1429470] Tue, 23 September 2014 17:51 Go to previous messageGo to next message
Eclipse UserFriend
Hi Sebastian,

Thank you on your answer, can you help me about specialize the parser rule ValidID as you wrote in one of last post?
Sorry if it is easy, i'm beginner in xtext.

Thank you very much,

Marko
Re: XBase : How to strip "var/val" in XVar [message #1430569 is a reply to message #1429890] Wed, 24 September 2014 10:15 Go to previous messageGo to next message
Eclipse UserFriend
Am 23.09.14 23:51, schrieb Marko Markovic:
> Hi Sebastian,
>
> Thank you on your answer, can you help me about specialize the parser
> rule ValidID as you wrote in one of last post?
> Sorry if it is easy, i'm beginner in xtext.
>
> Thank you very much,
>
> Marko

Hi Marko,

that was a mistake of mine. I assume the idea to have a Move expression
put you on the wrong track. Anyway, ValidID can be overridden like this:

ValidID: ID | 'Move';

But as I tried to say, it wouldn't solve your problem since you
introduced a new expression and need to have all infrastructure
components for that one available (type inferrer, compiler, ..)

Regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com
Re: XBase : How to strip "var/val" in XVar [message #1430649 is a reply to message #1430569] Wed, 24 September 2014 12:03 Go to previous messageGo to next message
Eclipse UserFriend
Thank you Sebastian on your answer, I tried it (ValidID: ID | 'Move'Wink and I had error and I didn't know what I need to do next.
If you find some similar example I would be very grateful to you.

Best regards,

Marko
Re: XBase : How to strip "var/val" in XVar [message #1440498 is a reply to message #1430649] Wed, 08 October 2014 08:47 Go to previous message
Eclipse UserFriend
Hi,
I solved this problem, I created xtend class AlasTypeComputer in package ...typesystem and AlasCompiler.xtend in package ..jvmmodel and bind in MyDslRuntimeModule
public Class<? extends XbaseCompiler> bindXbaseCompiler() {
return AlasCompiler.class;
}

@Override
public Class<? extends ITypeComputer> bindITypeComputer() {
return AlasTypeComputer.class;
}

If someone would like more detail about this I'm here Smile

Best regards,

Marko
Previous Topic:Luna SR1, model editor going berserk during text reconciliation
Next Topic:[SOLVED] Errors running builder 'Xtext Project Builder' on project 'blah'
Goto Forum:
  


Current Time: Thu Sep 25 07:40:26 EDT 2025

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

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

Back to the top