From 0bca0d24a20ca713dd1c9ef042dcc64d3b795fef Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Sun, 29 Mar 2020 21:57:32 -0400 Subject: Fix up ReplPair There was something in ReplPair that was causing issues. Since we don't need any of the fancy ReplPair functionality, I ripped it all out, since it was causing issues (probably sorting-related, with a comparator or something missing somewhere) --- src/main/java/tlIItools/ReplPair.java | 327 +--------------------------------- 1 file changed, 4 insertions(+), 323 deletions(-) (limited to 'src/main/java/tlIItools/ReplPair.java') 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 @@ -65,25 +65,6 @@ public class ReplPair implements Comparable { } } - /** - * 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. */ @@ -105,8 +86,6 @@ public class ReplPair implements Comparable { */ public String replace; - private StageStatus stat = StageStatus.BOTH; - /** * Create a new blank replacement pair. */ @@ -231,15 +210,9 @@ public class ReplPair implements Comparable { int pno = 0; int defPrior = 1; - int defStage = 1; - - boolean defMulti = false; - - StageStatus defStatus = StageStatus.BOTH; - - List> stages = new ArrayList<>(); - stages.add(new ArrayList<>()); + List 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 { 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 { 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 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 tmpList = new ArrayList<>(); - tmpList.addAll(detals); - - for (List stageList : stages) { - List 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 -- cgit v1.2.3