XSD -> ecore -> Xtext: How to deal with anyType in Xtext Grammar? [message #1815744] |
Wed, 09 October 2019 13:26  |
Eclipse User |
|
|
|
Searching the forums, I've found this example from 5 years ago:
https://www.eclipse.org/forums/index.php/m/1696134/?srch=xtext+anyType#msg_1696134
I've taken a IEEE standard specified in XSD, read it in and created an ecore model from it. I've also created an Xtext project from that model.
My customers, for whatever reason (and I no longer have the energy to debate with them), hate XML so I've used the Xtext DSL grammar to "yamlize" the data storage.
So far it's been fairly straightforward (although I've not created a model using my DSL and saved as XML, but in theory that should work down the line).
The original XSD makes use of the xsd construct to allow the spec to be extended:
<xs:element name="vendorExtensions">
<xs:complexType>
<xs:sequence>
<xs:any namespace="##any" processContents="lax" maxOccurs="unbounded">
As mentioned in the linked forum post, my default grammar (generated by the new Xtext Project wizard from my ecore model), generates a rule without any content:
VendorExtensionsType returns VendorExtensionsType:
{VendorExtensionsType}
'VendorExtensionsType'
;
And the VendorExtensionsType contains a FeatureMap:
protected FeatureMap any;
I'm at a complete loss for understanding what I can put into my grammar for this rule that will be understood as a FeatureMap
I've tried creating another ecore model where I create classes that extend the VendorExtensionsType, but I can't quite get anything working. (all kinds of weird Xtext messages regarding super etc... can't recall them off the top of my head).
Any tips on where to start? Or any examples of anything like this? The original forum post I linked to went nowhere, so I'm worried.
|
|
|
|
|
Re: XSD -> ecore -> Xtext: How to deal with anyType in Xtext Grammar? [message #1815764 is a reply to message #1815756] |
Thu, 10 October 2019 03:30  |
Eclipse User |
|
|
|
Hi
Have you looked at HUTN, which is a more human friendly form of XML? I understand that the Epsilon project provides an implementation.
More generally you are fighting the eXtensible X in XML which allows major anarchy, only somewhat and confusingly tamed by XSD.
In contrast a given metamodel is not arbitrarily extensible, although you may use inheritance to extend in a disciplined fashion and then define a correspondingly extended DSL.
If you want arbitrary extension, you need to define extension as a regular capability. Using a simplified XML as a familiar but ridiculously unreadable example, you could do something like:
XMLElementName := ID;
XMLAttributeName := ID;
TopLevel := (ElementDef | AtrtributeDef) * XMLElement
ElementDef : 'tag' XMLElementName ';';
AttributeDef : 'tag' XMLAttributeName ';';
XMLElement := 'leftarrow' startTagName= XMLElementName attributes+=XMLAttributes* (( 'rightarrow' elements+= XMLElement 'leftarrow' 'slash' endTagName= XMLElementName 'rightarrow') | ('slash' 'rightarrow'));
XMLAttribute := 'quotes' name=XMLAttributeName value=STRING 'endquotes';
The above allows arbitrary XMLElement and XMLAttribute names to be parsed. Consistency of usage is moved to semantic validation.
Regards
Ed Willink
|
|
|
Powered by
FUDForum. Page generated in 0.03964 seconds