Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [solved] Accessing types and their properties from another file (with same grammar)
[solved] Accessing types and their properties from another file (with same grammar) [message #1419928] Tue, 09 September 2014 08:59 Go to next message
Simon Hofer is currently offline Simon HoferFriend
Messages: 4
Registered: September 2014
Junior Member
Hi

I'm new to xtext and have a question. I have defined a grammar according to [an'T post link, just google xtext-and-dot-expressions] and modified it a little bit e.g. imports. My grammar now looks like this

grammar org.eclipse.xtext.example.domainmodel.Domainmodel with org.eclipse.xtext.xbase.Xbase

generate domainmodel "[interpreted as link]/example/Domainmodel"

DomainModel:
	'package' packageName=QualifiedName
	importSection=XImportSection?
	elements+=Entity*
	usages+=Usage*
	
;
	
Entity:
    "entity" name=ValidID "{"
        features+=Feature*
    "}"
;
 
Feature:
    Attribute | Reference
;
 
Attribute:
    "attr" name=ValidID ":" type=DataType
;
 
enum DataType:
    string | int
;
 
Reference:
    "ref" name=ValidID ":" type=[Entity|QualifiedName]
;

Usage:
    "use" ref=DotExpression
;
 
DotExpression returns Ref:
    EntityRef ({DotExpression.ref=current}  "." tail=[Feature])*
;
 
EntityRef returns Ref:
    {EntityRef} entity=[Entity]
; 



I have two files:
1) firstModel.dmodel
package myFirstPackage

entity myFirstEntity {
	attr value : int	
}



2) secondModel.dmodel
package mySecondPackage
import myFirstPackage.*

entity mySecondEntity {
	attr myAttr : int
	ref myRef : myFirstEntity
}

use mySecondEntity.myRef



The import works, but the "dot-operation" does not. I followed christian's example, implemented the ScopeProvider and modified the bindIScopeProvider method in AbstractDomainmodelRuntimeModule.java accordingly.

Do I have to change / implement something else?

[Updated on: Thu, 11 September 2014 11:22]

Report message to a moderator

Re: Accessing types and their properties from another file (with same grammar) [message #1420226 is a reply to message #1419928] Tue, 09 September 2014 17:52 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13264
Registered: July 2009
Senior Member
Hi,

you use xbase, is that intended? and how does your scopeprovider class look like? xbase scoping is very different from non xbase scoping


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Tue, 09 September 2014 18:03]

Report message to a moderator

Re: Accessing types and their properties from another file (with same grammar) [message #1420236 is a reply to message #1420226] Tue, 09 September 2014 18:11 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13264
Registered: July 2009
Senior Member
here is what works for me

class MyDslScopeProvider extends XbaseBatchScopeProvider {

	override getScope(EObject context, EReference reference) {
		if (context instanceof DotExpression) {
			return scope_DotExpression_tail(context, reference)
		}
		super.getScope(context, reference)
	}

	def IScope scope_DotExpression_tail(DotExpression exp, EReference ref) {
		val head = exp.ref;
		switch (head) {
			EntityRef : Scopes::scopeFor(head.entity.features)
			DotExpression : {
				val tail = head.tail
				switch (tail) {
					Attribute : IScope::NULLSCOPE
					Reference : Scopes::scopeFor(tail.type.features)
					default: IScope::NULLSCOPE
				}
			}
			
			default: IScope::NULLSCOPE
		}
	}
	
}


public class MyDslRuntimeModule extends org.xtext.example.mydsl.AbstractMyDslRuntimeModule {

	public Class<? extends IBatchScopeProvider> bindIBatchScopeProvider() {
		return MyDslScopeProvider.class;
	}
	
}


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Accessing types and their properties from another file (with same grammar) [message #1421443 is a reply to message #1420236] Thu, 11 September 2014 11:21 Go to previous message
Simon Hofer is currently offline Simon HoferFriend
Messages: 4
Registered: September 2014
Junior Member
Thanks Christian, it works Smile
Previous Topic:annotate a parameter in method
Next Topic:xcore, ecore, emf, xtext and maven
Goto Forum:
  


Current Time: Mon Dec 09 20:28:28 GMT 2019

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

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

Back to the top