Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Issues with Formatter2 API and xtext 2.9.x
Issues with Formatter2 API and xtext 2.9.x [message #1720347] Mon, 18 January 2016 02:52 Go to next message
Weihua Fan is currently offline Weihua FanFriend
Messages: 18
Registered: December 2015
Junior Member
I'm developing an expression like language (with left recursive issue)
Everything works fine until I try to add Formatter support to the language

Here's the language definition:
Model:
	types+=Type*;
	
Type:
	name=ID '=' pattern=Pattern ';'
;
	
Pattern: 
	Concat 
;
	
Concat returns Pattern:
	Union (':' actionList=ActionList)? ({Concat.left=current} right=Union (':' actionList=ActionList)?)*
;

Union returns Pattern:
	And ({Union.left=current} '|' right=And)* 
;

And returns Pattern:
	Primary ({And.left=current} '&' right=Primary)*
;

Primary returns Pattern
	:  {Multi} '{' pattern=Pattern '}'  
	|  {Not} '!' pattern=Primary 
	|  {Atomic} pattern=Atomic 
    ;
 
Atomic returns Pattern
	:  {Feature} value=ID
;

ActionList 
	:  featureActions+=FeatureUpdateAction+
;

FeatureUpdateAction
	:  {FeatureUpdate} '+' featureName=ID
;	


Sample language:
patternWithAction = A|B&C:+f1+f2  E  F;
patternWithoutAction = A&B E C|D;


When formatting on patternWithoutAction it works.
When formatting on patternWithAction it throws the following errors:
1195678 [main] ERROR org.eclipse.xtext.ui.editor.formatting2.ContentFormatter$FormattingUnitOfWork  - Error formatting platform:/resource/Test/rule/test.mydsl: null
java.lang.IllegalStateException
	at org.eclipse.xtext.formatting2.regionaccess.internal.NodeModelBasedRegionAccessBuilder.process(NodeModelBasedRegionAccessBuilder.java:219)
	at org.eclipse.xtext.formatting2.regionaccess.internal.NodeModelBasedRegionAccessBuilder.process(NodeModelBasedRegionAccessBuilder.java:210)
	at org.eclipse.xtext.formatting2.regionaccess.internal.NodeModelBasedRegionAccessBuilder.process(NodeModelBasedRegionAccessBuilder.java:210)
	at org.eclipse.xtext.formatting2.regionaccess.internal.NodeModelBasedRegionAccessBuilder.process(NodeModelBasedRegionAccessBuilder.java:210)
	at org.eclipse.xtext.formatting2.regionaccess.internal.NodeModelBasedRegionAccessBuilder.process(NodeModelBasedRegionAccessBuilder.java:210)
	at org.eclipse.xtext.formatting2.regionaccess.internal.NodeModelBasedRegionAccessBuilder.process(NodeModelBasedRegionAccessBuilder.java:210)
	at org.eclipse.xtext.formatting2.regionaccess.internal.NodeModelBasedRegionAccessBuilder.process(NodeModelBasedRegionAccessBuilder.java:210)
	at org.eclipse.xtext.formatting2.regionaccess.internal.NodeModelBasedRegionAccessBuilder.getEObjectToTokensMap(NodeModelBasedRegionAccessBuilder.java:86)
	at org.eclipse.xtext.formatting2.regionaccess.internal.NodeModelBasedRegionAccess.<init>(NodeModelBasedRegionAccess.java:29)
	at org.eclipse.xtext.formatting2.regionaccess.internal.NodeModelBasedRegionAccessBuilder.create(NodeModelBasedRegionAccessBuilder.java:57)
	at org.eclipse.xtext.formatting2.regionaccess.TextRegionAccessBuilder.create(TextRegionAccessBuilder.java:37)
	at org.eclipse.xtext.ui.editor.formatting2.ContentFormatter.initRequest(ContentFormatter.java:126)
	at org.eclipse.xtext.ui.editor.formatting2.ContentFormatter.exec(ContentFormatter.java:88)
	at org.eclipse.xtext.ui.editor.formatting2.ContentFormatter$FormattingUnitOfWork.exec(ContentFormatter.java:57)
	at org.eclipse.xtext.ui.editor.formatting2.ContentFormatter$FormattingUnitOfWork.exec(ContentFormatter.java:1)
	at org.eclipse.xtext.resource.OutdatedStateManager.exec(OutdatedStateManager.java:121)
	at org.eclipse.xtext.ui.editor.model.XtextDocument$XtextDocumentLocker.internalReadOnly(XtextDocument.java:520)
	at org.eclipse.xtext.ui.editor.model.XtextDocument$XtextDocumentLocker.priorityReadOnly(XtextDocument.java:485)
	at org.eclipse.xtext.ui.editor.model.XtextDocument.priorityReadOnly(XtextDocument.java:142)
	at org.eclipse.xtext.ui.editor.formatting2.ContentFormatter.format(ContentFormatter.java:103)
	at org.eclipse.jface.text.source.SourceViewer.doOperation(SourceViewer.java:1023)
	at org.eclipse.jface.text.source.projection.ProjectionViewer.doOperation(ProjectionViewer.java:1501)
	at org.eclipse.ui.texteditor.TextOperationAction$1.run(TextOperationAction.java:128)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
	at org.eclipse.ui.texteditor.TextOperationAction.run(TextOperationAction.java:126)
	at org.eclipse.jface.action.Action.runWithEvent(Action.java:473)
	at org.eclipse.jface.commands.ActionHandler.execute(ActionHandler.java:122)
	at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:90)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
	at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:252)
	at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:234)
	at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:132)
	at org.eclipse.e4.core.commands.internal.HandlerServiceHandler.execute(HandlerServiceHandler.java:152)
	at org.eclipse.core.commands.Command.executeWithChecks(Command.java:493)
	at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:486)
	at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:210)
	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.executeCommand(KeyBindingDispatcher.java:286)
	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.press(KeyBindingDispatcher.java:507)
	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.processKeyEvent(KeyBindingDispatcher.java:558)
	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.filterKeySequenceBindings(KeyBindingDispatcher.java:378)
	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.access$0(KeyBindingDispatcher.java:324)
	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher$KeyDownFilter.handleEvent(KeyBindingDispatcher.java:86)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1105)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4225)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1491)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1514)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1499)
	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1528)
	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1524)
	at org.eclipse.swt.widgets.Canvas.sendKeyEvent(Canvas.java:496)
	at org.eclipse.swt.widgets.Control.doCommandBySelector(Control.java:1060)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:5784)
	at org.eclipse.swt.internal.cocoa.OS.objc_msgSend(Native Method)
	at org.eclipse.swt.internal.cocoa.NSResponder.interpretKeyEvents(NSResponder.java:68)
	at org.eclipse.swt.widgets.Composite.keyDown(Composite.java:594)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:5694)
	at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
	at org.eclipse.swt.widgets.Widget.callSuper(Widget.java:227)
	at org.eclipse.swt.widgets.Widget.windowSendEvent(Widget.java:2130)
	at org.eclipse.swt.widgets.Shell.windowSendEvent(Shell.java:2337)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:5756)
	at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
	at org.eclipse.swt.widgets.Display.applicationSendEvent(Display.java:5193)
	at org.eclipse.swt.widgets.Display.applicationProc(Display.java:5342)
	at org.eclipse.swt.internal.cocoa.OS.objc_msgSend(Native Method)
	at org.eclipse.swt.internal.cocoa.NSApplication.sendEvent(NSApplication.java:128)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3695)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1127)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156)
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:654)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:598)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:139)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:669)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1515)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1488)


