📄 pi2remarkpi.java
字号:
/*
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
author: Yuan yongfu lijin liyong lib 511,the College of Mathematics and Computer Science,HuNan Normal University,China
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
*/
package edu.hunnu.webjetchecker.convert;
import java.io.File;
import java.util.StringTokenizer;
public class pi2RemarkPi {
private String str;
private File file;
public pi2RemarkPi(String str, File file) {
this.str = str;
this.file = file;
}
public String getResult() {
String str = pi2RemarkPi_Body();
return str;
}
public String pi2RemarkPi_Body() {
// ********************end match to Pi with
// remark**************************
// *************Pi with remark to bpel***********************
StringTokenizer token = new StringTokenizer(this.str, ".");
int num = token.countTokens();
String[] actions = new String[num];
for (int i = 0; i < num; i++) {
actions[i] = token.nextToken();
}
String head = actions[0];
if (head.startsWith("("))
head = head.substring(1);
if (!(head.indexOf("(") < 0))
head = head.substring(0, head.indexOf("("));
else if (!(head.indexOf("<") < 0))
head = head.substring(0, head.indexOf("<"));
String tail = actions[num - 2];
if (!(tail.indexOf("(") < 0))
tail.substring(0, tail.indexOf("("));
else if (!(tail.indexOf("<") > 0))
tail = tail.substring(0, tail.indexOf("<"));
Bpel2RemarkPi bm = new Bpel2RemarkPi(this.file);
String strf = bm.getResult();
int index = strf.indexOf("^");
if (index == -1) {
System.out.println("The Pi model don't hava restrict names!");
} else {
int tempIndex = strf.indexOf(")", index);
strf = strf.substring(tempIndex + 1);
}
int posHead = strf.indexOf(head); // posHead是开始的动作在带匹配的Pi演算的表达式中的位置
int temp0 = posHead;
temp0 = positionBackward(strf, temp0, 0); // start结束*的位置
int temp1 = temp0 - 1;
temp1 = positionBackward(strf, temp1, 0); // start开始*的位置
int bsPos = startPos(strf, temp1);
int posTail = strf.indexOf(tail);
int temp2 = posTail;
temp2 = positionForward(strf, temp2, 0); // end开始*的位置
int temp3 = temp2 + 1;
temp3 = positionForward(strf, temp3, 0); // end结束*的位置
int bePos = endPos(strf, temp2);
int eePos = positionForward(strf, bePos + 1, 0);
String result = strf.substring(bsPos - 1, eePos + 2);
return result;
}
public int positionBackward(String str, int i, int j) {
int cons = i + 1;
while (!(str.substring(i, i + 1).equals("*"))) {
if (i == 0) { // 已经找到字符串顶端,则匹配最后一个找到的*
i = cons;
break;
} else if (str.substring(i, i + 1).equals(".") && j != 0) { // 当遇到字符"."后返回最后匹配的*,第一次匹配时忽略"."
while (!str.substring(i, i + 1).equals("*")) {
i = i + 1;
}
return i;
}
i = i - 1;
}
return i;
}
public int positionForward(String str, int i, int j) {
int cons = i - 1;
while (!str.substring(i, i + 1).equals("*")) {
if (i == str.length() - 2) { // 已经找到字符串尾端,则匹配最后一个找到的*
i = cons;
break;
} else if (str.substring(i, i + 1).equals(".") && j != 0) { // 当遇到字符"."后返回倒数第二次匹配的*,第一次匹配时忽略"."
while (!str.substring(i, i + 1).equals("*")) {
i = i - 1;
}
i = i - 1;
while (!str.substring(i, i + 1).equals("*")) {
i = i - 1;
}
return i;
}
i = i + 1;
}
return i;
}
// 方法startPos,返回(*start*)开始的位置,
public int startPos(String str, int pos) {
int cons = pos; // cons记录初始的start的*位置
pos = positionBackward(str, positionBackward(str, pos - 1, 1) - 1, 1);
if (pos == cons) { // 如果*的位置没有发生变化,说明此时的start的位置为最终匹配的位置(中间没有其他的),返回
return pos;
} else if ((str.substring(pos + 1, pos + 2)).equals("s")) { // 如果下一个还是start,则继续往下找,直到满足条件
startPos(str, pos);
} else {
pos = positionForward(str, positionForward(str, pos + 1, 1) + 1, 1);// 如果下一个是end,则回溯到前面一个start
}
return pos;
}
// 方法endPos,返回(*end*)开始的位置
public int endPos(String str, int pos) {
int cons = pos;
pos = positionForward(str, positionForward(str, pos + 1, 1) + 1, 1);
if (pos == cons) {
return pos;
} else if (str.substring(pos + 1, pos + 2).equals("e")) {
endPos(str, pos);
} else
pos = positionBackward(str, positionBackward(str, pos - 1, 1) - 1,
1);
return pos;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -