Home » Modeling » TMF (Xtext) » XBase : How to strip "var/val" in XVariableDeclaration
| | |
Re: XBase : How to strip "var/val" in XVariableDeclaration [message #1367389 is a reply to message #1367262] |
Mon, 19 May 2014 15:20   |
Eclipse User |
|
|
|
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 #1426348 is a reply to message #1426313] |
Thu, 18 September 2014 12:02   |
Eclipse User |
|
|
|
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 XVariableDec [message #1429467 is a reply to message #1429418] |
Tue, 23 September 2014 05:04   |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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 XVar [message #1430569 is a reply to message #1429890] |
Wed, 24 September 2014 10:15   |
Eclipse User |
|
|
|
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
|
|
| | |
Goto Forum:
Current Time: Thu Sep 25 07:40:22 EDT 2025
Powered by FUDForum. Page generated in 0.06185 seconds
|