Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Local Variable in XBlockExpression
Local Variable in XBlockExpression [message #1424450] Mon, 15 September 2014 21:28 Go to next message
Eclipse UserFriend
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 02:24 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Local Variable in XBlockExpression [message #1424962 is a reply to message #1424585] Tue, 16 September 2014 13:12 Go to previous messageGo to next message
Eclipse UserFriend
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 158 times)

[Updated on: Tue, 16 September 2014 13:14] by Moderator

Re: Local Variable in XBlockExpression [message #1424998 is a reply to message #1424962] Tue, 16 September 2014 14:29 Go to previous message
Eclipse UserFriend
https://www.eclipse.org/forums/index.php/t/810104/
Previous Topic:Xtext bug?
Next Topic:Python-like indentation and editor problems
Goto Forum:
  


Current Time: Tue Jul 01 15:19:56 EDT 2025

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

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

Back to the top