Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » local scope problem
icon8.gif  local scope problem [message #1707911] Thu, 10 September 2015 13:16 Go to next message
Peter Obermann is currently offline Peter ObermannFriend
Messages: 17
Registered: July 2015
Junior Member
Hello there,

how can I use the variable created locally for the allocation in scope?
The variable "for_lokal" must end later "end scope".

When I add in AssignmentType "Scope", then it is available in every scope. Sad

Thanks in advance!


index.php/fa/23218/0/

index.php/fa/23219/0/
  • Attachment: grammar.jpg
    (Size: 70.31KB, Downloaded 294 times)
  • Attachment: syntax.jpg
    (Size: 36.58KB, Downloaded 271 times)

[Updated on: Thu, 10 September 2015 13:26]

Report message to a moderator

Re: local scope problem [message #1707920 is a reply to message #1707911] Thu, 10 September 2015 14:15 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
can you share grammar and model as text.
you can adapt the scopeprovider and put everything into scope you want.
your problem is that Scope is no Variable thus you cannot reference it as variable


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: local scope problem [message #1707935 is a reply to message #1707920] Thu, 10 September 2015 16:04 Go to previous messageGo to next message
Peter Obermann is currently offline Peter ObermannFriend
Messages: 17
Registered: July 2015
Junior Member
Hello Christian,
Thanks for your answer.

If I use the Test Rule, then it works. but then the variable in all scope exists. : - (((

Many greetings


Model:
  var +=Var*
  statement+=Statement*  
;

Var:
	'var' name=ID '=' (a=AssignmentType)';'
;

Test:
	Var | Scope
;

AssignmentType:
	INTEGER | FLOAT | var=[Var|ID] // |sc=[Test|ID]
;


INTEGER:
	name=MY_INT
;

FLOAT:
	name=MY_FLOAT
;


Statement:
	Assignment | Scope
;


Assignment:
	var=[Var|ID] '='  variables=AssignmentType ';'
;


Scope: 'scope' name=ID '=' int=MY_INT 'do'
		(statement+=Statement)*  
	 'end' 'scope' ';'
;

terminal MY_INT				: ('0'..'9'|'-'|'+')+ ('0'..'9')*;								
terminal MY_FLOAT			: ('0'..'9'|'-'|'+')  ('0'..'9')* '.' ('0'..'9'|'_')*;	
Re: local scope problem [message #1707946 is a reply to message #1707935] Thu, 10 September 2015 17:42 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

as i said: you would have to adapt scoping e.g. like

	def IScope scope_AssignmentType_sc(Scope ctx, EReference ref) {
		new SimpleScope(new FilteringScope(delegateGetScope(ctx,ref), [
			!EcoreUtil2.isAssignableFrom(MyDslPackage.Literals.SCOPE, EClass)
		]), newArrayList(EObjectDescription.create(QualifiedName.create(ctx.name), ctx)))
	}
	
	def IScope scope_AssignmentType_sc(Model ctx, EReference ref) {
		IScope.NULLSCOPE // hides global level stuff
	}


AssignmentType:
	INTEGER | FLOAT | sc=[Test|ID]
;


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: local scope problem [message #1707961 is a reply to message #1707946] Thu, 10 September 2015 20:50 Go to previous messageGo to next message
Peter Obermann is currently offline Peter ObermannFriend
Messages: 17
Registered: July 2015
Junior Member
Hello Christian,

Thank you for your help . Your sample code works, but in the initialization, there is a little problem.

I can not assign a variable anymore, only integer or float Sad

What actually makes your magic code? Smile

Many greetings

index.php/fa/23233/0/
  • Attachment: syntax.png
    (Size: 99.89KB, Downloaded 244 times)
Re: local scope problem [message #1707969 is a reply to message #1707961] Fri, 11 September 2015 04:30 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
well if you want refson toplevel you have to let them trough

def IScope scope_AssignmentType_sc(Model ctx, EReference ref) {
//here
new FilteringScope(delegateGetScope(ctx,ref), [
!EcoreUtil2.isAssignableFrom(MyDslPackage.Literals.SCOPE, EClass)
])
}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: local scope problem [message #1708043 is a reply to message #1707969] Fri, 11 September 2015 16:57 Go to previous messageGo to next message
Peter Obermann is currently offline Peter ObermannFriend
Messages: 17
Registered: July 2015
Junior Member
Hello Christian,
Thanks a lot for your help. It works Smile

Another question: Smile
I have enabled org.eclipse.xtext.validation.NamesAreUniqueValidator, can I take out individual Rule of verification?

Greetings and nice weekend
Re: local scope problem [message #1708045 is a reply to message #1708043] Fri, 11 September 2015 17:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
you can customize org.eclipse.xtext.validation.NamesAreUniqueValidationHelper.checkUniqueNames(Iterable<IEObjectDescription>, CancelIndicator, ValidationMessageAcceptor)
and filter the iterable before calling super


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: local scope problem [message #1708662 is a reply to message #1708045] Fri, 18 September 2015 13:23 Go to previous message
Peter Obermann is currently offline Peter ObermannFriend
Messages: 17
Registered: July 2015
Junior Member
Hello Christian,

Thank you for your response.

I'll try it tonight. Many thanks Smile
Previous Topic:Can the EmbeddedEditor be used without a dialog?
Next Topic:Integrating into Eclipse e4 application
Goto Forum:
  


Current Time: Fri Apr 26 04:24:04 GMT 2024

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

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

Back to the top