in src/main/java/com/ql/util/express/match/QLPatternNode.java [125:237]
public void splitChild() throws Exception {
String originalStr = this.originalContent;
if ("(".equals(originalStr) || ")".equals(originalStr) || "|".equals(originalStr) || "||".equals(originalStr)
|| "/**".equals(originalStr) || "**/".equals(originalStr) || "*".equals(originalStr)
|| "->".equals(originalStr)) {
this.matchMode = MatchMode.DETAIL;
this.nodeType = this.nodeTypeManager.findNodeType(originalStr);
return;
}
StringBuilder tempStr = new StringBuilder();
int count = 0;
for (int i = 0; i < originalStr.length(); i++) {
if (originalStr.charAt(i) == '(') {
tempStr.append(originalStr.charAt(i));
count = count + 1;
} else if (originalStr.charAt(i) == ')') {
tempStr.append(originalStr.charAt(i));
count = count - 1;
} else if (count > 0) {
tempStr.append(originalStr.charAt(i));
} else if (originalStr.charAt(i) == '$') {
if (this.matchMode != MatchMode.NULL
&& this.matchMode != MatchMode.AND) {
throw new QLCompileException("不正确的模式串,在一个匹配模式中不能|,$并存,请使用字串模式:" + originalStr);
}
children.add(new QLPatternNode(this.nodeTypeManager, "ANONY_PATTERN",
tempStr.toString(), false, this.level + 1));
this.matchMode = MatchMode.AND;
tempStr = new StringBuilder();
} else if (originalStr.charAt(i) == '|') {
if (this.matchMode != MatchMode.NULL && this.matchMode != MatchMode.OR) {
throw new QLCompileException("不正确的模式串,在一个匹配模式中不能|,$并存,请使用字串模式:" + originalStr);
}
children.add(new QLPatternNode(this.nodeTypeManager, "ANONY_PATTERN",
tempStr.toString(), false, this.level + 1));
this.matchMode = MatchMode.OR;
tempStr = new StringBuilder();
} else if (originalStr.charAt(i) == '#') {
this.rootNodeType = this.nodeTypeManager.findNodeType(originalStr.substring(i + 1));
break;
} else {
tempStr.append(originalStr.charAt(i));
}
}
// 处理没有()的内容
if (count > 0) {
throw new QLCompileException("不正确的模式串,(没有找到对应的):" + originalStr);
}
if (!this.children.isEmpty()) {
children.add(
new QLPatternNode(this.nodeTypeManager, "ANONY_PATTERN", tempStr.toString(), false, this.level + 1));
tempStr = new StringBuilder();
}
//需要剔除乘法*的情况
if (tempStr.toString().endsWith("*") && tempStr.length() > 1) {
this.minMatchNum = 0;
this.maxMatchNum = Integer.MAX_VALUE;
tempStr = new StringBuilder(tempStr.substring(0, tempStr.length() - 1));
}
if (tempStr.toString().endsWith("}")) {
int index = tempStr.lastIndexOf("{");
if (index > 0) {
String numStr = tempStr.substring(index + 1, tempStr.length() - 1);
int index2 = numStr.indexOf(':');
if (index2 > 0) {
this.minMatchNum = Integer.parseInt(numStr.substring(0, index2));
this.maxMatchNum = Integer.parseInt(numStr.substring(index2 + 1));
} else {
this.minMatchNum = Integer.parseInt(numStr);
this.maxMatchNum = Integer.parseInt(numStr);
}
tempStr = new StringBuilder(tempStr.substring(0, index));
}
}
if (tempStr.toString().endsWith("^") && tempStr.length() > 1) {
this.isTreeRoot = true;
tempStr = new StringBuilder(tempStr.substring(0, tempStr.length() - 1));
}
if (tempStr.toString().endsWith("~") && tempStr.length() > 1) {
this.isSkip = true;
tempStr = new StringBuilder(tempStr.substring(0, tempStr.length() - 1));
}
if (tempStr.toString().endsWith("@") && tempStr.length() > 1) {
this.blame = true;
tempStr = new StringBuilder(tempStr.substring(0, tempStr.length() - 1));
}
//处理(ABC|bcd)模式
if (tempStr.length() > 2 && tempStr.charAt(0) == '(' && tempStr.charAt(tempStr.length() - 1) == ')') {
this.isChildMode = true;
this.children.add(
new QLPatternNode(this.nodeTypeManager, "ANONY_PATTERN", tempStr.substring(1, tempStr.length() - 1),
false, this.level + 1));
this.matchMode = MatchMode.AND;
tempStr = new StringBuilder();
}
int index = tempStr.indexOf("->");
if (index > 0) {
this.targetNodeType = this.nodeTypeManager.findNodeType(tempStr.substring(index + 2));
tempStr = new StringBuilder(tempStr.substring(0, index));
}
if (tempStr.length() > 0) {
this.matchMode = MatchMode.DETAIL;
this.nodeType = this.nodeTypeManager.findNodeType(tempStr.toString());
}
}