|
|
Re: passing additional info to generator [message #1274256 is a reply to message #1273917] |
Fri, 21 March 2014 07:45 |
Uli Merkel Messages: 250 Registered: June 2013 |
Senior Member |
|
|
perhaps a preference page would help you.
See http://xtextcasts.org/episodes/21-preference-page
OR (siehe Eclipse Magazin 3.14 Seite 31):
add in your DSL grammar some "generator_options":
Model:
('generator_options' options+=Option? (',' options+=Option)*)*
modules+=Module+;
Option: name=ID ('=' value=STRING)?;
And evaluate them in the generator:
def universalPreparation(Model sm) {
loadMyOptions(sm.options)
return ""
}
/* now the main thing */
override doGenerate(Resource resource, IFileSystemAccess fsa) {
var String scriptFileName = resource.getURI().lastSegment.toString();
scriptfileName = scriptFileName;
universalPreparation(resource.contents.head as Model)
...;
}
And the generator.xtend has the following 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))
}
[Updated on: Fri, 21 March 2014 08:55] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02940 seconds