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

WIP: Choose protocol at runtime (not in DSL).

- changed semantics of ViaTest slightly (setting same value for inputBoth does not change to newly send value as the "FromMqtt-" and "FromRest-" part is not prepended, and therefore it stays the same)
parent adc5e0a8
...@@ -24,44 +24,37 @@ aspect Analysis { ...@@ -24,44 +24,37 @@ aspect Analysis {
} }
// --- isAlreadyDefined --- // --- isAlreadyDefined ---
syn boolean TokenEndpointDefinition.isAlreadyDefined() { syn boolean TokenEndpointDefinition.isAlreadyDefined() = lookupTokenEndpointDefinitions(getToken()).size() > 1;
java.util.List<TokenEndpointDefinition> definitions = lookupTokenEndpointDefinitions(getToken());
java.util.Set<String> protocols = definitions
.stream()
.map(TokenEndpointDefinition::protocol)
.collect(java.util.stream.Collectors.toSet());
return definitions.size() > protocols.size();
}
syn boolean DependencyDefinition.isAlreadyDefined() = lookupDependencyDefinition(getSource().containingTypeDecl(), getID()) != this; syn boolean DependencyDefinition.isAlreadyDefined() = lookupDependencyDefinition(getSource().containingTypeDecl(), getID()) != this;
// --- protocol --- // // --- protocol ---
syn String TokenEndpointDefinition.protocol(); // syn String TokenEndpointDefinition.protocol();
eq ReceiveFromMqttDefinition.protocol() = "mqtt"; // eq ReceiveFromMqttDefinition.protocol() = "mqtt";
eq SendToMqttDefinition.protocol() = "mqtt"; // eq SendToMqttDefinition.protocol() = "mqtt";
eq ReceiveFromRestDefinition.protocol() = "rest"; // eq ReceiveFromRestDefinition.protocol() = "rest";
eq SendToRestDefinition.protocol() = "rest"; // eq SendToRestDefinition.protocol() = "rest";
// --- usesPROTOCOL ---
syn boolean RagConnect.usesMqtt() = !mqttEndpointDefinitions().isEmpty();
syn boolean RagConnect.usesRest() = !restEndpointDefinitions().isEmpty();
// --- mqttEndpointDefinitions --- // // --- usesPROTOCOL ---
coll java.util.List<TokenEndpointDefinition> RagConnect.mqttEndpointDefinitions() [new java.util.ArrayList<>()] root RagConnect; // syn boolean RagConnect.usesMqtt() = !mqttEndpointDefinitions().isEmpty();
ReceiveFromMqttDefinition contributes this // syn boolean RagConnect.usesRest() = !restEndpointDefinitions().isEmpty();
to RagConnect.mqttEndpointDefinitions()
for ragconnect();
SendToMqttDefinition contributes this
to RagConnect.mqttEndpointDefinitions()
for ragconnect();
// --- restEndpointDefinitions --- // // --- mqttEndpointDefinitions ---
coll java.util.List<TokenEndpointDefinition> RagConnect.restEndpointDefinitions() [new java.util.ArrayList<>()] root RagConnect; // coll java.util.List<TokenEndpointDefinition> RagConnect.mqttEndpointDefinitions() [new java.util.ArrayList<>()] root RagConnect;
ReceiveFromRestDefinition contributes this // ReceiveFromMqttDefinition contributes this
to RagConnect.restEndpointDefinitions() // to RagConnect.mqttEndpointDefinitions()
for ragconnect(); // for ragconnect();
SendToRestDefinition contributes this // SendToMqttDefinition contributes this
to RagConnect.restEndpointDefinitions() // to RagConnect.mqttEndpointDefinitions()
for ragconnect(); // for ragconnect();
//
// // --- restEndpointDefinitions ---
// coll java.util.List<TokenEndpointDefinition> RagConnect.restEndpointDefinitions() [new java.util.ArrayList<>()] root RagConnect;
// ReceiveFromRestDefinition contributes this
// to RagConnect.restEndpointDefinitions()
// for ragconnect();
// SendToRestDefinition contributes this
// to RagConnect.restEndpointDefinitions()
// for ragconnect();
syn boolean MappingDefinitionType.assignableTo(JavaTypeUse target); syn boolean MappingDefinitionType.assignableTo(JavaTypeUse target);
eq JavaMappingDefinitionType.assignableTo(JavaTypeUse target) = getType().assignableTo(target); eq JavaMappingDefinitionType.assignableTo(JavaTypeUse target) = getType().assignableTo(target);
......
//TypeComponentMustache ; //TypeComponentMustache ;
//rel TypeComponentMustache.TypeComponent -> TypeComponent ; //rel TypeComponentMustache.TypeComponent -> TypeComponent ;
MRagConnect ::= ReceiveDefinition:MReceiveDefinition* PushSendDefinition:MSendDefinition* PullSendDefinition:MSendDefinition* MappingDefinition:MMappingDefinition* DependencyDefinition:MDependencyDefinition* RootTypeComponent:MTypeComponent* TokenComponent:MTokenComponent*; MRagConnect ::= ReceiveDefinition:MReceiveDefinition* SendDefinition:MSendDefinition* MappingDefinition:MMappingDefinition* DependencyDefinition:MDependencyDefinition* RootTypeComponent:MTypeComponent* TokenComponent:MTokenComponent*;
abstract MEndpointDefinition ::= InnerMappingDefinition:MInnerMappingDefinition*; abstract MEndpointDefinition ::= InnerMappingDefinition:MInnerMappingDefinition*;
MReceiveDefinition : MEndpointDefinition; MReceiveDefinition : MEndpointDefinition;
MSendDefinition : MEndpointDefinition; MSendDefinition : MEndpointDefinition;
......
...@@ -7,13 +7,8 @@ rel EndpointDefinition.Mapping* <-> MappingDefinition.UsedAt*; ...@@ -7,13 +7,8 @@ rel EndpointDefinition.Mapping* <-> MappingDefinition.UsedAt*;
abstract TokenEndpointDefinition : EndpointDefinition; abstract TokenEndpointDefinition : EndpointDefinition;
rel TokenEndpointDefinition.Token -> TokenComponent; rel TokenEndpointDefinition.Token -> TokenComponent;
abstract ReceiveTokenEndpointDefinition : TokenEndpointDefinition; ReceiveTokenEndpointDefinition : TokenEndpointDefinition;
abstract SendTokenEndpointDefinition : TokenEndpointDefinition; SendTokenEndpointDefinition : TokenEndpointDefinition;
ReceiveFromMqttDefinition : ReceiveTokenEndpointDefinition;
SendToMqttDefinition : SendTokenEndpointDefinition;
ReceiveFromRestDefinition : ReceiveTokenEndpointDefinition;
SendToRestDefinition : SendTokenEndpointDefinition;
DependencyDefinition ::= <ID>; DependencyDefinition ::= <ID>;
rel DependencyDefinition.Source <-> TokenComponent.DependencySourceDefinition*; rel DependencyDefinition.Source <-> TokenComponent.DependencySourceDefinition*;
......
...@@ -2,4 +2,6 @@ aspect Configuration { ...@@ -2,4 +2,6 @@ aspect Configuration {
public static boolean ASTNode.loggingEnabledForReads = false; public static boolean ASTNode.loggingEnabledForReads = false;
public static boolean ASTNode.loggingEnabledForWrites = false; public static boolean ASTNode.loggingEnabledForWrites = false;
public static TypeDecl ASTNode.rootNode; public static TypeDecl ASTNode.rootNode;
public static boolean ASTNode.usesMqtt;
public static boolean ASTNode.usesRest;
} }
...@@ -34,25 +34,24 @@ aspect AttributesForMustache { ...@@ -34,25 +34,24 @@ aspect AttributesForMustache {
eq MRagConnect.getChild().mqttHandlerField() = mqttHandlerField(); eq MRagConnect.getChild().mqttHandlerField() = mqttHandlerField();
eq MRagConnect.getRootTypeComponent(int i).isFirst() = i == 0; eq MRagConnect.getRootTypeComponent(int i).isFirst() = i == 0;
syn boolean MRagConnect.usesMqtt() = getRagConnect().usesMqtt(); syn String MRagConnect.closeMethod() = "ragconnectCloseConnections";
// syn boolean MRagConnect.usesMqtt() = getRagConnect().usesMqtt();
syn String MRagConnect.mqttHandlerAttribute() = "_mqttHandler"; syn String MRagConnect.mqttHandlerAttribute() = "_mqttHandler";
syn String MRagConnect.mqttHandlerField() = "_mqttHandler"; syn String MRagConnect.mqttHandlerField() = "_mqttHandler";
syn String MRagConnect.mqttSetHostMethod() = "MqttSetHost"; // syn String MRagConnect.mqttSetHostMethod() = "MqttSetHost";
syn String MRagConnect.mqttWaitUntilReadyMethod() = "MqttWaitUntilReady"; syn String MRagConnect.mqttSetupWaitUntilReadyMethod() = "ragconnectSetupMqttWaitUntilReady";
syn String MRagConnect.mqttCloseMethod() = "MqttCloseConnections";
syn boolean MRagConnect.usesRest() = getRagConnect().usesRest(); // syn boolean MRagConnect.usesRest() = getRagConnect().usesRest();
syn String MRagConnect.restHandlerAttribute() = "_restHandler"; syn String MRagConnect.restHandlerAttribute() = "_restHandler";
syn String MRagConnect.restHandlerField() = "_restHandler"; syn String MRagConnect.restHandlerField() = "_restHandler";
syn String MRagConnect.restSetPortMethod() = "RestSetPort"; // syn String MRagConnect.restSetPortMethod() = "RestSetPort";
syn String MRagConnect.restCloseMethod() = "RestCloseConnections";
// --- MEndpointDefinition --- // --- MEndpointDefinition ---
syn String MEndpointDefinition.preemptiveExpectedValue(); syn String MEndpointDefinition.preemptiveExpectedValue();
syn String MEndpointDefinition.preemptiveReturn(); syn String MEndpointDefinition.preemptiveReturn();
syn TokenEndpointDefinition MEndpointDefinition.endpointDef(); syn TokenEndpointDefinition MEndpointDefinition.endpointDef();
syn String MEndpointDefinition.firstInputVarName(); syn String MEndpointDefinition.firstInputVarName();
syn String MEndpointDefinition.newConnectionMethod(); // syn String MEndpointDefinition.newConnectionMethod();
eq MEndpointDefinition.getInnerMappingDefinition(int i).isLast() = i == getNumInnerMappingDefinition() - 1; eq MEndpointDefinition.getInnerMappingDefinition(int i).isLast() = i == getNumInnerMappingDefinition() - 1;
eq MEndpointDefinition.getInnerMappingDefinition().resultVarPrefix() = resultVarPrefix(); eq MEndpointDefinition.getInnerMappingDefinition().resultVarPrefix() = resultVarPrefix();
...@@ -61,21 +60,21 @@ aspect AttributesForMustache { ...@@ -61,21 +60,21 @@ aspect AttributesForMustache {
inh String MEndpointDefinition.mqttHandlerAttribute(); inh String MEndpointDefinition.mqttHandlerAttribute();
inh String MEndpointDefinition.restHandlerAttribute(); inh String MEndpointDefinition.restHandlerAttribute();
syn String MEndpointDefinition.connectParameterName() { syn String MEndpointDefinition.connectParameterName() = "uriString";
switch (endpointDef().protocol()) { // switch (endpointDef().protocol()) {
case "mqtt": return "topic"; // case "mqtt": return "topic";
case "rest": return "path"; // case "rest": return "path";
default: return null; // default: return null;
} // }
} // }
syn String MEndpointDefinition.handlerAttribute() { // syn String MEndpointDefinition.handlerAttribute() {
switch (endpointDef().protocol()) { // switch (endpointDef().protocol()) {
case "mqtt": return mqttHandlerAttribute(); // case "mqtt": return mqttHandlerAttribute();
case "rest": return restHandlerAttribute(); // case "rest": return restHandlerAttribute();
default: return null; // default: return null;
} // }
} // }
syn String MEndpointDefinition.connectMethod() = "connect" + tokenName() + (ragconnect().lookupTokenEndpointDefinitions(token()).size() > 1 ? "Via" + capitalize(endpointDef().protocol()) : ""); syn String MEndpointDefinition.connectMethod() = "connect" + tokenName();
syn TokenComponent MEndpointDefinition.token() = endpointDef().getToken(); syn TokenComponent MEndpointDefinition.token() = endpointDef().getToken();
syn boolean MEndpointDefinition.alwaysApply() = endpointDef().getAlwaysApply(); syn boolean MEndpointDefinition.alwaysApply() = endpointDef().getAlwaysApply();
syn String MEndpointDefinition.resultVarPrefix() = "result"; // we do not need "_" here, because methodName begins with one syn String MEndpointDefinition.resultVarPrefix() = "result"; // we do not need "_" here, because methodName begins with one
...@@ -112,39 +111,39 @@ aspect AttributesForMustache { ...@@ -112,39 +111,39 @@ aspect AttributesForMustache {
eq MReceiveDefinition.endpointDef() = getReceiveTokenEndpointDefinition(); eq MReceiveDefinition.endpointDef() = getReceiveTokenEndpointDefinition();
eq MReceiveDefinition.firstInputVarName() = "message"; eq MReceiveDefinition.firstInputVarName() = "message";
syn String MReceiveDefinition.newConnectionMethod() { // syn String MReceiveDefinition.newConnectionMethod() {
switch (endpointDef().protocol()) { // switch (endpointDef().protocol()) {
case "mqtt": return "newConnection"; // case "mqtt": return "newConnection";
case "rest": return "newPUTConnection"; // case "rest": return "newPUTConnection";
default: return null; // default: return null;
} // }
} // }
// --- MSendDefinition --- // --- MSendDefinition ---
eq MSendDefinition.preemptiveExpectedValue() = lastValue(); eq MSendDefinition.preemptiveExpectedValue() = lastValue();
eq MSendDefinition.preemptiveReturn() { eq MSendDefinition.preemptiveReturn() = "return false;";
switch (endpointDef().protocol()) { // switch (endpointDef().protocol()) {
case "mqtt": return "return false;"; // case "mqtt": return "return false;";
case "rest": return "throw e;"; // e is Exception variable // case "rest": return "throw e;"; // e is Exception variable
default: return null; // default: return null;
} // }
} // }
eq MSendDefinition.endpointDef() = getSendTokenEndpointDefinition(); eq MSendDefinition.endpointDef() = getSendTokenEndpointDefinition();
eq MSendDefinition.firstInputVarName() = "get" + tokenName() + "()"; eq MSendDefinition.firstInputVarName() = "get" + tokenName() + "()";
syn String MSendDefinition.sendTopic() = "_topic_" + tokenName(); syn String MSendDefinition.sender() = "_sender_" + tokenName();
syn String MSendDefinition.lastValue() = "_lastValue" + tokenName(); syn String MSendDefinition.lastValue() = "_lastValue" + tokenName();
syn String MSendDefinition.updateMethod() = "_update_" + tokenName(); syn String MSendDefinition.updateMethod() = "_update_" + tokenName();
syn String MSendDefinition.writeMethod() = "_writeLastValue_" + tokenName(); syn String MSendDefinition.writeMethod() = "_writeLastValue_" + tokenName();
syn String MSendDefinition.tokenResetMethod() = "get" + tokenName() + "_reset"; syn String MSendDefinition.tokenResetMethod() = "get" + tokenName() + "_reset";
syn boolean MSendDefinition.isPush() = getSendTokenEndpointDefinition().isPush(); // syn boolean MSendDefinition.isPush() = getSendTokenEndpointDefinition().isPush();
syn String MSendDefinition.newConnectionMethod() { // syn String MSendDefinition.newConnectionMethod() {
switch (endpointDef().protocol()) { // switch (endpointDef().protocol()) {
case "mqtt": return null; // case "mqtt": return null;
case "rest": return "newGETConnection"; // case "rest": return "newGETConnection";
default: return null; // default: return null;
} // }
} // }
// --- MMappingDefinition --- // --- MMappingDefinition ---
syn String MMappingDefinition.toType() = getMappingDefinition().getToType().prettyPrint(); syn String MMappingDefinition.toType() = getMappingDefinition().getToType().prettyPrint();
...@@ -182,11 +181,7 @@ aspect AttributesForMustache { ...@@ -182,11 +181,7 @@ aspect AttributesForMustache {
for (EndpointDefinition def : getEndpointDefinitionList()) { for (EndpointDefinition def : getEndpointDefinitionList()) {
if (def.isSendTokenEndpointDefinition()) { if (def.isSendTokenEndpointDefinition()) {
SendTokenEndpointDefinition sendDef = def.asSendTokenEndpointDefinition(); SendTokenEndpointDefinition sendDef = def.asSendTokenEndpointDefinition();
if (sendDef.isPush()) { result.addSendDefinition(sendDef.toMustache());
result.addPushSendDefinition(sendDef.toMustache());
} else {
result.addPullSendDefinition(sendDef.toMustache());
}
} else { } else {
result.addReceiveDefinition(def.asReceiveTokenEndpointDefinition().toMustache()); result.addReceiveDefinition(def.asReceiveTokenEndpointDefinition().toMustache());
} }
...@@ -257,9 +252,9 @@ aspect AttributesForMustache { ...@@ -257,9 +252,9 @@ aspect AttributesForMustache {
aspect AspectGeneration { aspect AspectGeneration {
syn boolean SendTokenEndpointDefinition.isPush(); // syn boolean SendTokenEndpointDefinition.isPush();
eq SendToMqttDefinition.isPush() = true; // eq SendToMqttDefinition.isPush() = true;
eq SendToRestDefinition.isPush() = false; // eq SendToRestDefinition.isPush() = false;
// --- rootNodeName --- // --- rootNodeName ---
syn String ASTNode.rootNodeName() = rootNode.getName(); syn String ASTNode.rootNodeName() = rootNode.getName();
......
...@@ -116,10 +116,8 @@ aspect Mappings { ...@@ -116,10 +116,8 @@ aspect Mappings {
// --- isSuitableEdgeMapping(def) --- // --- isSuitableEdgeMapping(def) ---
syn boolean TokenEndpointDefinition.isSuitableEdgeMapping(MappingDefinition def); syn boolean TokenEndpointDefinition.isSuitableEdgeMapping(MappingDefinition def);
eq ReceiveFromMqttDefinition.isSuitableEdgeMapping(MappingDefinition def) = def.getFromType().isByteArray(); eq ReceiveTokenEndpointDefinition.isSuitableEdgeMapping(MappingDefinition def) = def.getFromType().isByteArray();
eq SendToMqttDefinition.isSuitableEdgeMapping(MappingDefinition def) = def.getToType().isByteArray(); eq SendTokenEndpointDefinition.isSuitableEdgeMapping(MappingDefinition def) = def.getToType().isByteArray();
eq ReceiveFromRestDefinition.isSuitableEdgeMapping(MappingDefinition def) = def.getFromType().isString();
eq SendToRestDefinition.isSuitableEdgeMapping(MappingDefinition def) = def.getToType().isString();
// --- isPrimitiveType --- // --- isPrimitiveType ---
syn boolean TokenComponent.isPrimitiveType() = effectiveJavaTypeUse().isPrimitiveType(); syn boolean TokenComponent.isPrimitiveType() = effectiveJavaTypeUse().isPrimitiveType();
...@@ -145,9 +143,9 @@ aspect Mappings { ...@@ -145,9 +143,9 @@ aspect Mappings {
// --- suitableDefaultMapping --- // --- suitableDefaultMapping ---
syn DefaultMappingDefinition EndpointDefinition.suitableDefaultMapping(); syn DefaultMappingDefinition EndpointDefinition.suitableDefaultMapping();
eq ReceiveFromMqttDefinition.suitableDefaultMapping() { eq ReceiveTokenEndpointDefinition.suitableDefaultMapping() {
String typeName = getMappingList().isEmpty() ? String typeName = getMappingList().isEmpty() ?
getToken().getJavaTypeUse().getName() : getToken().effectiveJavaTypeUse().getName() :
getMappingList().get(0).getFromType().prettyPrint(); getMappingList().get(0).getFromType().prettyPrint();
switch(typeName) { switch(typeName) {
case "int": case "int":
...@@ -166,9 +164,9 @@ aspect Mappings { ...@@ -166,9 +164,9 @@ aspect Mappings {
default: return null; default: return null;
} }
} }
eq SendToMqttDefinition.suitableDefaultMapping() { eq SendTokenEndpointDefinition.suitableDefaultMapping() {
String typeName = getMappingList().isEmpty() ? String typeName = getMappingList().isEmpty() ?
getToken().getJavaTypeUse().getName() : getToken().effectiveJavaTypeUse().getName() :
getMappingList().get(getMappingList().size() - 1).getFromType().prettyPrint(); getMappingList().get(getMappingList().size() - 1).getFromType().prettyPrint();
switch(typeName) { switch(typeName) {
case "int": case "int":
...@@ -187,54 +185,54 @@ aspect Mappings { ...@@ -187,54 +185,54 @@ aspect Mappings {
default: return null; default: return null;
} }
} }
eq ReceiveFromRestDefinition.suitableDefaultMapping() { // eq ReceiveFromRestDefinition.suitableDefaultMapping() {
String typeName = getMappingList().isEmpty() ? // String typeName = getMappingList().isEmpty() ?
getToken().getJavaTypeUse().getName() : // getToken().getJavaTypeUse().getName() :
getMappingList().get(0).getFromType().prettyPrint(); // getMappingList().get(0).getFromType().prettyPrint();
switch(typeName) { // switch(typeName) {
case "int": // case "int":
case "Integer": return ragconnect().defaultStringToIntMapping(); // case "Integer": return ragconnect().defaultStringToIntMapping();
case "short": // case "short":
case "Short": return ragconnect().defaultStringToShortMapping(); // case "Short": return ragconnect().defaultStringToShortMapping();
case "long": // case "long":
case "Long": return ragconnect().defaultStringToLongMapping(); // case "Long": return ragconnect().defaultStringToLongMapping();
case "float": // case "float":
case "Float": return ragconnect().defaultStringToFloatMapping(); // case "Float": return ragconnect().defaultStringToFloatMapping();
case "double": // case "double":
case "Double": return ragconnect().defaultStringToDoubleMapping(); // case "Double": return ragconnect().defaultStringToDoubleMapping();
case "char": // case "char":
case "Character": return ragconnect().defaultStringToCharMapping(); // case "Character": return ragconnect().defaultStringToCharMapping();
default: return null; // default: return null;
} // }
} // }
eq SendToRestDefinition.suitableDefaultMapping() { // eq SendToRestDefinition.suitableDefaultMapping() {
String typeName = getMappingList().isEmpty() ? // String typeName = getMappingList().isEmpty() ?
getToken().getJavaTypeUse().getName() : // getToken().getJavaTypeUse().getName() :
getMappingList().get(getMappingList().size() - 1).getFromType().prettyPrint(); // getMappingList().get(getMappingList().size() - 1).getFromType().prettyPrint();
switch(typeName) { // switch(typeName) {
case "int": // case "int":
case "Integer": return ragconnect().defaultIntToStringMapping(); // case "Integer": return ragconnect().defaultIntToStringMapping();
case "short": // case "short":
case "Short": return ragconnect().defaultShortToStringMapping(); // case "Short": return ragconnect().defaultShortToStringMapping();
case "long": // case "long":
case "Long": return ragconnect().defaultLongToStringMapping(); // case "Long": return ragconnect().defaultLongToStringMapping();
case "float": // case "float":
case "Float": return ragconnect().defaultFloatToStringMapping(); // case "Float": return ragconnect().defaultFloatToStringMapping();
case "double": // case "double":
case "Double": return ragconnect().defaultDoubleToStringMapping(); // case "Double": return ragconnect().defaultDoubleToStringMapping();
case "char": // case "char":
case "Character": return ragconnect().defaultCharToStringMapping(); // case "Character": return ragconnect().defaultCharToStringMapping();
default: return null; // default: return null;
} // }
} // }
// --- isByteArray --- // --- isByteArray ---
syn boolean MappingDefinitionType.isByteArray() = false; syn boolean MappingDefinitionType.isByteArray() = false;
eq JavaArrayMappingDefinitionType.isByteArray() = getType().getName().equals("byte"); eq JavaArrayMappingDefinitionType.isByteArray() = getType().getName().equals("byte");
// --- isString --- // // --- isString ---
syn boolean MappingDefinitionType.isString() = false; // syn boolean MappingDefinitionType.isString() = false;
eq JavaMappingDefinitionType.isString() = getType().getName().equals("String"); // eq JavaMappingDefinitionType.isString() = getType().getName().equals("String");
// --- allMappingDefinitions --- // --- allMappingDefinitions ---
syn java.util.List<MappingDefinition> RagConnect.allMappingDefinitions() { syn java.util.List<MappingDefinition> RagConnect.allMappingDefinitions() {
...@@ -255,19 +253,19 @@ aspect Mappings { ...@@ -255,19 +253,19 @@ aspect Mappings {
result.add(defaultDoubleToBytesMapping()); result.add(defaultDoubleToBytesMapping());
result.add(defaultCharToBytesMapping()); result.add(defaultCharToBytesMapping());
result.add(defaultStringToBytesMapping()); result.add(defaultStringToBytesMapping());
// string conversion // // string conversion
result.add(defaultStringToIntMapping()); // result.add(defaultStringToIntMapping());
result.add(defaultStringToShortMapping()); // result.add(defaultStringToShortMapping());
result.add(defaultStringToLongMapping()); // result.add(defaultStringToLongMapping());
result.add(defaultStringToFloatMapping()); // result.add(defaultStringToFloatMapping());
result.add(defaultStringToDoubleMapping()); // result.add(defaultStringToDoubleMapping());
result.add(defaultStringToCharMapping()); // result.add(defaultStringToCharMapping());
result.add(defaultIntToStringMapping()); // result.add(defaultIntToStringMapping());
result.add(defaultShortToStringMapping()); // result.add(defaultShortToStringMapping());
result.add(defaultLongToStringMapping()); // result.add(defaultLongToStringMapping());
result.add(defaultFloatToStringMapping()); // result.add(defaultFloatToStringMapping());
result.add(defaultDoubleToStringMapping()); // result.add(defaultDoubleToStringMapping());
result.add(defaultCharToStringMapping()); // result.add(defaultCharToStringMapping());
return result; return result;
} }
} }
...@@ -31,12 +31,8 @@ EndpointDefinition endpoint_definition ...@@ -31,12 +31,8 @@ EndpointDefinition endpoint_definition
; ;
EndpointDefinition endpoint_definition_type EndpointDefinition endpoint_definition_type
= RECEIVE token_ref {: return new ReceiveFromMqttDefinition().setToken(token_ref); :} = RECEIVE token_ref {: return new ReceiveTokenEndpointDefinition().setToken(token_ref); :}
| RECEIVE token_ref VIA MQTT {: return new ReceiveFromMqttDefinition().setToken(token_ref); :} | SEND token_ref {: return new SendTokenEndpointDefinition().setToken(token_ref); :}
| RECEIVE token_ref VIA REST {: return enableAlwaysApply(new ReceiveFromRestDefinition()).setToken(token_ref); :}
| SEND token_ref {: return new SendToMqttDefinition().setToken(token_ref); :}
| SEND token_ref VIA MQTT {: return new SendToMqttDefinition().setToken(token_ref); :}
| SEND token_ref VIA REST {: return enableAlwaysApply(new SendToRestDefinition()).setToken(token_ref); :}
; ;
TokenComponent token_ref TokenComponent token_ref
......
...@@ -5,6 +5,3 @@ ...@@ -5,6 +5,3 @@
"maps" { return sym(Terminals.MAPS); } "maps" { return sym(Terminals.MAPS); }
"to" { return sym(Terminals.TO); } "to" { return sym(Terminals.TO); }
"as" { return sym(Terminals.AS); } "as" { return sym(Terminals.AS); }
"via" { return sym(Terminals.VIA); }
"mqtt" { return sym(Terminals.MQTT); }
"rest" { return sym(Terminals.REST); }
...@@ -20,10 +20,14 @@ public class Compiler extends AbstractCompiler { ...@@ -20,10 +20,14 @@ public class Compiler extends AbstractCompiler {
// private ValueOption optionOutputDir; // private ValueOption optionOutputDir;
private ValueOption optionRootNode; private ValueOption optionRootNode;
private ValueOption optionProtocols;
private BooleanOption optionVerbose; private BooleanOption optionVerbose;
private BooleanOption optionLogReads; private BooleanOption optionLogReads;
private BooleanOption optionLogWrites; private BooleanOption optionLogWrites;
private static final String OPTION_PROTOCOL_MQTT = "mqtt";
private static final String OPTION_PROTOCOL_REST = "rest";
public Compiler() { public Compiler() {
super("ragconnect", true); super("ragconnect", true);
} }
...@@ -61,10 +65,10 @@ public class Compiler extends AbstractCompiler { ...@@ -61,10 +65,10 @@ public class Compiler extends AbstractCompiler {
printMessage("Writing output files"); printMessage("Writing output files");
final List<String> handlers = new ArrayList<>(); final List<String> handlers = new ArrayList<>();
if (ragConnect.usesMqtt()) { if (ASTNode.usesMqtt) {
handlers.add("MqttHandler.jadd"); handlers.add("MqttHandler.jadd");
} }
if (ragConnect.usesRest()) { if (ASTNode.usesRest) {
handlers.add("RestHandler.jadd"); handlers.add("RestHandler.jadd");
} }
// copy handlers into outputDir // copy handlers into outputDir
...@@ -138,6 +142,12 @@ public class Compiler extends AbstractCompiler { ...@@ -138,6 +142,12 @@ public class Compiler extends AbstractCompiler {
new ValueOption("rootNode", "root node in the base grammar.") new ValueOption("rootNode", "root node in the base grammar.")
.acceptAnyValue() .acceptAnyValue()
.needsValue(true)); .needsValue(true));
optionProtocols = addOption(
new ValueOption("protocols", "Protocols to enable")
.acceptMultipleValues(true)
.addDefaultValue(OPTION_PROTOCOL_MQTT, "Enable MQTT")
.addAcceptedValue(OPTION_PROTOCOL_REST, "Enable REST")
);
optionVerbose = addOption( optionVerbose = addOption(
new BooleanOption("verbose", "Print more messages while compiling.") new BooleanOption("verbose", "Print more messages while compiling.")
.defaultValue(false)); .defaultValue(false));
...@@ -181,6 +191,8 @@ public class Compiler extends AbstractCompiler { ...@@ -181,6 +191,8 @@ public class Compiler extends AbstractCompiler {
ragConnect.additionalRelations().forEach(ragConnectGrammarPart::addDeclaration); ragConnect.additionalRelations().forEach(ragConnectGrammarPart::addDeclaration);
ASTNode.loggingEnabledForReads = optionLogReads.value(); ASTNode.loggingEnabledForReads = optionLogReads.value();
ASTNode.loggingEnabledForWrites = optionLogWrites.value(); ASTNode.loggingEnabledForWrites = optionLogWrites.value();
ASTNode.usesMqtt = optionProtocols.hasValue(OPTION_PROTOCOL_MQTT);
ASTNode.usesRest = optionProtocols.hasValue(OPTION_PROTOCOL_REST);
return ragConnect; return ragConnect;
} }
......
package org.jastadd.ragconnect.compiler;
import beaver.Parser;
import org.jastadd.ragconnect.ast.*;
import org.jastadd.ragconnect.parser.RagConnectParser;
import org.jastadd.ragconnect.scanner.RagConnectScanner;
import java.io.BufferedReader;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
/**
* Testing Ros2Rag without parser.
*
* @author rschoene - Initial contribution
*/