Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Cross reference and scoping
Cross reference and scoping [message #1400683] Mon, 14 July 2014 15:14 Go to next message
Heiner Bunjes is currently offline Heiner BunjesFriend
Messages: 3
Registered: July 2014
Junior Member
I am new to xtext and trying to create a DSL to describe an event processing
ProcessorNetwork with the following features:

- A ProcessorNetwork consists of multiple Processors.
- A Processor has multiple 'InLets' and one 'OutLet'.
- Each Processor (Proc) is of a specific type (ProcType).
- The ProcType of a Proc defines which InLets the Proc has.

My current grammar is listed below.

What I want to achieve is that the lines marked with <a>
shall become an [Inlet]-Reference that is checked by xtext.
Allowed values shall be names of those Inlets that are members of the
ProcType of the Proc that is referenced in the preceding line (the line before
the line that is marked with <a>).

In my example DSL this means that at the location <Cursor> only references to
the InLets "inlet_1" and "inlet_2" shall be allowed because only these two
InLets are allowed for proctype_1.


How can this be done?



######## <example DSL>

version 14
 
procType proctype_1 
	inLet inlet_1 inlettype_1 "The first inlet for proctype_1" 
	inLet inlet_2 inlettype_2 "The second inlet for proctype_1" 

procType proctype_2 
	inLet inlet_1 inlettype_3 "The first inlet for proctype_2" 
	inLet inlet_3 inlettype_1 "The second inlet for proctype_2" 
	inLet inlet_4 inlettype_4 "The third inlet for proctype_2" 


proc proc_1 proctype_1

proc proc_2 proctype_2

inGate ingate_1 proc_1 <Cursor> 

######## </example DSL>


######## <Grammar>

grammar btc.Epedsl with org.eclipse.xtext.common.Terminals
generate epedsl <link not allowed, sorry>


Model:
	'version 14'
	procTypes     += ProcType+
	procs         += Proc+
	InGates       += InGate+
	OutGates      += OutGate+ 
	links         += Link*
	('EOF' | 'eof')?
;


InGate : 'inGate' 
    name         = ID
    proc         = [Proc]
    inlet        = ID       // See TODO <a>  	
	description  = STRING?
;


OutGate : 'outGate' 
	name         = ID 
	proc         = [Proc]
	description  = STRING?
;


Proc : 'proc'
	name     =  ID
	procType =  [ProcType]
;	


ProcType : 'procType' 
	name   =  ID
	inlets += InLet+ 
;


Fqn : ID('.'ID)*
;


InLet : 'inLet' 
	name         = ID
	inletType    = ID
	description  = STRING?
;


Link : 'link' 
	procFrom = [Proc] 
	procTo   = [Proc] 
	inletTo  = ID     // See TODO <a>
;

######## </Grammar>

Re: Cross reference and scoping [message #1400718 is a reply to message #1400683] Mon, 14 July 2014 16:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
InGate : 'inGate' 
    name         = ID
    proc         = [Proc]
    inlet        = [InLet]       // See TODO <a>  	
	description  = STRING?
;



def IScope scope_InGate_inlet(InGate ctx, EReference r) {
    Scopes.scopeFor(ctx.procprocType.inlets)
}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Cross reference and scoping [message #1401394 is a reply to message #1400718] Tue, 15 July 2014 14:38 Go to previous messageGo to next message
Heiner Bunjes is currently offline Heiner BunjesFriend
Messages: 3
Registered: July 2014
Junior Member
Great, thank you very much! I tried it and it worked just fine (after finding out, where to put it).

Have a great day Christian!
Re: Cross reference and scoping [message #1401828 is a reply to message #1401394] Wed, 16 July 2014 06:11 Go to previous messageGo to next message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 250
Registered: June 2013
Senior Member
Hello Heiner,

perhaps you can save us a couple of searching hours and tell us where you put it?

Uli
Re: Cross reference and scoping [message #1401917 is a reply to message #1401828] Wed, 16 July 2014 08:48 Go to previous messageGo to next message
Heiner Bunjes is currently offline Heiner BunjesFriend
Messages: 3
Registered: July 2014
Junior Member
I put it into /com.btcag.epedsl.grammar/src/btc/scoping/EpedslScopeProvider.xtend

so that now this file looks like this:


/*
 * generated by Xtext
 */
package btc.scoping

import org.eclipse.xtext.scoping.IScope
import btc.epedsl.InGate
import org.eclipse.emf.ecore.EReference
import org.eclipse.xtext.scoping.Scopes
import btc.epedsl.Link

/**
 * This class contains custom scoping description.
 * 
 * see : http://www.eclipse.org/Xtext/documentation.html#scoping
 * on how and when to use it 
 *
 */
class EpedslScopeProvider extends org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider {

	def IScope scope_InGate_inlet(InGate ctx, EReference r) {
		Scopes.scopeFor(ctx.proc.procType.inlets)
	}

	def IScope scope_Link_inletTo(Link ctx, EReference r) {
		Scopes.scopeFor(ctx.procTo.procType.inlets)
	}
	
}


Re: Cross reference and scoping [message #1402259 is a reply to message #1401917] Wed, 16 July 2014 19:23 Go to previous message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 250
Registered: June 2013
Senior Member
Thanks Heiner, very helpful indeed, Uli
Previous Topic:[xtext] about EMF created by xtext
Next Topic:No EObjectDescription could be found in Scope
Goto Forum:
  


Current Time: Fri Mar 29 06:21:15 GMT 2024

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

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

Back to the top