[英]Error highlights in every line when grammar breaks somewhere in Xtext editor
[英]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]
重現步驟:
語法:
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方面的錯誤?
附加信息
我為此奮斗了幾天,並收集了一些有趣的信息:
NullPointerException
。
PartialParsingHelper.reparse(IParser parser, IParseResult prev, ReplaceRegion cr)
會有奇怪的行為 Statemachine.eSet()
而不是Variable.eSet()
ClassCastException
來自相等的功能ID:
StateMachine.vars
具有功能ID == 0 Variable.value
具有功能ID == 0 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
的補丁。 要解決此問題:
public Class bindIPartialParserHelper()
來注冊此類(您的項目中一個頗受尊敬的類,擴展了org.eclipse.xtext.service.DefaultRuntimeModule) 問題在於重新解析您的語言中已經解析的部分:未正確設置舊元素的父容器。 新元素與舊元素鏈接,而不是與舊元素的父鏈接。
我想您已經自己弄清楚了,但是此說明可能會幫助下一個遇到相同問題的人。
Xtext團隊確認這是2.4.x版本的錯誤。 有關錯誤修正的更多詳細信息和通知,請參閱相關問題 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.