Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Enable or disable grammatical rule by file extension
icon5.gif  Enable or disable grammatical rule by file extension [message #1711892] Tue, 20 October 2015 09:20 Go to next message
Peter Obermann is currently offline Peter ObermannFriend
Messages: 17
Registered: July 2015
Junior Member
Hello there,

I would like to enable or disable a grammatical rule by file extension. Is this possible? or do I have to create a completely new project? Sad

The grammar rule (HI and HELLO) should be activated at * .mydsl file extension. When file extension * .mydsl1 grammar should be disabled rule HELLO.

Thanks in advance!

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:
	greetings+=Greeting*;
	
Greeting:
	HELLO | HI
;
	
HELLO:	'Hello' name=ID '!';
HI   :  'Hi' name=ID '!';
Re: Enable or disable grammatical rule by file extension [message #1711928 is a reply to message #1711892] Tue, 20 October 2015 10:36 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
Senior Member

You can't disable that in the grammar, but you can simulate the behavior, so the effect will be the same for the end user. Do this by implementing a semantic validation rule for HELLO: If the EObjects's resource file extension is mydsl1, then create an error. Further, tweak the content assist to suppress the 'Hello' keyword if the resource file extension is mydsl1.

As an effect, the user does not see that he could enter 'Hello' where it would by syntactically possible, and if he uses it anyway, he gets a validation error after parsing.

HTH,
~Karsten


Need professional support for Xtext, EMF, Eclipse IDE?
Go to: http://devhub.karakun.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: Enable or disable grammatical rule by file extension [message #1712075 is a reply to message #1711928] Wed, 21 October 2015 08:37 Go to previous messageGo to next message
Peter Obermann is currently offline Peter ObermannFriend
Messages: 17
Registered: July 2015
Junior Member
Hello Karsten,
Thank you for your response. The validation worked.

Unfortunately does not work after enlargement refactoring. In the added file type is an error message. Sad

many greetings

change in the plugin.xml:
    
    <extension
            point="org.eclipse.ui.editors">
        <editor         class="org.xtext.example.mydsl.ui.MyDslExecutableExtensionFactory:org.eclipse.xtext.ui.editor.XtextEditor"
            contributorClass="org.eclipse.ui.editors.text.TextEditorActionContributor"
            default="true"
            extensions="mydsl,mydsl1"
            id="org.xtext.example.mydsl.MyDsl"
            name="MyDsl Editor">
        </editor>
    </extension>



!MESSAGE org.eclipse.xtext.ui.refactoring.ui.DefaultRenameElementHandler  - Error initializing refactoring
!STACK 0
java.lang.NullPointerException
	at org.eclipse.xtext.ui.refactoring.ui.DefaultRenameElementHandler.isRefactoringEnabled(DefaultRenameElementHandler.java:133)
	at org.eclipse.xtext.ui.refactoring.ui.DefaultRenameElementHandler$1.exec(DefaultRenameElementHandler.java:81)
	at org.eclipse.xtext.ui.refactoring.ui.DefaultRenameElementHandler$1.exec(DefaultRenameElementHandler.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.refactoring.ui.DefaultRenameElementHandler.execute(DefaultRenameElementHandler.java:72)
	at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:294)
	at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:90)
	at sun.reflect.GeneratedMethodAccessor56.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:55)
	at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:247)
	at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:229)
	at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:132)
	at org.eclipse.e4.core.commands.internal.HandlerServiceHandler.execute(HandlerServiceHandler.java:149)
	at org.eclipse.core.commands.Command.executeWithChecks(Command.java:499)
	at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508)
	at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:210)
	at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.executeItem(HandledContributionItem.java:825)
	at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.handleWidgetSelection(HandledContributionItem.java:701)
	at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.access$6(HandledContributionItem.java:685)
	at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem$4.handleEvent(HandledContributionItem.java:613)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4199)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1467)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1490)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1475)
	at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1279)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4042)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3669)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1151)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1032)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:148)
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:636)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:579)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:135)
	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:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:648)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:603)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1465)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1438)


index.php/fa/23633/0/
  • Attachment: error.png
    (Size: 108.25KB, Downloaded 607 times)
Re: Enable or disable grammatical rule by file extension [message #1712079 is a reply to message #1712075] Wed, 21 October 2015 08:48 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14669
Registered: July 2009
Senior Member
Hi,

there are more than one places where the file extension in involved so
are you sure you did the registration for the multiple file extensions right
(editing the workflow, regenerate and merge/copy plugin.xml_gen to plugin.xml)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Enable or disable grammatical rule by file extension [message #1712101 is a reply to message #1712079] Wed, 21 October 2015 10:26 Go to previous messageGo to next message
Peter Obermann is currently offline Peter ObermannFriend
Messages: 17
Registered: July 2015
Junior Member
Hello, it works now. Smile

Many thanks.
Greeting
Re: Enable or disable grammatical rule by file extension [message #1712137 is a reply to message #1712079] Wed, 21 October 2015 13:32 Go to previous messageGo to next message
Peter Obermann is currently offline Peter ObermannFriend
Messages: 17
Registered: July 2015
Junior Member
Hello there,

ask another Smile How can I use another Java project in Xtext Framework?

I have an external class that information for both UI project and also for the Validation has.

Thanks in advance. Very Happy

Example:
index.php/fa/23637/0/
  • Attachment: Project.png
    (Size: 309.71KB, Downloaded 596 times)
Re: Enable or disable grammatical rule by file extension [message #1712142 is a reply to message #1712137] Wed, 21 October 2015 13:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14669
Registered: July 2009
Senior Member
just edit the manifest of the data project and make it export the package.
edit the manifest of the mydsl project and add a dependency to the data plugin


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Enable or disable grammatical rule by file extension [message #1712143 is a reply to message #1712142] Wed, 21 October 2015 13:57 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14669
Registered: July 2009
Senior Member
p:S: you many need to configure the data project as plugin project (rightklick configure)

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Enable or disable grammatical rule by file extension [message #1712186 is a reply to message #1712143] Wed, 21 October 2015 19:56 Go to previous message
Peter Obermann is currently offline Peter ObermannFriend
Messages: 17
Registered: July 2015
Junior Member
Hi Christian ,

thanks it works . Smile

Many greetings
Previous Topic:Assertion failed for unordered group
Next Topic:Handling terminal conflicts
Goto Forum:
  


Current Time: Sat Apr 27 02:29:45 GMT 2024

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

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

Back to the top