Skip to content

Commit

Permalink
Axiom: Added prism language extensions
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 25, 2020
1 parent 94fc8a9 commit 04b6770
Show file tree
Hide file tree
Showing 6 changed files with 2,536 additions and 87 deletions.
Expand Up @@ -56,4 +56,5 @@ public String toString() {
public static IdentifierSpaceKey of(AxiomIdentifier key, Object value) {
return from(ImmutableMap.of(key, value));
}

}
Expand Up @@ -24,7 +24,7 @@


public enum BasicStatementRule implements AxiomStatementRule<AxiomIdentifier> {
/*
/*
REQUIRE_REQUIRED_ITEMS(all(),all()) {
@Override
public void apply(Context<AxiomIdentifier> rule) throws AxiomSemanticException {
Expand Down Expand Up @@ -117,21 +117,13 @@ public void apply(Lookup<AxiomIdentifier> context, ActionBuilder<AxiomIdentifier
Dependency.Search<AxiomItemValue<?>> typeDef = action.require(context.global(AxiomTypeDefinition.IDENTIFIER_SPACE, AxiomTypeDefinition.identifier(type)));
typeDef.notFound(() -> action.error("type '%s' was not found.", type));
typeDef.unsatisfied(() -> action.error("Referenced type %s is not complete.", type));
action.apply(ctx -> {
ctx.replace(typeDef.get());
AxiomItemValue<?> superType = typeDef.get();
// Copy Identifiers
Optional<AxiomItem<?>> identifiers = superType.item(Item.IDENTIFIER_DEFINITION);
if(identifiers.isPresent()) {
ctx.parentValue().mergeItem(identifiers.get());
}// Copy Items
Optional<AxiomItem<?>> items = superType.item(Item.ITEM_DEFINITION);
if(items.isPresent()) {
ctx.parentValue().mergeItem(items.get());
}
action.apply(superTypeValue -> {
superTypeValue.replace(typeDef.get());
addFromType(typeDef.get(), superTypeValue.parentValue());
});
}


},

IMPORT_DEFAULT_TYPES(all(), types(Type.MODEL)) {
Expand Down Expand Up @@ -169,6 +161,7 @@ public void apply(Lookup<AxiomIdentifier> context, ActionBuilder<AxiomIdentifier
});
}
},

APPLY_EXTENSION(all(), types(Type.EXTENSION_DEFINITION)) {

@Override
Expand Down Expand Up @@ -196,26 +189,6 @@ public void apply(Context<AxiomIdentifier> rule) throws AxiomSemanticException {
},
*/
;
/*
ADD_SUPERTYPE(items(), types(Type.TYPE_DEFINITION)) {
@Override
public void apply(Context<AxiomIdentifier> rule) throws AxiomSemanticException {
Optional<AxiomIdentifier> superType = action.optionalChildValue(Item.SUPERTYPE_REFERENCE, AxiomIdentifier.class);
if(superType.isPresent()) {
Requirement<AxiomStatement<?>> req = action.requireGlobalItem(Item.TYPE_DEFINITION, superType.get());
action.apply((ctx) -> {
//ctx.builder().add(Item.SUPERTYPE_REFERENCE, req.get());
});
action.errorMessage(() -> {
if(!req.isSatisfied()) {
return action.error("Supertype %s is not defined", superType.get());
}
return null;
});
}
}
};*/

private final Set<AxiomIdentifier> items;
private final Set<AxiomIdentifier> types;
Expand Down Expand Up @@ -264,4 +237,18 @@ private static ImmutableSet<AxiomIdentifier> all() {
private static IdentifierSpaceKey namespaceId(String uri) {
return IdentifierSpaceKey.of(Item.NAMESPACE.name(), uri);
}

public static void addFromType(AxiomItemValue<?> source, AxiomValueContext<?> target) {
AxiomItemValue<?> superType = source;
// FIXME: Add namespace change if necessary
// Copy Identifiers
Optional<AxiomItem<?>> identifiers = superType.item(Item.IDENTIFIER_DEFINITION);
if(identifiers.isPresent()) {
target.mergeItem(identifiers.get());
}// Copy Items
Optional<AxiomItem<?>> items = superType.item(Item.ITEM_DEFINITION);
if(items.isPresent()) {
target.mergeItem(items.get());
}
}
}
54 changes: 0 additions & 54 deletions infra/axiom/src/main/resources/axiom-lang.axiom
Expand Up @@ -57,26 +57,6 @@ model axiom-lang {
item extension {
type AxiomExtensionDefinition;
}

// TODO move to prism schema; consider renaming to objectType?
item object {
type PrismObjectDefinition;
}

// TODO move to prism schema; consider renaming to containerType?
item container {
type PrismContainerDefinition;
}

// TODO move to prism schema; consider renaming to referenceType?
item reference {
type PrismReferenceDefinition;
}

// TODO move to prism schema
item item {
type PrismItemDefinition;
}
}

type AxiomImportDeclaration {
Expand Down Expand Up @@ -161,21 +141,6 @@ model axiom-lang {
type AxiomIdentifierDefinition;
}

// TODO move to prism schema
item object {
type boolean;
}

// TODO move to prism schema
item container {
type boolean;
}

// TODO move to prism schema
item objectReference {
type boolean;
}

// TODO reconsider this - strictly speaking this is part of "global type+item definition combo"
item itemName {
type AxiomIdentifier;
Expand Down Expand Up @@ -242,23 +207,4 @@ model axiom-lang {
extends string;
}

// TODO move to prism schema; probably should be prism:ObjectDefinition
type PrismObjectDefinition {
extends AxiomTypeDefinition;
}

// TODO move to prism schema; probably should be prism:ContainerDefinition
type PrismContainerDefinition {
extends AxiomTypeDefinition;
}

// TODO move to prism schema; probably should be prism:ReferenceDefinition
type PrismReferenceDefinition {
extends AxiomTypeDefinition;
}

// TODO move to prism schema; probably should be prism:ItemDefinition
type PrismItemDefinition {
extends AxiomItemDefinition;
}
}

0 comments on commit 04b6770

Please sign in to comment.