Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Best practices for defining custom terminals in a dedicated grammar file
Best practices for defining custom terminals in a dedicated grammar file [message #1175093] Thu, 07 November 2013 14:18 Go to next message
Tatiana Fesenko is currently offline Tatiana FesenkoFriend
Messages: 62
Registered: July 2009
Member
Hello!

Creating a dedicated grammar which extends the common Xtext terminals is a recommended approach to introduce custom terminals . However, defining a grammar in just the first step is DSL implementation which should be followed by changes in the mwe2 file and possible Java code customization. Unfortunately, I didn't find any documentation with recipes or best practices how to do it. Can you suggest useful resources?

I am asking because we used this approach in our grammar and we faced several issues with it.
For example, Xtext generates a preferences page for custom terminals which fails to open with com.google.inject.CreationExceptions. It happens because Guice OurTerminalsRuntimeModule extends DefaultRuntimeModule which uses dependencies (e.g. for DocumentPartitioner) that are normally bound to and in the code generated by the Antlr component. And an Antlr component cannot be used for the custom Terminals grammar because it is "without production rules". I looked how this situation is handled in Xtext itself - the preferences page for Xtext Common terminals was simply excluded from the plugin.xml, but it's there in the plugin.xml_gen . I guess we can recommend to comment out the preferences page extension for the custom terminals.

Let's share experience with creating custom terminals and advise best practices here.
Thanks,
Tanya.
Re: Best practices for defining custom terminals in a dedicated grammar file [message #1180984 is a reply to message #1175093] Mon, 11 November 2013 09:38 Go to previous message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
There is not too much code needed for a shared terminals grammar. Most
of it is automatically generated by the individual consuming languages.
E.g. I wouldn't expect any UI contribution for the terminal language.

For our own Terminals we have a minimal config incorporated in the MWE2
workflow for bootstrapping Xtext (last few lines):

http://git.eclipse.org/c/tmf/org.eclipse.xtext.git/tree/devtools/org.eclipse.xtext.bootstrap/src/org/eclipse/xtext/bootstrap/GenerateXtext.mwe2

The ParsetreeConstructorFragment is obsolete. You will need the
generated GrammarAccessFragment. The most reusable manually implemented
component will probably be the IValueConverterService.


Am 07.11.13 15:18, schrieb Tatiana Fesenko:
> Hello!
>
> Creating a dedicated grammar which extends the common Xtext terminals is
> http://stackoverflow.com/questions/5660653/xtext-use-custom-terminals-definitions?answertab=active#tab-top
> . However, defining a grammar in just the first step is DSL
> implementation which should be followed by changes in the mwe2 file and
> possible Java code customization. Unfortunately, I didn't find any
> documentation with recipes or best practices how to do it. Can you
> suggest useful resources?
> I am asking because we used this approach in our grammar and we faced
> several issues with it. For example, Xtext generates a preferences page
> for custom terminals which fails to open with
> com.google.inject.CreationExceptions. It happens because Guice
> OurTerminalsRuntimeModule extends DefaultRuntimeModule which uses
> dependencies (e.g. for DocumentPartitioner) that are normally bound to
> and in the code generated by the Antlr component. And an Antlr component
> cannot be used for the custom Terminals grammar because it is "without
> production rules". I looked how this situation is handled in Xtext
> itself - the preferences page for Xtext Common terminals was simply
> excluded from the plugin.xml, but it's there in the
> http://git.eclipse.org/c/tmf/org.eclipse.xtext.git/tree/plugins/org.eclipse.xtext.ui/plugin.xml_gen
> . I guess we can recommend to comment out the preferences page extension
> for the custom terminals.
>
> Let's share experience with creating custom terminals and advise best
> practices here. Thanks,
> Tanya.


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Previous Topic:Prioritizing rules in Xtext
Next Topic:How does Xtext resolve references? [SOLVED]
Goto Forum:
  


Current Time: Thu Nov 26 10:42:12 GMT 2020

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

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

Back to the top