Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Includes, global constants in DSL files
Includes, global constants in DSL files [message #1698591] Tue, 16 June 2015 14:39 Go to next message
Gary Worsham is currently offline Gary WorshamFriend
Messages: 176
Registered: September 2013
Senior Member
This is probably an idiotic question, but after generating a fairly complex grammar and just using it without lots of modification for a year, my Xtext skills have dropped off a bit.

My grammar includes a rule for a parameter "color", e.g.

('@color' color = STRING)?

What I want to do is have a master list of colors that each of my DSL files can reference. My system is like a visual CAD system where blocks of certain types are all the same color.

So, imagine in the DSL file itself, instead of:

@color "0xff3f05"

I could have something like

#include "colors.txt"
@color "Purply-Pink"

where the mapping from 0xff3f05 to "Purply-Pink" (or whatever it is in reality) takes place in the file colors.txt. Then I can easily adjust the colors for all like blocks at once. Right now I have the constant right in my DSL file and if I want to change it then I do a global search and replace within the project. Which works, but kind of a hassle.
Re: Includes, global constants in DSL files [message #1698606 is a reply to message #1698591] Tue, 16 June 2015 15:55 Go to previous messageGo to next message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 250
Registered: June 2013
Senior Member
Hi Gary,

think all you have to do is to implement this conversion list in the GENERATOR.
Read in the color string and if it does not start with "0x" replace it with the associated color from your colors.txt
Re: Includes, global constants in DSL files [message #1698651 is a reply to message #1698606] Wed, 17 June 2015 00:49 Go to previous messageGo to next message
Gary Worsham is currently offline Gary WorshamFriend
Messages: 176
Registered: September 2013
Senior Member
Hi Uli,

Thanks for the response. I think I see what you mean. The master list of possible color values would be included (imported) into all generated (or non-generated) Java as a reference and then the specific one called out would be inserted at the correct place in the generated code.

My project is a bit of a hybrid. Some of the blocks are coded directly in Java because I did quite a few that way before getting sick of it and figuring out how to use Xtext/Xtend. Since then I've converted many but not all of the original Java based blocks over to my DSL. But some will probably remain Java because they have structures or features that I'm currently too lazy to describe with the DSL. As long as I don't come up with a lot more new blocks that would use those structures, maybe being lazy is worth it.

DL
Re: Includes, global constants in DSL files [message #1699123 is a reply to message #1698651] Sun, 21 June 2015 16:16 Go to previous messageGo to next message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 250
Registered: June 2013
Senior Member
Hi Gary,

just another option which is based that definitions of all files with the same extension are available when you edit a file (if you do not apply a NoScopeProvider).

Define in your grammar some option to define your color substitutes.

The grammar should allow a DSL with just this definition only (!!).

Then allow in your color definition either a STRING or a reference to your ColorsSubstitute Class.

At the end you have COLORS_SUBSTITUES.mydsl
and myDe4finitions.mydsl for all your other definitions
Re: Includes, global constants in DSL files [message #1699288 is a reply to message #1699123] Tue, 23 June 2015 09:07 Go to previous messageGo to next message
Anakreontas Mentis is currently offline Anakreontas MentisFriend
Messages: 85
Registered: October 2014
Member
Hello Uli.

Regarding your first sentence: When one edits a file, are the definitions of all the files in the project with the proper extension available or only those files with the proper extension currently opened in the Eclipse editor? In a test I made, variables declared in other files are not available.

In the DSL I'm working on, a file should have access only to variables declared in included files. Inclusion has the same semantics (and syntax) as in C. Variables declared in other files in the same project should not be visible unless the files are explicitly included. To test how scoping behaves in my implementation, I created a file in the same project containing variable definitions. When another file referenced the variables, the scoping implementation could not resolve them which is what I want.

I would like however to implement your suggestion having a file that defines constants known at runtime which are not specified in any of the project's file. Perhaps I failed to implement your suggestion because variable definitions are not top level declarations (The grammar should allow a DSL with just this definition only (!!).). In the resulting EMF object hierarchy, variables are contained in the root object called View.
Re: Includes, global constants in DSL files [message #1699464 is a reply to message #1699288] Wed, 24 June 2015 12:58 Go to previous message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 250
Registered: June 2013
Senior Member
well AFAIK, all files in your project with yor proper DSL are used for scoping by default.
It's up to you to limit the ScopeProvider to only those files you want to scan. This may be one way to restrict scope to your "include file".
Previous Topic:using common terminal names as keywords
Next Topic:Hexcode terminal vs Named Colors terminal. Terminal structuring problem.
Goto Forum:
  


Current Time: Thu Apr 25 09:07:23 GMT 2024

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

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

Back to the top