[solved] Accessing types and their properties from another file (with same grammar) [message #1419928] |
Tue, 09 September 2014 08:59 |
Simon Hofer 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 #1420236 is a reply to message #1420226] |
Tue, 09 September 2014 18:11 |
|
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;
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Powered by
FUDForum. Page generated in 0.03556 seconds