summaryrefslogtreecommitdiff
path: root/src/main/java/tlIItools/ReplPair.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/tlIItools/ReplPair.java')
-rw-r--r--src/main/java/tlIItools/ReplPair.java327
1 files changed, 4 insertions, 323 deletions
diff --git a/src/main/java/tlIItools/ReplPair.java b/src/main/java/tlIItools/ReplPair.java
index 5830db3f..74012716 100644
--- a/src/main/java/tlIItools/ReplPair.java
+++ b/src/main/java/tlIItools/ReplPair.java
@@ -66,25 +66,6 @@ public class ReplPair implements Comparable<ReplPair> {
}
/**
- * Possible statuses of pairs with respect to exporting.
- * @author Ben Culkin
- */
- public static enum StageStatus {
- /**
- * Only use for staging pairs; don't export.
- */
- INTERNAL,
- /**
- * Don't use for staging pairs; do export.
- */
- EXTERNAL,
- /**
- * Use for staging pairs; do export.
- */
- BOTH;
- }
-
- /**
* The priority for this replacement.
*/
public int priority;
@@ -105,8 +86,6 @@ public class ReplPair implements Comparable<ReplPair> {
*/
public String replace;
- private StageStatus stat = StageStatus.BOTH;
-
/**
* Create a new blank replacement pair.
*/
@@ -231,15 +210,9 @@ public class ReplPair implements Comparable<ReplPair> {
int pno = 0;
int defPrior = 1;
- int defStage = 1;
-
- boolean defMulti = false;
-
- StageStatus defStatus = StageStatus.BOTH;
-
- List<List<ReplPair>> stages = new ArrayList<>();
- stages.add(new ArrayList<>());
+ List<ReplPair> resList = new ArrayList<>();
+
// For every line in the source...
while (scn.hasNextLine()) {
String name = scn.nextLine().trim();
@@ -249,181 +222,8 @@ public class ReplPair implements Comparable<ReplPair> {
if (name.equals("")) continue;
if (name.startsWith("#")) continue;
- // Global control. Process it.
- if (name.startsWith("|//")) {
- name = name.substring(3);
-
- // Split out each control
- String[] bits = name.split(";");
-
- for (String bit : bits) {
- String bitHead = bit.toUpperCase();
- String bitBody = bit;
-
- int idx = bit.indexOf('/');
- if (idx != -1) {
- bitHead = bit.substring(0, idx).toUpperCase();
- bitBody = bit.substring(idx + 1);
- }
-
- switch (bitHead) {
- case "P":
- try {
- defPrior = Integer.parseInt(bitBody);
- } catch (NumberFormatException nfex) {
- String errMsg = String.format("'%s' is not a valid priority (must be an integer)", bitBody);
- errs.add(new ReplError(lno, pno, errMsg, name));
- }
- break;
- case "S":
- try {
- int tmpStage = Integer.parseInt(bitBody);
- if (tmpStage < 0) {
- String errMsg = String.format("'%s' is not a valid stage (must be a positive integer)", bitBody);
- errs.add(new ReplError(lno, pno, errMsg, name));
-
- break;
- }
- defStage = tmpStage;
- } catch (NumberFormatException nfex) {
- String errMsg = String.format("'%s' is not a valid stage (must be a positive integer)", bitBody);
- errs.add(new ReplError(lno, pno, errMsg, name));
- }
- break;
- case "MT":
- defMulti = true;
- break;
- case "MF":
- defMulti = false;
- break;
- case "M":
- defMulti = Boolean.parseBoolean(bitBody);
- break;
- case "I":
- defStatus = StageStatus.INTERNAL;
- break;
- case "E":
- defStatus = StageStatus.EXTERNAL;
- break;
- case "B":
- defStatus = StageStatus.BOTH;
- break;
- default:
- errs.add(new ReplError(lno, pno, String.format("Invalid control name '%s'", bitHead), name));
- break;
- }
- }
-
- continue;
- }
-
ReplPair rp = new ReplPair();
rp.priority = defPrior;
- rp.stat = defStatus;
-
- int stage = defStage;
-
- boolean isMulti = defMulti;
-
- // Name has attached controls, process them.
- if (name.startsWith("//")) {
- name = name.substring(2);
-
- int idx = name.indexOf("//");
- if (idx == -1) {
- String msg = "Did not find control terminator (//) in name where it should be";
-
- errs.add(new ReplError(lno, pno, msg, name));
- continue;
- }
-
- String contName = name.substring(0, idx);
- String actName = name.substring(idx + 2);
-
- // Split out each control
- String[] bits = contName.split(";");
-
- for (String bit : bits) {
- String bitHead = bit.toUpperCase();
- String bitBody = bit;
-
- idx = bit.indexOf('/');
- if (idx != -1) {
- bitHead = bit.substring(0, idx).toUpperCase();
- bitBody = bit.substring(idx + 1);
- }
-
- switch (bitHead) {
- case "N":
- rp.name = bitBody;
- break;
- case "P":
- try {
- rp.priority = Integer.parseInt(bitBody);
- } catch (NumberFormatException nfex) {
- String errMsg = String.format("'%s' is not a valid priority (must be an integer)", bitBody);
- errs.add(new ReplError(lno, pno, errMsg, name));
- }
- break;
- case "S":
- try {
- int tmpStage = Integer.parseInt(bitBody);
- if (tmpStage < 0) {
- String errMsg = String.format("'%s' is not a valid stage (must be a positive integer)", bitBody);
- errs.add(new ReplError(lno, pno, errMsg, name));
-
- break;
- }
- stage = tmpStage;
- } catch (NumberFormatException nfex) {
- String errMsg = String.format("'%s' is not a valid stage (must be a positive integer)", bitBody);
- errs.add(new ReplError(lno, pno, errMsg, name));
- }
- break;
- case "MT":
- isMulti = true;
- break;
- case "MF":
- isMulti = false;
- break;
- case "M":
- isMulti = Boolean.parseBoolean(bitBody);
- break;
- case "I":
- rp.stat = StageStatus.INTERNAL;
- break;
- case "E":
- rp.stat = StageStatus.EXTERNAL;
- break;
- case "B":
- rp.stat = StageStatus.BOTH;
- break;
- default:
- errs.add(new ReplError(lno, pno, String.format("Unknown control name '%s'", bitHead), name));
- break;
- }
- }
-
- // Multi-line name with a trailer
- if (isMulti) {
- String tmp = actName;
-
- while (tmp.endsWith("\\")) {
- boolean incNL = tmp.endsWith("|\\");
-
- if (!scn.hasNextLine()) break;
-
- tmp = scn.nextLine().trim();
-
- if (tmp.equals("")) continue;
- if (tmp.startsWith("#")) continue;
-
- actName = String.format("%s%s%s", actName, incNL ? "\n" : "", tmp);
- }
- }
-
- name = actName;
- }
rp.find = name;
if (rp.name == null) rp.name = name;
@@ -447,132 +247,13 @@ public class ReplPair implements Comparable<ReplPair> {
lno += 1;
} while (body.startsWith("#"));
- isMulti = defMulti;
-
- // Body has attached controls, process them.
- if (body.startsWith("//")) {
- body = body.substring(2);
-
- int idx = body.indexOf("//");
- if (idx == -1) {
- String msg = "Did not find control terminator (//) in body where it should be";
-
- errs.add(new ReplError(lno, pno, msg, body));
- continue;
- }
-
- String contBody = body.substring(0, idx);
- String actBody = body.substring(idx + 2);
-
- // Split out each control
- String[] bits = actBody.split(";");
-
- for (String bit : bits) {
- String bitHead = bit.toUpperCase();
- String bitBody = bit;
-
- idx = bit.indexOf('/');
- if (idx != -1) {
- bitHead = bit.substring(0, idx).toUpperCase();
- bitBody = bit.substring(idx + 1);
- }
-
- switch (bitHead) {
- case "MT":
- isMulti = true;
- break;
- case "MF":
- isMulti = false;
- break;
- case "M":
- isMulti = Boolean.parseBoolean(bitBody);
- break;
- default:
- errs.add(new ReplError(lno, pno, String.format("Invalid control name '%s'", bitHead), body));
- break;
- }
- }
-
- // Multi-line name with a trailer
- if (isMulti) {
- String tmp = actBody;
-
- while (tmp.endsWith("\\")) {
- boolean incNL = tmp.endsWith("|\\");
-
- if (!scn.hasNextLine()) break;
-
- tmp = scn.nextLine().trim();
-
- if (tmp.startsWith("#")) continue;
-
- actBody = String.format("%s%s%s", actBody, incNL ? "\n" : "", tmp);
- }
- }
-
- body = actBody;
- }
rp.replace = body;
- List<ReplPair> stageList;
- if (stages.size() < stage) {
- stageList = stages.get(stage);
-
- if (stageList == null) {
- stageList = new ArrayList<>();
- stages.set(stage, stageList);
- }
- } else {
- stageList = new ArrayList<>();
- stages.add(stage, stageList);
- }
-
- stageList.add(rp);
- }
-
- // Special-case one-stage processing.
- if (stages.size() == 1) {
- detals.addAll(stages.iterator().next());
-
- detals.sort(null);
-
- return detals;
+ resList.add(rp);
}
- // Handle stages
- List<ReplPair> tmpList = new ArrayList<>();
- tmpList.addAll(detals);
-
- for (List<ReplPair> stageList : stages) {
- List<ReplPair> curStage = new ArrayList<>();
-
- for (ReplPair rp : stageList) {
- // Process through every pair in the previous
- // stages
- for (ReplPair curPar : tmpList) {
- rp.replace = rp.replace.replaceAll(curPar.find, curPar.replace);
- }
-
- // If we're external; add straight to the output
- if (rp.stat == StageStatus.EXTERNAL) detals.add(rp);
- else curStage.add(rp);
- }
-
- tmpList.addAll(curStage);
- tmpList.sort(null);
- }
-
- // Copy over to output, excluding internals
- for (ReplPair rp : tmpList) {
- if (rp.stat == StageStatus.INTERNAL) continue;
-
- detals.add(rp);
- }
-
- detals.sort(null);
-
- return detals;
+ return resList;
}
@Override