Skip to main content



      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 04:59 Go to next message
Eclipse UserFriend
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 07:22] by 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 13:52 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

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

[Updated on: Tue, 09 September 2014 14:03] by 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 14:11 Go to previous messageGo to next message
Eclipse UserFriend
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;
	}
	
}
Re: Accessing types and their properties from another file (with same grammar) [message #1421443 is a reply to message #1420236] Thu, 11 September 2014 07:21 Go to previous message
Eclipse UserFriend
Thanks Christian, it works Smile
Previous Topic:annotate a parameter in method
Next Topic:xcore, ecore, emf, xtext and maven
Goto Forum:
  


Current Time: Wed Jul 23 15:43:29 EDT 2025

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

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

Back to the top