Commit a82df0f9 authored by René Schöne's avatar René Schöne
Browse files

begin with concise grammar

- grammar kept as separate file to compare to old grammar
- parser should be complete
- navigation partly generated using abstract-type-navigation-pp
- working on Generation.jadd
parent 48684df4
Pipeline #11969 failed with stages
in 34 seconds
aspect NewStuff {
/** Tests if EndpointTarget is a TokenEndpointTarget.
* @return 'true' if this is a TokenEndpointTarget, otherwise 'false'
*/
syn boolean EndpointTarget.isTokenEndpointTarget() = false;
eq TokenEndpointTarget.isTokenEndpointTarget() = true;
/** Tests if EndpointTarget is a TypeEndpointTarget.
* @return 'true' if this is a TypeEndpointTarget, otherwise 'false'
*/
syn boolean EndpointTarget.isTypeEndpointTarget() = false;
eq TypeEndpointTarget.isTypeEndpointTarget() = true;
/** Tests if EndpointTarget is a UntypedEndpointTarget.
* @return 'true' if this is a UntypedEndpointTarget, otherwise 'false'
*/
syn boolean EndpointTarget.isUntypedEndpointTarget() = false;
eq UntypedEndpointTarget.isUntypedEndpointTarget() = true;
/** casts a EndpointTarget into a TokenEndpointTarget if possible.
* @return 'this' cast to a TokenEndpointTarget or 'null'
*/
syn TokenEndpointTarget EndpointTarget.asTokenEndpointTarget();
eq EndpointTarget.asTokenEndpointTarget() = null;
eq TokenEndpointTarget.asTokenEndpointTarget() = this;
/** casts a EndpointTarget into a TypeEndpointTarget if possible.
* @return 'this' cast to a TypeEndpointTarget or 'null'
*/
syn TypeEndpointTarget EndpointTarget.asTypeEndpointTarget();
eq EndpointTarget.asTypeEndpointTarget() = null;
eq TypeEndpointTarget.asTypeEndpointTarget() = this;
/** casts a EndpointTarget into a UntypedEndpointTarget if possible.
* @return 'this' cast to a UntypedEndpointTarget or 'null'
*/
syn UntypedEndpointTarget EndpointTarget.asUntypedEndpointTarget();
eq EndpointTarget.asUntypedEndpointTarget() = null;
eq UntypedEndpointTarget.asUntypedEndpointTarget() = this;
}
aspect RagConnectNavigation {
// --- program ---
......
RagConnect ::= ConnectSpecificationFile* Program ;
abstract ConnectSpecification ::= EndpointDefinition* DependencyDefinition* MappingDefinition* ;
ConnectSpecificationFile : ConnectSpecification ::= <FileName> ;
EndpointDefinition ::= <AlwaysApply:boolean> <IndexBasedListAccess:boolean> <WithAdd:boolean> <Send:boolean> EndpointTarget ;
rel EndpointDefinition.Mapping* <-> MappingDefinition.UsedAt*;
abstract EndpointTarget ;
TokenEndpointTarget : EndpointTarget ;
rel TokenEndpointTarget.Token <-> TokenComponent.TokenEndpointTarget* ;
TypeEndpointTarget : EndpointTarget ;
rel TypeEndpointTarget.Type <-> TypeComponent.TypeEndpointTarget* ;
UntypedEndpointTarget : EndpointTarget ::= <TokenOrType> ; // only used by parser
// to be integrated:
//AttributeEndpointTarget : EndpointTarget ::= <Name> ;
//RelationEndpointTarget : EndpointTarget ;
//rel RelationEndpointTarget.Role <-> Role.RelationEndpointTarget* ;
DependencyDefinition ::= <ID>;
rel DependencyDefinition.Source <-> TokenComponent.DependencySourceDefinition*;
rel DependencyDefinition.Target -> Component;
MappingDefinition ::= <ID> FromType:MappingDefinitionType <FromVariableName> ToType:MappingDefinitionType <Content> ;
abstract MappingDefinitionType ::= ;
JavaMappingDefinitionType : MappingDefinitionType ::= Type:JavaTypeUse ;
JavaArrayMappingDefinitionType : MappingDefinitionType ::= Type:JavaTypeUse ;
DefaultMappingDefinition : MappingDefinition ;
/*
Design considerations
- InnerMappingDefinition needed for iteration attribute (first, last) - not easily possible with list-relation
- [OLD] InnerMappingDefinition needed for iteration attribute (first, last) - not possible with list-relation
- [NEW in 1.0.0] no complete intermediate structure, but instead single nodes where applicable
*/
aspect NewStuff {
syn nta JastAddList<MTypeComponent> RagConnect.getRootTypeComponentList() {
JastAddList<MTypeComponent> result = new JastAddList<>();
for (Component child : rootNode.getComponentList()) {
if (child.isTypeComponent()) {
result.add(child.asTypeComponent().toMustache());
}
}
return result;
}
aspect AttributesForMustache {
// --- EndpointDefinition ---
syn String EndpointDefinition.idTokenName() = "InternalRagconnectTopicInList";
// --- MRagConnect ---
eq MRagConnect.getRootTypeComponent(int i).isFirst() = i == 0;
inh boolean MTypeComponent.isFirst();
eq RagConnect.getRootTypeComponentList(int i).isFirst() = i == 0;
syn String MRagConnect.closeMethod() = "ragconnectCloseConnections";
syn String MRagConnect.mqttHandlerAttribute() = "_mqttHandler";
syn String MRagConnect.mqttHandlerField() = "_mqttHandler";
syn String MRagConnect.mqttSetupWaitUntilReadyMethod() = "ragconnectSetupMqttWaitUntilReady";
syn String RagConnect.closeMethod() = "ragconnectCloseConnections";
syn String RagConnect.mqttHandlerAttribute() = "_mqttHandler";
syn String RagConnect.mqttHandlerField() = "_mqttHandler";
syn String RagConnect.mqttSetupWaitUntilReadyMethod() = "ragconnectSetupMqttWaitUntilReady";
syn String MRagConnect.restHandlerAttribute() = "_restHandler";
syn String MRagConnect.restHandlerField() = "_restHandler";
syn String RagConnect.restHandlerAttribute() = "_restHandler";
syn String RagConnect.restHandlerField() = "_restHandler";
syn boolean MRagConnect.hasTreeListEndpoints() = !sendingTreeListEndpoints().isEmpty() || !receivingTreeListEndpoints().isEmpty();
syn List<MTypeEndpointDefinition> MRagConnect.sendingTreeListEndpoints() {
List<MTypeEndpointDefinition> result = new ArrayList<>();
for (var mEndpointDef : getTypeSendDefinitionList()) {
if (mEndpointDef.typeIsList()) {
result.add(mEndpointDef);
syn boolean RagConnect.hasTreeListEndpoints() {
for (EndpointDefinition endpointDef : getEndpointDefinitionList()) {
if (endpointDef.typeIsList()) {
return true;
}
}
return result;
return false;
}
syn List<MTypeEndpointDefinition> MRagConnect.receivingTreeListEndpoints() {
List<MTypeEndpointDefinition> result = new ArrayList<>();
for (var mEndpointDef : getTypeReceiveDefinitionList()) {
if (mEndpointDef.typeIsList()) {
result.add(mEndpointDef);
syn Set<TypeDecl> RagConnect.typesForReceivingListEndpoints() {
Set<TypeDecl> result = new HashSet<>();
for (EndpointDefinition endpointDef : getEndpointDefinitionList()) {
if (endpointDef.typeIsList() && !endpointDef.getSend()) {
result.add(endpointDef.type().getTypeDecl());
}
}
return result;
}
syn List<TypeDecl> MRagConnect.typesForReceivingListEndpoints() {
return receivingTreeListEndpoints().stream()
.map(mEndpointDef -> mEndpointDef.type().getTypeDecl())
.distinct()
.collect(java.util.stream.Collectors.toList());
}
// --- MEndpointDefinition ---
syn String MEndpointDefinition.preemptiveExpectedValue();
syn String MEndpointDefinition.preemptiveReturn();
syn EndpointDefinition MEndpointDefinition.endpointDef();
syn String MEndpointDefinition.firstInputVarName();
syn String MEndpointDefinition.parentTypeName();
syn String MEndpointDefinition.entityName();
syn String MEndpointDefinition.updateMethod();
syn String MEndpointDefinition.writeMethod();
syn String MEndpointDefinition.getterMethod();
syn String EndpointDefinition.preemptiveExpectedValue() = toMustache().preemptiveExpectedValue();
syn String EndpointDefinition.preemptiveReturn() = toMustache().preemptiveReturn();
syn String EndpointDefinition.firstInputVarName() = toMustache().firstInputVarName();
syn String EndpointDefinition.parentTypeName() = toMustache().parentTypeName();
syn String EndpointDefinition.entityName() = toMustache().entityName();
syn String EndpointDefinition.updateMethod() = toMustache().updateMethod();
syn String EndpointDefinition.writeMethod() = toMustache().writeMethod();
syn String EndpointDefinition.getterMethod() = toMustache().getterMethod();
eq MEndpointDefinition.getInnerMappingDefinition(int i).isLast() = i == getNumInnerMappingDefinition() - 1;
eq MEndpointDefinition.getInnerMappingDefinition(int i).inputVarName() = i == 0 ? firstInputVarName() : getInnerMappingDefinition(i - 1).outputVarName();
syn String EndpointDefinition.uniqueSuffix() = getSend() ? "Send" : "Receive";
syn String MEndpointDefinition.connectParameterName() = "uriString";
syn String MEndpointDefinition.connectMethod() = "connect" + entityName();
syn String MEndpointDefinition.internalConnectMethod() = "_internal_" + connectMethod();
syn boolean MEndpointDefinition.isTypeEndpointDefinition() = endpointDef().isTypeEndpointDefinition();
syn String EndpointDefinition.connectParameterName() = "uriString";
syn String EndpointDefinition.connectMethod() = "connect" + entityName();
syn String EndpointDefinition.internalConnectMethod() = "_internal_" + connectMethod();
syn boolean EndpointDefinition.isTypeEndpointDefinition() = endpointDef().isTypeEndpointDefinition();
syn String MEndpointDefinition.disconnectMethod() {
syn String EndpointDefinition.disconnectMethod() {
// TODO unclear. rework, when lookup methods are done.
// if both (send and receive) are defined for an endpoint, ensure methods with different names
String extra;
if (endpointDef().isTokenEndpointDefinition()) {
......@@ -75,21 +72,35 @@ aspect AttributesForMustache {
}
return "disconnect" + extra + entityName();
}
// TODO potentially dangerous because asXEndpointDefinition can return null
syn TokenComponent EndpointDefinition.token() = getEndpointTarget().asTokenEndpointTarget().getToken();
syn TypeComponent EndpointDefinition.type() = getEndpointTarget().asTypeEndpointTarget().getType();
syn String EndpointDefinition.tokenName() = token().getName();
syn String EndpointDefinition.typeName() = type().getName();
syn String EndpointDefinition.typeDeclName() = type().getTypeDecl().getName();
}
syn String MEndpointDefinition.uniqueSuffix();
eq MTokenSendDefinition.uniqueSuffix() = "Send";
eq MTokenReceiveDefinition.uniqueSuffix() = "Receive";
eq MTypeSendDefinition.uniqueSuffix() = "Send";
eq MTypeReceiveDefinition.uniqueSuffix() = "Receive";
aspect OldStuff {
// --- EndpointDefinition ---
syn String EndpointDefinition.idTokenName() = "InternalRagconnectTopicInList";
// TODO potentially dangerous because asXEndpointDefinition can return null
syn TokenComponent MEndpointDefinition.token() = endpointDef().asTokenEndpointDefinition().getToken();
syn TypeComponent MEndpointDefinition.type() = endpointDef().asTypeEndpointDefinition().getType();
syn boolean MEndpointDefinition.alwaysApply() = endpointDef().getAlwaysApply();
syn boolean MEndpointDefinition.typeIsList() = endpointDef().typeIsList();
syn String MEndpointDefinition.tokenName() = token().getName();
syn String MEndpointDefinition.typeName() = type().getName();
syn String MEndpointDefinition.typeDeclName() = type().getTypeDecl().getName();
// --- MEndpointDefinition ---
syn String MEndpointDefinition.preemptiveExpectedValue();
syn String MEndpointDefinition.preemptiveReturn();
syn EndpointDefinition MEndpointDefinition.endpointDef();
syn String MEndpointDefinition.firstInputVarName();
syn String MEndpointDefinition.parentTypeName();
syn String MEndpointDefinition.entityName();
syn String MEndpointDefinition.updateMethod();
syn String MEndpointDefinition.writeMethod();
syn String MEndpointDefinition.getterMethod();
eq MEndpointDefinition.getInnerMappingDefinition(int i).isLast() = i == getNumInnerMappingDefinition() - 1;
eq MEndpointDefinition.getInnerMappingDefinition(int i).inputVarName() = i == 0 ? firstInputVarName() : getInnerMappingDefinition(i - 1).outputVarName();
}
aspect AttributesForMustache {
syn MInnerMappingDefinition MEndpointDefinition.lastDefinition() = getInnerMappingDefinition(getNumInnerMappingDefinition() - 1);
syn String MEndpointDefinition.lastDefinitionToType() = lastDefinition().toType();
syn String MEndpointDefinition.lastResult() = lastDefinition().outputVarName();
......@@ -199,7 +210,6 @@ aspect AttributesForMustache {
// --- MTypeComponent ---
syn String MTypeComponent.name() = getTypeComponent().getName();
inh boolean MTypeComponent.isFirst();
// --- MTokenComponent ---
syn String MTokenComponent.parentTypeName() = getTokenComponent().containingTypeDecl().getName();
......
......@@ -22,10 +22,20 @@ ConnectSpecificationFile connect_specification_file
private Iterable<String> makeMappingDefs(ArrayList<?> raw_mapping_defs) {
return () -> raw_mapping_defs.stream().map(raw -> ((Symbol) raw).value.toString()).iterator();
}
private TokenEndpointDefinition enableAlwaysApply(TokenEndpointDefinition def) {
def.setAlwaysApply(true);
return def;
}
// private TokenEndpointDefinition enableAlwaysApply(TokenEndpointDefinition def) {
// def.setAlwaysApply(true);
// return def;
// }
private EndpointDefinition createEndpointDefinition(
String type_name, String child_name, boolean send,
boolean indexBasedListAccess, boolean withAdd) {
EndpointDefinition result = new EndpointDefinition();
result.setSend(send);
result.setIndexedBasedListAccess(indexBasedListAccess);
result.setWithAdd(withAdd);
result.setTarget(new UntypedEndpointTarget(type_name + "." + child_name));
return result;
}
:} ;
EndpointDefinition endpoint_definition
......@@ -45,44 +55,27 @@ EndpointDefinition endpoint_definition
EndpointDefinition endpoint_definition_type
= SEND ID.type_name DOT ID.child_name
{:
SendUntypedEndpointDefinition result = new SendUntypedEndpointDefinition();
result.setTokenOrType(type_name + "." + child_name);
return result;
:}
| SEND INDEXED ID.type_name DOT ID.child_name
{:
SendUntypedEndpointDefinition result = new SendUntypedEndpointDefinition();
result.setTokenOrType(type_name + "." + child_name);
result.setIndexed(true);
return result;
return createEndpointDefinition(type_name, child_name, true, false, false);
:}
// | SEND INDEXED ID.type_name DOT ID.child_name
// {:
// return createEndpointDefinition(type_name, child_name, true, true, false);
// :}
| RECEIVE ID.type_name DOT ID.child_name
{:
ReceiveUntypedEndpointDefinition result = new ReceiveUntypedEndpointDefinition();
result.setTokenOrType(type_name + "." + child_name);
return result;
return createEndpointDefinition(type_name, child_name, false, false, false);
:}
| RECEIVE INDEXED ID.type_name DOT ID.child_name
{:
ReceiveUntypedEndpointDefinition result = new ReceiveUntypedEndpointDefinition();
result.setTokenOrType(type_name + "." + child_name);
result.setIndexed(true);
return result;
return createEndpointDefinition(type_name, child_name, false, true, false);
:}
| RECEIVE WITH ADD ID.type_name DOT ID.child_name
{:
ReceiveUntypedEndpointDefinition result = new ReceiveUntypedEndpointDefinition();
result.setTokenOrType(type_name + "." + child_name);
result.setWithAdd(true);
return result;
return createEndpointDefinition(type_name, child_name, false, false, true);
:}
| RECEIVE INDEXED WITH ADD ID.type_name DOT ID.child_name
{:
ReceiveUntypedEndpointDefinition result = new ReceiveUntypedEndpointDefinition();
result.setTokenOrType(type_name + "." + child_name);
result.setIndexed(true);
result.setWithAdd(true);
return result;
return createEndpointDefinition(type_name, child_name, false, true, true);
:}
;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment