Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Controlling generator behavior with parameters
Controlling generator behavior with parameters [message #1790240] Thu, 07 June 2018 10:56 Go to next message
Alex Mising name is currently offline Alex Mising nameFriend
Messages: 149
Registered: March 2010
Senior Member
Hi,

I would like to provide a set of parameters that control various aspects of my generator (e.g. tab width to give an example). How does one communicate outside information to the generator?

1) Looking at AbstractGenerator I see that there is an "IGeneratorContext context" argument but that only gives access to a cancellation request indicator to allow you to fast-exit, so it's not of much use. I would want something where I can pass some opaque (to xtext) data that my generator knows how to interpret.

2) I will need to allow parameters to be set via the maven plugin. The documentation I have found here, does not list what other options I can pass as configuration. Does xtext-maven-plugin have a complete reference page with all options? Is there an option where I could define some string that is opaquely passed to the language generator for interpretation?

Thanks!
Alex
Re: Controlling generator behavior with parameters [message #1790241 is a reply to message #1790240] Thu, 07 June 2018 11:02 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
(1) usually such things are done via preferences inside eclipse. or a composent that reeads prefs in eclipse and has another binding in standalone mode that reads from somewhere else.
(2) no there is no docs. you need to read the source ocde. but i am not aware of anything beeing there to support this.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Controlling generator behavior with parameters [message #1790243 is a reply to message #1790241] Thu, 07 June 2018 11:09 Go to previous messageGo to next message
Alex Mising name is currently offline Alex Mising nameFriend
Messages: 149
Registered: March 2010
Senior Member
Thanks for this info.

So, (1) would mean I can only do this in the IDE which is not what I am after. I will download (2) to have a look.

Even if I were to modify the maven plugin to be able to define such a string, it'd need to the generator, meaning xtext runtime needs to be involved.

I guess a quick hack would be to set a system property that the generator looks at and avoid all this.
Re: Controlling generator behavior with parameters [message #1790245 is a reply to message #1790243] Thu, 07 June 2018 11:15 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
the aliternative would to have a service X (singleton) and inject it to the generator and fill it from the maven plugin

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Controlling generator behavior with parameters [message #1790299 is a reply to message #1790245] Fri, 08 June 2018 07:16 Go to previous message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 250
Registered: June 2013
Senior Member
I just extended my grammar as:

Model: {Model}
('generator_options' options+=Option? (',' options+=Option)*)+;
Option: name=ID ('=' value=STRING)?;

In the Generator, I added some Utilities:

// *** advanced Option utilities
static Map<String, String> myOptions = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);

def loadMyOptions(EList<Option> options) {
myOptions.clear
for (Option option : options) {
myOptions.put(option.name, option.value ?: "")
}
return ("")
}

def getMyOption(String key) {
return myOptions.get(key) ?: ""
}

def boolean isMyOption(String key) {
return myOptions.containsKey(key)
}

def boolean isMyOption(String key, String compareValue) {
compareValue.equals(getMyOption(key))
}

def boolean isMyOptionIgnoreCase(String key, String compareValue) {
compareValue.equalsIgnoreCase(getMyOption(key))
}
...
def universalPreparation(Model sm) {
loadMyOptions(sm.options)
return ""
}

and activated this with:

override void doGenerate(Resource resource, IFileSystemAccess fsa) {
var String scriptFileName = resource.getURI().lastSegment.toString();
scriptfileName = scriptFileName;
outFileBase = scriptFileName.substring(0, scriptFileName.lastIndexOf("."));
universalPreparation(resource.contents.head as Model)
fsa.generateFile('DEMO.umevis0.graphml',genDemoVisout())
....


HIH, Uli
Previous Topic:Handling characters that return ecore::EChar and identifiers
Next Topic:How to fetch value from my text
Goto Forum:
  


Current Time: Tue Apr 23 13:46:30 GMT 2024

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

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

Back to the top