xtext nested {}决策可以匹配输入,例如"'}'"使用多种替代品

时间:2015-06-29 13:53:44

标签: nested grammar antlr3 xtext

我是xtext(antlr)的新手,并且不明白为什么IconType'}'之间存在歧义。和WindowType'}'。

warning(200): ../org.simsulla.tools.ui.gui/src-gen/org/simsulla/tools/ui/gui/parser/antlr/internal/InternalGui.g:137:1: Decision can match input such as "'windowType'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): ../org.simsulla.tools.ui.gui.ui/src-gen/org/simsulla/tools/ui/gui/ui/contentassist/antlr/internal/InternalGui.g:117:38: Decision can match input such as "'windowType' '=' '{' 'name' '=' RULE_ID 'iconType' '=' '{' 'name' '=' RULE_ID 'spriteType' '=' RULE_STRING 'Orientation' '=' RULE_STRING '}' '}'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input

这是我的语法

Ui:
    guiTypes+=GuiTypes+;

GuiTypes:
    windowType+=WindowType+
;

WindowType:
    'windowType' '=' '{'
        'name' '=' name=STRING
        iconType+=IconType* 
    '}'
;

IconType:
    'iconType' '=' '{'
        'name' '=' name=STRING
        'spriteType' '=' spriteType=STRING
        'Orientation' '=' Orientation=STRING
    '}'
;

1 个答案:

答案 0 :(得分:1)

语法片段有多种方式重复WindowType

  • UiGuiTypes派生到多个WindowType个实例,或
  • Ui派生到多个GuiTypes个实例,其中每个实例都派生为WindowType
  • 上述任意组合。

因此给定的输入对应于多个不同的解析树。语法因此含糊不清。