XText 实体示例,原始类型 [英] XText entity example, primitive type

查看:20
本文介绍了XText 实体示例,原始类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试做的是修改一些基本的 entity DSL 示例,使其支持原语,并且可以完成以下操作:

What I'm trying to do, is modify a bit the basic entity DSL example, so that it supports primitives, and something like this can be done:

entity Dog {
   name : String
}

entity Person {
   name : String
   dog : Dog
}

这样成员的类型可以是对另一个实体名称的引用,也可以是预定义的原语.我也在寻找一种方法,因此在生成的编辑器中为基元和实体名称提供了内容辅助.

So that the type of the members can be either a reference to the name of another entity, or a predefined primitive. I'm also looking for a way, so there is content assist in the generated editor for both the primitives, and the entity names.

到目前为止,这是我的 .xtext:

Here is my .xtext so far:

Model:
    (entites+=Entity)*;

Entity:
    'entity' name=ID '{'
    (members+=Member)*
    '}';

AbstractType:
    Entity | PrimitiveType;

PrimitiveType:
    name='Integer' | name='String';

Member:
    (many?='many')? name=ID ':' (type=[AbstractType]);

在这种情况下,IntegerString 被编辑器识别为关键字,但它们被标记为错误,并显示消息:

In this case, Integer and String are recognized by the editor as keywords, but they are marked as error, with the message:

不匹配的输入整数"需要 RULE_ID

mismatched input 'Integer' expecting RULE_ID

我尝试使用此问题的解决方案:在 xtext 语法中定义原语 ,这还算不错,因为原语没有被标记为错误,但没有内容辅助.

I tried using the solution for this question: Defining Primitives within xtext Grammar , which was half-decent, because the primitives were not marked as error, but there were no content assist for them.

那么正确的做法是什么?

推荐答案

xxxx=[YYYYY] 是一个交叉引用.这是对在其他地方定义的东西的引用.在您的模型中,您没有 PrimitiveType 的实例,因此您不能拥有它的实例.所以你必须明确地定义它们

xxxx=[YYYYY] is a cross reference. this is a reference to something that is defined somewhere else. in your model yo have nowhere an instance of a PrimitiveType so you cannot have a instance of it. so you have to define them explicitely

Model:
(primitives+= PrimitiveType)*;
PrimitiveType:
'datatype' (name='Integer' | name='String');

型号

datatype String
datatype Integer
entity Dog {
    name : String
}

entity Person {
   name : String
   dog : Dog
}

或者不得不想出一个完全不同的语法

or have to come up with a completely different grammar

Model:
    (entites+=Entity)*;

Entity:
    'entity' name=ID '{'
    (members+=Member)*
    '}';

Type:
    EntityRefence | SimpleDataType;

EntityRefence:
    entity=[Entity]
;

SimpleDataType:
    type=PrimitiveType
;


enum PrimitiveType:
    String | Integer
;

Member:
    (many?='many')? name=ID ':' type=Type;

这篇关于XText 实体示例,原始类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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