Xtext,多文件交叉引用 [英] Xtext, multi-file Cross-reference

查看:32
本文介绍了Xtext,多文件交叉引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想调用另一个文件中声明的变量.文件的包含是使用交叉引用完成的.以及声明的调用.这是语法:

I want to call variables declared in another file. The include of the file is done using cross referencing. and the call of the declared too. this is the grammar:

Script:
includes+=(Include)* assignments+=(Assignment)* g=GetLog?  clock=Clock? tests+=Test*
;

Assignment:
    Config |Cosem ;

Include:
    'INCLUDE' includedScript=[Script|STRING];

Cosem:
name=ID '=' 'COSEM' '(' classid=INT ',' version=INT ','  obis=STRING ')' ;

AttributeRef:
     name=[Cosem] "." attributeRef =IDValue

;

声明是Cosem规则.

从文档中我知道我必须在 IResourceDescription 中做一些事情,但我不知道究竟是什么

from the documentation I understand that I must do something in the IResourceDescription but I don't know what exactly

编辑

public class MyDslQNP extends DefaultDeclarativeQualifiedNameProvider {

    QualifiedName qualifiedName(Script script) {
        return QualifiedName.create(script.eResource().getURI().trimFileExtension().lastSegment(), script.eResource().getURI().fileExtension());
    }

}

推荐答案

您正在寻找的称为范围"xtext.它在 YourDslScopeProvider

what you are looking for is called "scoping" xtext. it is implemented in YourDslScopeProvider

这看起来像

class MyDslScopeProvider extends AbstractMyDslScopeProvider {

    override getScope(EObject context, EReference reference) {
        if (reference === MyDslPackage.Literals.ATTRIBUTE_REF__NAME) {
            // we are scoping the AttributeRef.name cross reference
            val script = EcoreUtil2.getContainerOfType(context, Script)
            if (script !== null) {
                val allImportedCosems = script.includes.map[includedScript.assignments.filter(Cosem)].flatten
                // put the imported cosems into scope
                return Scopes.scopeFor(allImportedCosems)
            }
        }
        super.getScope(context, reference)
    }

}

这篇关于Xtext,多文件交叉引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