diff --git a/src/main/java/com/scenemaxeng/compiler/MacroFilter.java b/src/main/java/com/scenemaxeng/compiler/MacroFilter.java index e2714a9..c6d45ff 100644 --- a/src/main/java/com/scenemaxeng/compiler/MacroFilter.java +++ b/src/main/java/com/scenemaxeng/compiler/MacroFilter.java @@ -19,12 +19,17 @@ public class MacroFilter { private HashMap macroRules; - class LexicographicComparator implements Comparator { + static class LexicographicComparator implements Comparator { @Override public int compare(Object a, Object b) { - HashMap a1 = (HashMap) a; - HashMap b1 = (HashMap) b; - int len = a1.get("pat").length() - b1.get("pat").length(); + JSONObject a1 = (JSONObject) a; + JSONObject b1 = (JSONObject) b; + int len = 0; + try { + len = a1.getString("pat").length() - b1.getString("pat").length(); + } catch (JSONException e) { + e.printStackTrace(); + } if (len > 0) { return -1; @@ -91,15 +96,15 @@ public ApplyMacroResults apply(String prg) { List patternsSorted = new ArrayList<>();// patterns.toList(); for (int i = 0; i < patterns.length(); i++) { - patternsSorted.add(patterns.getString(i)); + patternsSorted.add(patterns.getJSONObject(i)); } Collections.sort(patternsSorted, new LexicographicComparator()); for (int i = 0; i < patternsSorted.size(); ++i) { - HashMap item = (HashMap) patternsSorted.get(i); + JSONObject item = (JSONObject) patternsSorted.get(i); - String pat = item.get("pat"); + String pat = item.getString("pat"); if (pat.length() == 0) { continue; } @@ -122,7 +127,7 @@ public ApplyMacroResults apply(String prg) { } } - String program = item.get("prg"); + String program = item.getString("prg"); Pattern p = Pattern.compile(pat); Matcher m = p.matcher(mr.finalPrg);