Does anyone know what is wrong with my language?
Re: Issues with Formatter2 API and xtext 2.9.x [message #1720624 is a reply to message #1720347] Wed, 20 January 2016 00:27 Go to previous messageGo to next message
Weihua Fan is currently offline Weihua FanFriend
Messages: 18
Registered: December 2015
Junior Member
OK. Finally got it work by myself. If Xtext could use Antlr4 internally in the future everything(left recursive I mean) will be easier.
It seems Xtext will check the container of each node in the AST before formatting. So I try to put ActionPattern between Concat & Union instead of part of Concat. Also I have to explicitly create ActionPattern object (use {ActionPattern}) in ActionPattern rule to avoid the above container check error.

Here's the final version of my language:


Model:
	types+=Type*;
	
Type:
	name=ID '=' pattern=Pattern ';'
;
	
Pattern: 
	Concat 
;
	
Concat returns Pattern:
	ActionPattern ({Concat.left=current} right=ActionPattern)*
;

ActionPattern returns Pattern:
	{ActionPattern} pattern=Union (':' actionList=ActionList)? 
;

Union returns Pattern:
	And ({Union.left=current} '|' right=And)* 
;

And returns Pattern:
	Primary ({And.left=current} '&' right=Primary)*
;

Primary returns Pattern
	:  {Multi} '{' pattern=Pattern '}'  
	|  {Not} '!' pattern=Primary 
	|  {Atomic} pattern=Atomic 
    ;
 
Atomic returns Pattern
	:  {Feature} value=ID
;

ActionList 
	:  featureActions+=FeatureUpdateAction+
;

FeatureUpdateAction
	:  {FeatureUpdate} '+' featureName=ID
;		

Re: Issues with Formatter2 API and xtext 2.9.x [message #1720831 is a reply to message #1720624] Thu, 21 January 2016 10:24 Go to previous messageGo to next message
Moritz Eysholdt is currently offline Moritz EysholdtFriend
Messages: 161
Registered: July 2009
Location: Kiel, Germany
Senior Member
hello Weihua,

thank you for reporting the problem. It looks like you ran into this bug:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=485118

Regarding your comment about Antlr4: Unfortunately Antlr4 doesn't support static detection of grammar ambiguities. Antlr3 does. I find this static analysis more valuable for language engineering than support for left recursion.

regards,
Moritz
Re: Issues with Formatter2 API and xtext 2.9.x [message #1724160 is a reply to message #1720831] Mon, 22 February 2016 03:25 Go to previous message
Weihua Fan is currently offline Weihua FanFriend
Messages: 18
Registered: December 2015
Junior Member
Thank you. Glad to hear it Surprised

Moritz Eysholdt wrote on Thu, 21 January 2016 10:24
hello Weihua,

thank you for reporting the problem. It looks like you ran into this bug:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=485118

Regarding your comment about Antlr4: Unfortunately Antlr4 doesn't support static detection of grammar ambiguities. Antlr3 does. I find this static analysis more valuable for language engineering than support for left recursion.

regards,
Moritz

Previous Topic:Which Xtext JARs can be runtime dependencies for webapp?
Next Topic:Understanding Date Types
Goto Forum:
  


Current Time: Fri Sep 24 11:10:15 GMT 2021

Powered by FUDForum. Page generated in 0.01706 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top