簡體   English   中英

生成的編輯器中的異常:Xtext錯誤或語法錯誤?

[英]Exception in generated editor: Xtext bug or error in grammar?

轉移到Xtext 2.4.2和Eclipse Kepler之后,我們的DSL編輯器出現了問題。 之前一切都工作正常(Xtext 2.3.x,Juno)。

當我們編輯初始化列表時,我們的DSL編輯器將引發ClassCastException: [1,2,3] Xtext錯誤彈出窗口

重現步驟:

  1. 創建一個新的“ Xtext State-Machine Example”項目
  2. 使用下面的語法編輯語法
  3. 刪除軟件包org.eclipse.xtext.example.fowlerdsl.generator(它將在4重新生成。)
  4. 運行org.eclipse.xtext.example.fowlerdsl.GenerateStatemachine.mwe2工作流程
  5. 運行Eclipse應用程序
  6. 在一個空項目中創建一個新文件(example.statemachine)並復制以下內容

語法:

grammar org.eclipse.xtext.example.fowlerdsl.Statemachine
    with org.eclipse.xtext.common.Terminals
generate statemachine "http://www.eclipse.org/xtext/example/fowlerdsl/Statemachine"

Statemachine : {Statemachine}
    (vars += VarDeclWithOptionalInit)*
;
VarDeclWithOptionalInit returns Variable:
    VarDecl ('=' value=AstExpression)?
;
VarDecl returns Variable:
    'var' name = ID
;
AstExpression:
      ExpressionList
    | {AstExpression} INT
;
ExpressionList:
    '[' expressions+=AstExpression (',' expressions+=AstExpression)* ']'
;

example.statemachine的內容

//Adding space between chars inside [] cause Exception
var example1 = [1, 2, 3]

//Doing the same in [10, 20] or [30, 40] is Ok, but modifying
//the top-level list cause the Exception
var example2 = [[10, 20], 0, [30, 40], 1, 2]

我認為示例文件的內容是正確的。 但是,當我使用新值編輯列表時,或者在逗號或值周圍添加空格時,編輯器會從XtextReconcilierJob中彈出帶有ClassCastException的錯誤。

您認為我的語法有問題嗎,還是Xtext方面的錯誤?

附加信息

我為此奮斗了幾天,並收集了一些有趣的信息:

  • 在該示例中,編輯器僅在編輯頂級列表中的元素時拋出,而不是內部列表中的元素時拋出(請參見example2變量)
  • 在我的測試中,有時會在調用堆棧中更早地拋出NullPointerException
    • 我懷疑方法PartialParsingHelper.reparse(IParser parser, IParseResult prev, ReplaceRegion cr)會有奇怪的行為
    • 此方法在模型中找到當前已修改元素的父級,以使用新值對此調用eSet()。 但是在我們的例子中,它嘗試調用Statemachine.eSet()而不是Variable.eSet()
    • ClassCastException來自相等的功能ID:
      • StateMachine.vars具有功能ID == 0
      • Variable.value具有功能ID == 0
      • 但是2個功能的類型不同
    • 如果我在Variable添加一些特征BEFORE值,則拋出的Exception(較早)是NullPointerException ,因為StateMachine僅具有2個特征(0和1)時Variable.value具有特征id == 2或3

錯誤的StackTrace:

Thread [Worker-2] (Suspended (exception ClassCastException))
    StatemachineImpl.eSet(int, Object) line: 128
    StatemachineImpl(BasicEObjectImpl).eSet(EStructuralFeature, Object) line: 1071
    PartialParsingHelper.reparse(IParser, IParseResult, ReplaceRegion) line: 161
    StatemachineParser(AbstractAntlrParser).doReparse(IParseResult, ReplaceRegion) line: 136
    StatemachineParser(AbstractParser).reparse(IParseResult, ReplaceRegion) line: 48
    LazyLinkingResource(XtextResource).update(int, int, String) line: 220
    XtextDocumentReconcileStrategy.doReconcile(IRegion) line: 125
    XtextDocumentReconcileStrategy.reconcile(IRegion) line: 55
    XtextReconciler.doRun(XtextResource, IProgressMonitor) line: 329
    XtextReconciler.access$3(XtextReconciler, XtextResource, IProgressMonitor) line: 316
    XtextReconciler$1.process(XtextResource) line: 273
    XtextReconciler$1.process(Object) line: 1
    XtextReconciler$1(IUnitOfWork$Void<T>).exec(T) line: 36
    XtextDocument$XtextDocumentLocker(AbstractReadWriteAcces<P>).modify(IUnitOfWork<T,P>) line: 81
    XtextDocument$XtextDocumentLocker.modify(IUnitOfWork<T,XtextResource>) line: 201
    XtextDocument.internalModify(IUnitOfWork<T,XtextResource>) line: 98
    XtextReconciler.run(IProgressMonitor) line: 270
    Worker.run() line: 53

xText bugzilla中已經存在錯誤修正。 它是org.eclipse.parser.impl.PartialParsingHelper的補丁。 要解決此問題:

  1. 補丁中獲取文件。
  2. 將內容放在xText項目中的單獨類中
  3. 通過在RuntimeModule中重寫public Class bindIPartialParserHelper()來注冊此類(您的項目中一個頗受尊敬的類,擴展了org.eclipse.xtext.service.DefaultRuntimeModule)

問題在於重新解析您的語言中已經解析的部分:未正確設置舊元素的父容器。 新元素與舊元素鏈接,而不是與舊元素的父鏈接。

我想您已經自己弄清楚了,但是此說明可能會幫助下一個遇到相同問題的人。

Xtext團隊確認這是2.4.x版本的錯誤。 有關錯誤修正的更多詳細信息和通知,請參閱相關問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM