Skip to content

Commit

Permalink
Axiom: Added support for mixins
Browse files Browse the repository at this point in the history
Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
  • Loading branch information
tonydamage committed May 29, 2020
1 parent 22b81ca commit 7c50dfd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
Expand Up @@ -55,6 +55,7 @@ public static class Item implements AxiomItemDefinition {

public static final AxiomItemDefinition TARGET = new Item("target", Type.TYPE_REFERENCE, true);
public static final AxiomItemDefinition REF_TARGET = new Item("target", Type.TYPE_DEFINITION, true);
public static final AxiomItemDefinition USES = new Item("uses", Type.TYPE_REFERENCE, true);


private final AxiomIdentifier identifier;
Expand Down
Expand Up @@ -132,10 +132,21 @@ public void apply(Lookup<AxiomIdentifier> context, ActionBuilder<AxiomIdentifier
addFromType(typeDef.get(), superTypeValue.parentValue(), typeDef.get().name());
});
}


},
ITEMS_FROM_MIXIN(items(Item.USES),types(Type.TYPE_REFERENCE)) {

@Override
public void apply(Lookup<AxiomIdentifier> context, ActionBuilder<AxiomIdentifier> action) throws AxiomSemanticException {
Dependency<AxiomTypeDefinition> typeDef =
action.require(
context.onlyItemValue(Item.REF_TARGET, AxiomTypeDefinition.class)
.map(v -> v.get()));
typeDef.unsatisfied(() -> action.error("Supertype is not complete."));
action.apply(superTypeValue -> {
addFromType(typeDef.get(), superTypeValue.parentValue(), typeDef.get().name());
});
}
},
IMPORT_DEFAULT_TYPES(all(), types(Type.MODEL)) {
@Override
public void apply(Lookup<AxiomIdentifier> context, ActionBuilder<AxiomIdentifier> action) throws AxiomSemanticException {
Expand Down
22 changes: 12 additions & 10 deletions infra/axiom/src/main/resources/axiom-lang.axiom
Expand Up @@ -4,10 +4,8 @@ model axiom-lang {

root model {
documentation """
Axiom Model

Declares a new axiom model.
""";
""";
type AxiomModel;
}

Expand All @@ -28,10 +26,8 @@ model axiom-lang {

item root {
documentation """
Root Definition

Root Definition defines allowed root for serialized documents
modeled by Axiom language.
Defines allowed root for serialized documents
modeled by Axiom language.
""";
type AxiomRootDefinition;
}
Expand All @@ -49,7 +45,7 @@ model axiom-lang {
item mixin {
type AxiomMixinDefinition;
documentation """
Mixin Declaration, declares a new global mixin, aset of reusable item
Declares a new global mixin, a set of reusable item
definitions, which can be used in type definitions.
""";
}
Expand Down Expand Up @@ -190,12 +186,20 @@ model axiom-lang {
}

type AxiomTypeReference {
documentation "Type Reference";
argument name;

item name {
documentation "Name of referenced type";
type AxiomIdentifier;
minOccurs 1;
maxOccurs 1;
}
item target {
documentation "Definition of referenced type";
type AxiomTypeDefinition;
minOccurs 1;
maxOccurs 1;
operational true;
}
}
Expand All @@ -213,8 +217,6 @@ model axiom-lang {

// "Type library" (temporary)



type SemanticVersion {
extends string;
}
Expand Down

0 comments on commit 7c50dfd

Please sign in to comment.