作用域对象的 Xtext 示例

发布于 2024-12-10 07:42:34 字数 364 浏览 3 评论 0 原文

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

鉴于 trait 是用户定义的类型,当我输入 name.< 时,如何构建语法来编码完成/验证 String 中包含的方法。 /代码>?

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

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

谢谢

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.

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()

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

枫林﹌晚霞¤ 2024-12-17 07:42:34

这在很大程度上取决于你的语法,你必须做什么才能采用范围界定。
假设您的语法类似于

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] "()"
;

您的范围提供程序,

public class MyDslScopeProvider extends AbstractDeclarativeScopeProvider {

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

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

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

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

甜宝宝 2024-12-17 07:42:34

在我关于 Xtext 的书中,“使用 Xtext 和 Xtend 实现特定领域语言”,https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend ,有一章关于范围为“较小的”Java 语言(也处理继承)。您可以在此处找到示例来源: https://github.com/LorenzoBettini/packtpub- xtext-book-examples

In my book on Xtext, "Implementing Domain-Specific Languages with Xtext and Xtend", https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend , there is a chapter about scoping for a "smaller" Java language (dealing also with inheritance). You can find the sources of examples here: https://github.com/LorenzoBettini/packtpub-xtext-book-examples

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文