Xtext 项目列表或仅一项
我正在尝试创建一种语法来解析以下内容:
reference: java.util.String
但换句话说
reference: {java.util.String, java.lang.Integer}
,我希望它既解析限定名称的列表,又解析其中的一项(在本例中未用“{”标记)。
我尝试的是这样的:
Reference:
'reference' ':' ('{' values+=QualifiedName (',' values+=QualifiedName)* '}') | (values+=QualifiedName);
但是,我收到错误:在使用第一种形式的引用(不带 {)时,在“java”处缺少“{”。有什么建议我应该尝试吗?
编辑:也尝试过
Reference:
'reference' ':' ('{' values+=QualifiedName (',' values+=QualifiedName)* '}') | ((!'{')values+=QualifiedName);
,但在输入“!”时没有可行的替代方案语法定义错误。
编辑2:我对“逗号分隔列表”没有问题,我单独尝试了这个,效果很好。我唯一的问题是根据“{”字符区分规则的两个部分。
I'm trying to create a grammar that would parse the following:
reference: java.util.String
but as well
reference: {java.util.String, java.lang.Integer}
In other words, I want it to parse both a list of Qualified names but also only one item (not marked by '{' in this case).
What I tried is this:
Reference:
'reference' ':' ('{' values+=QualifiedName (',' values+=QualifiedName)* '}') | (values+=QualifiedName);
However, I am getting an error: missing '{' at 'java', when using the first form of the reference (without {). Any suggestions what I should try?
EDIT: Also tried
Reference:
'reference' ':' ('{' values+=QualifiedName (',' values+=QualifiedName)* '}') | ((!'{')values+=QualifiedName);
but getting a no viable alternative at input '!' error in the grammar definition.
EDIT2: I am not having problems with the "comma separated list", I tried this separatly and it works well. My only problem is distinguishing between the two parts of the rule based on the '{' character.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可以解决问题:
请注意组和替代方案的优先顺序。
This will do the trick:
Please mind the precedencies of groups and alternatives.
我对 Xtext 很陌生,所以尝试一下:
或者
I am quite new to Xtext, so just giving it a try:
or