xtext 格式化程序发生未知比较失败

unknown comparison failure occurs with xtext formatter

我正在自定义我的 dsl 和 whist 测试的 xtext 格式化程序,我遇到了一个我不明白的奇怪的比较失败。

这是我语法的相关部分:

EisModel:
    'project' '=' project_name=STRING ';' 
    'plcname' '=' plc_name=STRING ';'
    'author' '=' author_name=STRING ';'
    testcases+=Testcase*;
Testcase:
    "testcase" testcase_name=ID '{'
    testblock=Testblock?
    '}';
Testblock:
    'testActive' '=' testActive=BoolConstant ';'
    'blockType' '=' blockType=BlockConstant ';'
    'description' '=' description=STRING ';'
    define=DefineBlock?;
BoolConstant:
    value=('true' | 'false');
BlockConstant:
    value=('FC' | 'FB');

我认为比较失败与终端规则有关,因为我没有在格式化程序中做任何特别的事情。

这是 JUnit 故障跟踪的预期代码:

74  4    S "true"               BoolConstant:value='true'
78  0    H
78  1    S ";"                  Testblock:(';'  )
79  2    H "\n\t"               Whitespace:TerminalRule'WS'
81  9    S "blockType"          Testblock:'blockType'
90  1    H " "                  Whitespace:TerminalRule'WS'
91  1    S "="                  Testblock:( '=' )
92  1    H " "                  Whitespace:TerminalRule'WS'
93  2    S "FC"                 BlockConstant:value='FC'

这是实际代码:

          B BoolConstant         Testblock:testActive=BoolConstant path:Testblock/testActive=Testcase/testblock=EisModel/testcases[0]
74  4     S "true"               BoolConstant:value='true'
          E BoolConstant         Testblock:testActive=BoolConstant path:Testblock/testActive=Testcase/testblock=EisModel/testcases[0]
78  0    H
78  1    S ";"                  Testblock:(';'  )
79  2    H "\n\t"               Whitespace:TerminalRule'WS'
81  9    S "blockType"          Testblock:'blockType'
90  1    H " "                  Whitespace:TerminalRule'WS'
91  1    S "="                  Testblock:( '=' )
92  1    H " "                  Whitespace:TerminalRule'WS'
          B BlockConstant        Testblock:blockType=BlockConstant path:Testblock/blockType=Testcase/testblock=EisModel/testcases[0]
93  2     S "FC"                 BlockConstant:value='FC'
          E BlockConstant        Testblock:blockType=BlockConstant path:Testblock/blockType=Testcase/testblock=EisModel/testcases[0]

区别在于第 74 行和第 93 行。

而且我不知道出了什么问题,甚至不知道哪里可以调整。
有人可以帮忙吗?

这是测试:

@Test def void testTestblock() {
    assertFormatted[
        toBeFormatted = '''
            project="proj";plcname="name";author="Bob"; 
            testcase One {testActive = true ; blockType = FC ;    
            description = "string" ;    }
        '''

        expectation = '''
            project = "proj";
            plcname = "name";
            author = "Bob";
            testcase One {
                testActive = true;
                blockType = FC;
                description = "string";
            }
        '''
    ]
}

如果我在扩展 AbstractFormatter2 的格式化程序 class 中注释掉我的代码,甚至会出现错误,所以我将在这里省略它。

这对我来说听起来像是一个错误。请在 https://github.com/eclipse/xtext-core

举报

解决方法:

BoolConstant:
    value=BooleanValue;
BlockConstant:
    value=BlockValue;
BlockValue:"FC"|"FB";
BooleanValue: "true"|"false";

这里还有一些语法:

EisModel:
    'project' '=' project_name=STRING ';'
    'plcname' '=' plc_name=STRING ';'
    'author' '=' author_name=STRING ';'
    testcases+=Testcase*;

Testcase:
    "testcase" testcase_name=ID '{'
    testblock=Testblock?
    '}';

Testblock:
    'testActive' '=' testActive=BoolConstant ';'
    'blockType' '=' blockType=BlockConstant ';'
    'description' '=' description=STRING ';'
    define=DefineBlock?;

BoolConstant:
    value=BooleanValue;

BlockConstant:
    value=BlockValue;

BlockValue:
    'FC' | 'FB';

BooleanValue:
    'true' | 'false';

DefineBlock:
    'define' '{' direction=DirectionBlock '}' teststeps+=TeststepBlock*;

DirectionBlock:
    input=Input & inout=InOut? & output=Output;

Input:
    name='input' '[' inputVariables+=Variables* ']';

Output:
    name='output' '[' outputVariables+=Variables* ']';

InOut:
    name='inout' '[' inoutVariables+=Variables* ']';

这是另一个比较失败。
预期:

123  5      S "input"              Input:name='input'
128  0      H
128  1      S "["                  Input:'['
129  0      H
129  1      S "]"                  Input:']'
130  0      H
130  6      S "output"             Output:name='output'
136  0      H
136  1      S "["                  Output:'['
137  0      H
137  1      S "]"                  Output:']'

实际:

        B Input'input'         DirectionBlock:input=Input path:DirectionBlock/input=DefineBlock/direction=Testblock/define=Testcase/testblock=EisModel/testcases[0]
123  5       S "input"              Input:name='input'
128  0       H
128  1       S "["                  Input:'['
129  0       H
129  1       S "]"                  Input:']'
        E Input'input'         DirectionBlock:input=Input path:DirectionBlock/input=DefineBlock/direction=Testblock/define=Testcase/testblock=EisModel/testcases[0]
130  0      H
        B Output'output'       DirectionBlock:output=Output path:DirectionBlock/output=DefineBlock/direction=Testblock/define=Testcase/testblock=EisModel/testcases[0]
130  6       S "output"             Output:name='output'
136  0       H
136  1       S "["                  Output:'['
137  0       H
137  1       S "]"                  Output:']'
        E Output'output'       DirectionBlock:output=Output path:DirectionBlock/output=DefineBlock/direction=Testblock/define=Testcase/testblock=EisModel/testcases[0]

差异现在在第 123-129 行和第 130-137 行附近。

编辑

在编辑器中激活格式化程序后,我收到一条我不理解的错误消息。也许其他人会这样做:

Message: 
    Unhandled event loop exception    

Exception Stack Trace:
    java.lang.WhosebugError
        at com.google.common.collect.RegularImmutableMap.get(RegularImmutableMap.java:123)
        at com.google.common.collect.RegularImmutableMap.get(RegularImmutableMap.java:115)
        at org.eclipse.xtext.formatting2.regionaccess.internal.NodeModelBasedRegionAccess.regionForEObject(NodeModelBasedRegionAccess.java:49)
        at org.eclipse.xtext.formatting2.regionaccess.internal.NodeModelBasedRegionAccess.regionForEObject(NodeModelBasedRegionAccess.java:22)
        at org.eclipse.xtext.formatting2.AbstractFormatter2.isInRequestedRange(AbstractFormatter2.java:358)
        at org.eclipse.xtext.formatting2.AbstractFormatter2.shouldFormat(AbstractFormatter2.java:423)
        at org.eclipse.xtext.formatting2.internal.FormattableDocument.format(FormattableDocument.java:186)
        at org.example.eis.formatting2.EisFormatter._format(EisFormatter.java:224)
        at org.example.eis.formatting2.EisFormatter.format(EisFormatter.java:346)

一看java 类:

223 protected void _format(final DirectionBlock directionblock, @Extension final IFormattableDocument document) {
224    document.<DirectionBlock>format(directionblock); 
225 }