Flexmi: new version of the YAML flavour#222
Conversation
|
I slept on this, and realised it would be possible to simplify the flavour (and avoid
This is much easier to explain, and the YAML docs look pretty natural to me. This is an example of a small Ecore model with an EPackage and two EClasses: $nsuri: http://www.eclipse.org/emf/2002/Ecore
package:
name: myPackage
classes:
- name: Sport
- name: Basketball
supertype: Sport |
bb9db28 to
9514761
Compare
|
On further thought, the fact that we cannot repeat keys in YAML means that without <?xml version="1.0"?>
<?nsuri http://www.eclipse.org/emf/2002/Ecore?>
<class name="c1">
<eref name="r1" />
<eattr name="a1" />
<eref name="r2" />
</class>I have pushed a change reimplementing $nsuri: http://www.eclipse.org/emf/2002/Ecore
class:
name: c1
features:
- $type: eref
name: r1
- $type: eattr
name: a1
- $type: eref
name: r2Note that the use of the If we didn't care about $nsuri: http://www.eclipse.org/emf/2002/Ecore
class:
name: c1
eref:
- name: r1
- name: r2
eattr:
- name: a1 |
|
Likewise, for this metamodel: And this XML example: It could be written in the YAML flavour like this: ?nsuri: comps
component:
in:
integer: {name: p1}
boolean: {name: p2}
out:
ports:
- $type: integer
name: p3
- $type: boolean
name: p4
- $type: integer
name: p5Alternatively, to save some space, we could assume most of the out ports are integer ones, and shorten the YAML to: ?nsuri: comps
component:
in:
integer: {name: p1}
boolean: {name: p2}
out:
integer:
- name: p3
- $type: boolean
name: p4
- name: p5 |
0b78f13 to
34474bc
Compare
Closes #21
This PR changes the way we parse YAML, by using
yaml.loadinstead ofyaml.compose(using a custom SafeConstructor to track the original locations in the YAML file that the deserialised maps, lists, and their elements come from). This makes it possible to use some nice YAML features like merge tags (<<: *foo) and anchors/references.It also changes the style to match that of #21. The main features of the new style are as follows:
<root><elem1/>...<elemN/></root>.<__ attributes>...children...</__>. The aim would be to have YAML guess the type based on the names of the features in the future, but for now you can use the$typekey to specify the name of the XML element that would be generated.$type). If it's$nsurior?nsuri, it is added as a sibling of the element being built from the mapping. Otherwise, it becomes a child of the element being built.$typekey, in which case that is used.This has been enough to pass all the tests in the Flexmi test suite (after rewriting the YAML files). In fact, from my testing, I think
$typeis usually only needed for the root mapping, and for templates (where the context is harder to control).