Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » XSD -> ecore -> Xtext: How to deal with anyType in Xtext Grammar?
XSD -> ecore -> Xtext: How to deal with anyType in Xtext Grammar? [message #1815744] Wed, 09 October 2019 17:26 Go to next message
Brandon Lewis is currently offline Brandon LewisFriend
Messages: 170
Registered: May 2012
Senior Member
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 #1815745 is a reply to message #1815744] Wed, 09 October 2019 17:30 Go to previous messageGo to next message
Brandon Lewis is currently offline Brandon LewisFriend
Messages: 170
Registered: May 2012
Senior Member
Not sure what forum this is best to post in. I don't mind moving it to the Xtext forum, but it's rather "EMFy" so I think they'd argue it should be here.
Re: XSD -> ecore -> Xtext: How to deal with anyType in Xtext Grammar? [message #1815756 is a reply to message #1815745] Wed, 09 October 2019 18:59 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30692
Registered: July 2009
Senior Member
Well, I'd say you're kind of hosed because "<xs:any namespace="##any" processContents="lax" maxOccurs="unbounded">" pretty much specifies, "allow arbitrary XML content here". The namespace of "##any" specifies what you'd think, i.e., anything, and "lax" specified that there doesn't even need to be a schema to validate that the XML content conforms to anything meaningful or well-defined. So if you're really needing to embed such any-old-crappy XML content in some other DSL, you can pretty much conclude that arbitrary XML content is not going to embed in a DSL with its own well-defined grammar. Even if you replace "FeatureMap any", with "EObject[] anything", it's still a problem that there is no grammar to map the content in the instance to some modeled structure (and that's already assuming that "strict" is specified instead of "lax".
Re: XSD -> ecore -> Xtext: How to deal with anyType in Xtext Grammar? [message #1815764 is a reply to message #1815756] Thu, 10 October 2019 07:30 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6538
Registered: July 2009
Senior Member
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
Previous Topic:custom createItemPropertyDescriptor
Next Topic:Loading ecore and XMI: Class is not found or is abstract
Goto Forum:
  


Current Time: Sat Dec 14 00:54:39 GMT 2019

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

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

Back to the top