简体   繁体   English

如何限制规则在XTEXT中重复的次数?

[英]How to limit the number of times a rule can repeat in XTEXT?

My language has certain keywords which only accept values of certain length range (say, between 5 and 10 decimal numbers). 我的语言有某些关键字只接受某个长度范围的值(例如,5到10个十进制数)。 This id correct: 这个id正确:

KeyWord = 01234

This is incorrect: 这是不正确的:

KeyWord = 1234

I have a rule; 我有一个规则;

KeyWord:
  'KeyWord' '=' INT+;

How to limit the number of times INT can repeat? 如何限制INT重复的次数? This would so much easier if it was a more regexp-like syntax 如果它是一个更像正则表达式的语法,这将更容易

I would implement this as a validation check instead of trying to fit this in the grammar itself. 我会将其作为验证检查来实现,而不是试图将其纳入语法本身。 See http://www.eclipse.org/Xtext/documentation/2_1_0/050-validation.php http://www.eclipse.org/Xtext/documentation/2_1_0/050-validation.php

This will result in better error recovery and better error messages. 这将导致更好的错误恢复和更好的错误消息。 It even allows quick-fixes. 它甚至允许快速修复。

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

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