Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Rules in another file
Rules in another file [message #673509] Mon, 23 May 2011 22:09 Go to next message
Eclipse User is currently offline Eclipse UserFriend
Messages: 7
Registered: April 2011
Junior Member
Hello. I'm new to XText (started looking into it this week) so I could be posting some questions that may be somewhat basic...

Can I define rule in a separate file and refer to them in my main xtext model?
For example, I may have a separate build process for our compiler generate a file(.xtext file??) with list of literal keywords as enums or basic datatype rule:

StringType:
  'empty' | STRING;

enum MyType:
  type1 | type2 | type3;

enum MyCommand:
  command1 | command2 | command3;


then refer to them in the main xtext model:

StringVar:
  'var' name=ID '=' value=StringType;
MyTypeVar:
  'var' name=ID '=' value=MyType';'?;


1. What format should the output file be? .xtext file? jar package?
2. Would I place the xtext file next to the main model? Or, import the jar package?
3. I would import it using resource URI?
Re: Rules in another file [message #673520 is a reply to message #673509] Mon, 23 May 2011 23:19 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
A grammar can import another grammar (in .xtext syntax), so this works.
You can either generate a new model that is a combination of both
grammars, or set up your language to use a combination of existing and
generated models. You can configure this in your mwe/mwe2 workflow.

- henrik

On 5/24/11 12:09 AM, forums-noreply@eclipse.org wrote:
> Hello. I'm new to XText (started looking into it this week) so I could
> be posting some questions that may be somewhat basic...
>
> Can I define rule in a separate file and refer to them in my main xtext
> model?
> For example, I may have a separate build process for our compiler
> generate a file(.xtext file??) with list of literal keywords as enums or
> basic datatype rule:
>
>
> StringType:
> 'empty' | STRING;
>
> enum MyType:
> type1 | type2 | type3;
>
> enum MyCommand:
> command1 | command2 | command3;
>
>
> then refer to them in the main xtext model:
>
>
> StringVar:
> 'var' name=ID '=' value=StringType;
> MyTypeVar:
> 'var' name=ID '=' value=MyType';'?;
>
>
> 1. What format should the output file be? .xtext file? jar package?
> 2. Would I place the xtext file next to the main model? Or, import the
> jar package?
> 3. I would import it using resource URI?
Re: Rules in another file [message #673566 is a reply to message #673520] Tue, 24 May 2011 06:34 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

as Henrik says, single inheritance is possible (i.e. one grammar extends another). Note that you already use the default terminals that way (grammar X with Y). However, it is not the simplest thing to do when starting off with Xtext (as it is not a matter of referring to another xtext file but to a complete language infrastructure that has to exist).
Re: Rules in another file [message #673694 is a reply to message #673566] Tue, 24 May 2011 13:43 Go to previous message
Eclipse User is currently offline Eclipse UserFriend
Messages: 7
Registered: April 2011
Junior Member
Thanks for your replies. It seems kind of weird that they would be distinguished as separate grammars. I merely want to modularize the part of it so that the file with the literal keyword declaration can be simply dropped in and generated as one grammar.

Quote:

You can either generate a new model that is a combination of both grammars, ...
You can configure this in your mwe/mwe2 workflow.


Is there an example of this that I can take a look somewhere?

Thank you.
Previous Topic:Xtext Job in Switzerland
Next Topic:Support for language requiring preprocessing/macro expansion
Goto Forum:
  


Current Time: Fri Apr 19 23:50:06 GMT 2024

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

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

Back to the top