范围对象的Xtext示例 [英] Xtext example of a scoped object

查看:71
本文介绍了范围对象的Xtext示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个示例(在XText中),该示例如何在用户定义的对象成员上实现代码完成。据我所知,我需要使用IScope,但是如何将所有这些连接在一起还不清楚。

I'm looking for an example (in XText) of how to implement code completion on an user defined objects members. As far as I can see I need to use IScope, but how all this wires together is unclear.

考虑到特性是用户定义的类型,当我键入 name时,如何构建语法以完成/验证 String 中包含的方法。

Given that trait is a user defined type, how do I go about building a grammar to code complete / validate the methods contained within String when I type name.?

trait String {
    def toLowerCase(): String
    def toUpperCase(): String
}

val name = new String()
name.toLowerCase()

谢谢

推荐答案

这在很大程度上取决于您的语法采用范围界定。
假设您有这样的语法

It highly depends on your grammar what you have to do to adopt scoping. Let us say you have a grammar like

Model:
    statements+=Statement+
;

Statement:
    Trait | VarDef | Call
;

Trait:
    "trait" name=ID "{"
        ops+=Operation*
    "}"
;

Operation:
    "def" name=ID "()" ":" type=[Trait]
;

VarDef:
    "val" name=ID "=" "new" type=[Trait] "()"
;

Call:
    var=[VarDef] "." op=[Operation] "()"
;

然后您的范围提供者将看起来像

then your scopeprovider would look like

public class MyDslScopeProvider extends AbstractDeclarativeScopeProvider {

    IScope scope_Call_op(Call call, EReference ref) {
        return Scopes.scopeFor(call.getVar().getType().getOps());
    }
}    

您可以在此处找到有关该主题的博客系列:

You can find a blog series on the topic here:

https://web.archive.org/web/20130129085620/http://blogs.itemis.de/stundzig/archives/773

这篇关于范围对象的Xtext示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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