Commit be3196a7 authored by Ferdinand Alexander Mehlan's avatar Ferdinand Alexander Mehlan
Browse files

RegexStringBuilder added

parent 2acabf47
Pipeline #63008 passed with stage
in 50 seconds
......@@ -30,6 +30,7 @@ import java.util.regex.Pattern;
import de.monticore.generating.GeneratorEngine;
import de.monticore.generating.GeneratorSetup;
import de.monticore.lang.tagging.helper.RegexStringHelper;
import de.monticore.lang.tagging.helper.UnitKinds;
import de.monticore.lang.tagschema._ast.*;
import de.monticore.lang.tagschema._parser.TagSchemaParser;
......@@ -174,8 +175,7 @@ public class TagSchemaGenerator extends GeneratorEngine {
// build matching string
String complexMatching = "(\\\\d+(?:\\\\.\\\\d+)?(?:m|n|k|d)?m)\\\\s*x\\\\s*(\\\\d+(?:\\\\.\\\\d+)?(?:m|n|k|d)?m)\\\\s*x\\\\s*(\\\\d+(?:\\\\.\\\\d+)?(?:m|n|k|d)?m)";
String complexMatching = RegexStringHelper.getMatcher(complexTag);
// generate creator
List<String> imports = new LinkedList<String>();
......
/**
*
* ******************************************************************************
* MontiCAR Modeling Family, www.se-rwth.de
* Copyright (c) 2017, Software Engineering Group at RWTH Aachen,
* All rights reserved.
*
* This project is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this project. If not, see <http://www.gnu.org/licenses/>.
* *******************************************************************************
*/
package de.monticore.lang.tagging.helper;
import javax.measure.quantity.Quantity;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexStringHelper {
public static String getMatcher(String input) {
input = input.replaceFirst("\\{\\s*", "");
input = input.replaceFirst("\\s*}$", "");
input = input.replaceFirst("^\\s+", "");
Matcher m = Pattern.compile("\\$\\{(\\w+):(\\w+)\\}").matcher(input);
while (m.find()) {
input = input.replace(m.group(0), handleVarGroup(m.group(2)));
}
return input;
}
private static String handleVarGroup(String type) {
String ret = "";
if (type.equals("String")) {
ret += "(\\\\w+";
} else {
ret += "(\\\\d+(?:\\\\.\\\\d+)?(?:n|m|c|d|h|k|M|G|T)?";
ret += getUnit(type);
ret += ")";
}
ret += "\\\\s*";
return ret;
}
private static String getUnit(String type) {
switch (type) {
case "Length":
return "m";
case "Mass":
return "g";
case "Duration":
return "s";
case "ElectricCurrent":
return "A";
case "Temperature":
return "(?:K|C|F)";
default:
return null;
}
}
}
......@@ -23,12 +23,12 @@ public class PhysicalTags {
}
protected void doRegisterTagTypes(TaggingResolver tagging) {
tagging.addTagSymbolCreator(new IsPhysicalSymbolCreator());
tagging.addTagSymbolResolvingFilter(CommonResolvingFilter.create(IsPhysicalSymbol.KIND));
tagging.addTagSymbolCreator(new WeightSymbolCreator());
tagging.addTagSymbolResolvingFilter(CommonResolvingFilter.create(WeightSymbol.KIND));
tagging.addTagSymbolCreator(new SizeSymbolCreator());
tagging.addTagSymbolResolvingFilter(CommonResolvingFilter.create(SizeSymbol.KIND));
tagging.addTagSymbolCreator(new IsPhysicalSymbolCreator());
tagging.addTagSymbolResolvingFilter(CommonResolvingFilter.create(IsPhysicalSymbol.KIND));
}
public static void registerTagTypes(TaggingResolver tagging) {
......
......@@ -34,7 +34,7 @@ public class SizeSymbolCreator implements TagSymbolCreator {
* http://www.regexplanet.com/advanced/java/index.html
*/
public static final Pattern pattern = Pattern.compile(
"(\\d+(?:\\.\\d+)?(?:m|n|k|d)?m)\\s*x\\s*(\\d+(?:\\.\\d+)?(?:m|n|k|d)?m)\\s*x\\s*(\\d+(?:\\.\\d+)?(?:m|n|k|d)?m)"
"(\\d+(?:\\.\\d+)?(?:n|m|c|d|h|k|M|G|T)?m)\\s*x(\\d+(?:\\.\\d+)?(?:n|m|c|d|h|k|M|G|T)?m)\\s*x(\\d+(?:\\.\\d+)?(?:n|m|c|d|h|k|M|G|T)?m)\\s*"
);
public static Scope getGlobalScope(final Scope scope) {
......
......@@ -4,7 +4,10 @@ import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.cncModel
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.*;
tagschema PhysicalTags {
// Simple TagType
tagtype IsPhysical for EMAComponentInstance;
// Value TagType
tagtype Weight:Mass for EMAComponentInstance;
// Complex TagType
tagtype Size for EMAComponentInstance is { ${height:Length}x${width:Length}x${depth:Length} };
tagtype IsPhysical for EMAComponentInstance;
}
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