We are using Xtext to define the syntax of a complex parameter file.
To give users the most freedom, at some places parameters/keywords can be specified in arbitrary order. The keywords are also optional.
A small example for "Options":
See railway diagram: img16.imageshack.us/img16/6340/optionsy.png
The corresponding grammar rule looks like this:
Options:
options='Options' ((report?='Report' reportType=('Postscript' | 'Contour')?) | noEcho?='NoEcho' |
listMaterialParams?='ListMaterialParams' | listDriftDiffusionParams?='ListDriftDiffusionParams' |
InterpolationSearch?='InterpolationSearch' | singleDipole?='SingleDipole' | dense?='Dense')*;
Parsing works fine, but when the data structure is serialized, the order of the keywords is totally random. This makes it very difficult to read parts where whole blocks are ordered randomly at each save operation.
The file is serialized using this code:
public static String serializePar(Model model) {
Injector in = new ParLegacyStandaloneSetup().createInjectorAndDoEMFRegistration();
Serializer serializer = in.getInstance(Serializer.class);
return serializer.serialize(model, SaveOptions.newBuilder().format().getOptions());
}
Now I would like to ask, if there is a formatter option to specify a keyword priority for a case mentioned above. Or is there a better way to define it in the grammar?
Thanks in advance.
B
[Updated on: Thu, 01 March 2012 11:08]
Report message to a moderator