Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Local Variable in XBlockExpression
Local Variable in XBlockExpression [message #1424450] Tue, 16 September 2014 01:28 Go to next message
Marko Markovic is currently offline Marko MarkovicFriend
Messages: 35
Registered: August 2014
Member
Hi,

I use XBlockExpression in my xtext grammar but I have a problem. In XBlockExpression I can't create local variable..
I would like to create and some my functions in XBlockExpression, for example:

{
...
int time = 5
log("Setting the system time to ", time);
...
}

Is it possible?

I tried example from https://www.eclipse.org/Xtext/7languagesDoc.html#scripting

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"

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

but it doesn't work. There are warning for import "http://www.eclipse.org/xtext/xbase/Xbase" (The imported package is not on the classpath of this project which may lead to follow up errors.) and error for XExpressionInsideBlock (XExpressionInsideBlock cannot be resolved to a rule).
I included xtend library (there is xbase.lib in this library)

Thank you in advance,

Marko
Re: Local Variable in XBlockExpression [message #1424585 is a reply to message #1424450] Tue, 16 September 2014 06:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

the name of the rule was changed. it is now XExpressionOrVarDeclaration.
please file a bug against the docs.

btw the var then would look like

val int time = 5


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Local Variable in XBlockExpression [message #1424962 is a reply to message #1424585] Tue, 16 September 2014 17:12 Go to previous messageGo to next message
Marko Markovic is currently offline Marko MarkovicFriend
Messages: 35
Registered: August 2014
Member
Hi Christian,

Thank you for your answer, it works.
But I would like local variable in XBlockExpression without 'val'..
My grammar is:

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


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

MyExpression returns XExpression:
Variable | Move
;

Variable returns XExpression:
{Variable}
type=JvmTypeReference name=ValidID ( '=' exp=XExpression)?';'
;

Move returns XExpression:
{Move}
'move' '(' exps+=XExpression ')' ';'
;

but there is mistake in dsl editor (error.png in attach)

Do you have any suggestions for me?

Thank you,

Marko
  • Attachment: error.png
    (Size: 144.88KB, Downloaded 140 times)

[Updated on: Tue, 16 September 2014 17:14]

Report message to a moderator

Re: Local Variable in XBlockExpression [message #1424998 is a reply to message #1424962] Tue, 16 September 2014 18:29 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
https://www.eclipse.org/forums/index.php/t/810104/

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Xtext bug?
Next Topic:Python-like indentation and editor problems
Goto Forum:
  


Current Time: Thu Apr 25 10:11:06 GMT 2024

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

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

Back to the top