Skip to content

Commit

Permalink
Fixed issue with parser deleting data
Browse files Browse the repository at this point in the history
  • Loading branch information
rexc159 committed Mar 3, 2018
1 parent 69c1a58 commit a3c82a4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 22 deletions.
7 changes: 3 additions & 4 deletions src/StellarisDK/FileClasses/DataPattern.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@ public class DataPattern {
// Group 4-6: Recursion Pattern
// Group 7-9: Standard key value pair
// Group 10-12: String literal pair
// Group 13: Special match for tags
public static final Pattern sLre = Pattern.compile("([\\w:]+)(\\s*[=><]+\\s*)(hsv\\s*\\{.+?\\})|([\\w:]+)(\\s*[=><]+\\s*)\\{(.+?\\})|([\\w:]+)(\\s*[=><]+\\s*)([^\"]+?)\\s|([\\w:]+)(\\s*[=><]+\\s*)(.+?\")\\s*|(\\w+)");
// Group 13: Special match for tags
public static final Pattern sLre = Pattern.compile("([\\w:]+)(\\s*[=><]+\\s*)(hsv\\s*\\{.+?\\})|([\\w:]+)(\\s*[=><]+\\s*)\\{(.+?\\})|([\\w:]+)(\\s*[=><]+\\s*)([^\"]+?)\\s|([\\w:]+)(\\s*[=><]+\\s*)(.+?\")\\s*|([\\w\"]+)");

public static final Pattern color = Pattern.compile("(hsv|rgb)\\s*\\{\\s*([\\d.]+)\\s*([\\d.]+)\\s*([\\d.]+)\\s*\\}\\s?");

// Pattern matches for main data structure
// Group 1-4: Multi line recursion
// Group 5-8: Single line
// Group 9-10: Tags
public static final Pattern newCombine = Pattern.compile("(?m)^\\s?([\\w:]+)(\\s*[=<>]+\\s*)\\{\\s*(#.*)?[\\r\\n]([\\W\\D\\S]+?)^\\s?\\}|^\\s?(\\w+)(\\s*[=<>]+\\s*)([^#\\r\\n]+)(#.+)?|^\\s?([\\w:\"]+)\\s?");
public static final Pattern newCombine = Pattern.compile("(?m)^\\s?([\\w:]+)(\\s*[=<>]+\\s*)\\{\\s*(#.*)?[\\r\\n]([\\W\\D\\S]+?)^\\s?\\}|^\\s?(\\w+)(\\s*[=<>]+\\s*)([^#\\r\\n]+)(#.+)?");

// Mod Descriptor Specific Pattern
public static final Pattern mDSpec = Pattern.compile("(?s)(?m)^\\t?(\\w+)=\\{[\\r\\n](.+?)^\\}");
Expand Down
44 changes: 29 additions & 15 deletions src/StellarisDK/FileClasses/GenericData.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,25 @@ private ArrayList sLrecursion(String input) {
ArrayList data = new ArrayList() {
@Override
public String toString() {
GenericData.changeTab(true);
String tabs = "\r\n";
for (int k = 0; k < GenericData.getTab(); k++) {
tabs += "\t";
}
String out = "{";
for (Object item : this) {
out += tabs+item;
if (size() != 0 && this.get(0) instanceof VPair) {
GenericData.changeTab(true);
String tabs = "\r\n";
for (int k = 0; k < GenericData.getTab(); k++) {
tabs += "\t";
}
String out = "{";
for (Object item : this) {
out += tabs + item;
}
GenericData.changeTab(false);
return out + tabs.replaceFirst("\t", "") + "}";
} else {
String out = "{ ";
for (Object item : this) {
out += item + " ";
}
return out + "}";
}
GenericData.changeTab(false);
return out + tabs.replaceFirst("\t", "") + "}";
}
};
Matcher matcher = DataPattern.sLre.matcher(input);
Expand Down Expand Up @@ -182,9 +190,9 @@ public Object load(String input) {
if (matcher.group(7).contains("{")) {
ValueTriplet dat;
Matcher color = DataPattern.color.matcher(matcher.group(7));
if(color.find()){
dat = new ValueTriplet<>(matcher.group(6).trim(), new StellarisColor(color.group(1).trim(),color.group(2).trim(),color.group(3).trim(),color.group(4).trim()), size++);
}else{
if (color.find()) {
dat = new ValueTriplet<>(matcher.group(6).trim(), new StellarisColor(color.group(1).trim(), color.group(2).trim(), color.group(3).trim(), color.group(4).trim()), size++);
} else {
dat = new ValueTriplet<>(matcher.group(6).trim(), sLrecursion(matcher.group(7)), size++);
}
if (data.containsKey(matcher.group(5))) {
Expand All @@ -207,8 +215,14 @@ public Object load(String input) {
} else if (matcher.group(1) != null) {
temp = new PairArrayList();
int order = size++;
DataMap secMap = (DataMap) load(matcher.group(4).replaceAll("(?m)^\t", ""));
ValueTriplet dat = new ValueTriplet<>(matcher.group(2).trim(), secMap, order);
DataMap secMap;
ValueTriplet dat;
if(!matcher.group(4).contains("=")){
dat = new ValueTriplet<>(matcher.group(2).trim(), sLrecursion(matcher.group(4).trim().replaceAll("[\\t\\n\\r]", " ")), order);
}else{
secMap = (DataMap) load(matcher.group(4).replaceAll("(?m)^\t", ""));
dat = new ValueTriplet<>(matcher.group(2).trim(), secMap, order);
}
temp.add(dat);
if (data.containsKey(matcher.group(1).trim())) {
data.get(matcher.group(1).trim()).add(dat);
Expand Down
6 changes: 3 additions & 3 deletions src/StellarisDK/FileClasses/Helper/DataMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public Object[] compressToPairArray() {
try {
if (((ValueTriplet) data).getValue() != null)
objs[((ValueTriplet) data).getOrder()] = new ValueTriplet<>(key, ((ValueTriplet) data).toPair(), ((ValueTriplet) data).getOrder());
} catch (StackOverflowError e) {
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("[ERROR] StackOverFlow, FROM: DataMap");
System.out.println("[ERROR] CAUSE: Tried " + ((ValueTriplet) data).getOrder());
System.out.println("[ERROR] SIZE: " + getFullSize());
System.out.println("[ERROR] CAUSE: Tried " + key + " Value: " + ((ValueTriplet) data).getKey());
System.out.println("[ERROR] SIZE: " + getFullSize() + ", Actual: " + ((ValueTriplet) data).getOrder());
}
}
}
Expand Down

0 comments on commit a3c82a4

Please sign in to comment.