Controlling generator behavior with parameters [message #1790240] |
Thu, 07 June 2018 06:56  |
Eclipse User |
|
|
|
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 #1790299 is a reply to message #1790245] |
Fri, 08 June 2018 03:16  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.07800 seconds