简体   繁体   English

如何在 xtext 中创建 goto 表达式?

[英]How can I create a goto expression in xtext?

I want to create a goto expression as follows我想创建一个goto表达式如下

//label
 <bb 2> :

//goto
goto <bb 2>;

The following grammar works fine for a simple ID.以下语法适用于简单 ID。 I have no idea how to reference the <ID INT> in the goto expression.我不知道如何在 goto 表达式中引用<ID INT>

Goto returns Goto:
    {Goto}
    'goto' goto+=[Label]  ';'
;

LabelDef returns LabelDef:
    {LabelDef}
    label+= Label ':'
    ;

Label returns Label:
    {Label}
    name= ID
    ;

Do have any idea how to that?你知道怎么做吗?

I think you want a terminal that is essentially "ID INT" and then use it to crossreference your Label.我认为您想要一个本质上是“ID INT”的终端,然后使用它来交叉引用您的 Label。 I think this is going to be a lot of work just to be able to allow "spaces" in your labels.我认为这将是很多工作,只是为了能够在标签中允许“空格”。 Why not simply rely on terminal "ID" and users may name them "bb2" if they wish?为什么不简单地依赖终端“ID”,如果他们愿意,用户可以将它们命名为“bb2”?

the feature you are looking for is a DataType rule您正在寻找的功能是 DataType 规则

Goto returns Goto:
    {Goto}
    'goto' goto+=[Label|IDandINT]  ';'
;

LabelDef returns LabelDef:
    {LabelDef}
    label+= Label ':'
    ;

Label returns Label:
    {Label}
    name= IDandINT
    ;
IDandINT: ID INT;

you may also introduce / customize DefaultTerminalConverters/IValueConverter for the datatype rule to normalize whitespace您还可以为数据类型规则引入/自定义 DefaultTerminalConverters/IValueConverter 以规范空白

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM