我有一个简单的小语法,当我尝试生成 Xtext 人工制品时,它不断给出多种选择错误。语法是:
grammar org.xtext.example.hyrule.HyRule with org.eclipse.xtext.xbase.Xbase
generate hyRule (You can only use links to eclipse.org sites while you have fewer than 25 messages )
Start:
rules+=Rule+
;
Rule:
'FOR''PAYLOAD'payload=PAYLOAD'ELEMENTS' elements+=JvmFormalParameter+'CONSTRAINED' 'BY' expressions+= XExpression*;
PAYLOAD:
"Stacons"|"PFResults"|"any"
;
我得到的确切错误是:
![warning(200): ../org.xtext.example.hyrule/src-gen/org/xtext/example/hyrule/parser/antlr/internal/InternalHyRule.g:3197:2: Decision can match input such as "{RULE_ID, '=>', '('}" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
error(201): ../org.xtext.example.hyrule/src-gen/org/xtext/example/hyrule/parser/antlr/internal/InternalHyRule.g:3197:2: The following alternatives can never be matched: 2][1]
我附上了antlrworks中生成的antlr语法的语法图,可以清楚地看到多种备选方案(JvmFormalParameter可以通过JvmTypeReference或ValidID规则匹配RULE_ID)。
所以看起来 JvmFormalParameter 是模棱两可的......为我的愚蠢道歉,但有人能指出我错过了什么吗?在我的语法中使用 JvmFormalParameter 规则时,是否有某种方法可以克服这种歧义?