diff options
Diffstat (limited to 'src/jcgp/backend/parsers/FunctionParser.java')
-rw-r--r-- | src/jcgp/backend/parsers/FunctionParser.java | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/src/jcgp/backend/parsers/FunctionParser.java b/src/jcgp/backend/parsers/FunctionParser.java index 806099e..081c08a 100644 --- a/src/jcgp/backend/parsers/FunctionParser.java +++ b/src/jcgp/backend/parsers/FunctionParser.java @@ -42,11 +42,11 @@ public abstract class FunctionParser { resources.println("[Parser] Error: could not find " + file.getAbsolutePath()); return; } - + Scanner in = new Scanner(fr); boolean excessFunctions = false; resources.println("[Parser] Parsing file: " + file.getAbsolutePath() + "..."); - + /* * The encoding used in .par files is quite simple, so regex matches are used to extract * the values. @@ -71,29 +71,32 @@ public abstract class FunctionParser { */ while (in.hasNextLine()) { String line = in.nextLine(); - if (line.substring(line.length() - 1).matches("[0-9]")) { - String[] splitString = line.split("[^0-9]+"); - int functionIndex = Integer.parseInt(splitString[splitString.length - 1]); - - if (functionIndex < functionSet.getTotalFunctionCount()) { - if (Integer.parseInt(splitString[0]) != 0) { - functionSet.enableFunction(functionIndex); - resources.println("[Parser] Enabled function: " + functionSet.getFunction(functionIndex)); - } else if (Integer.parseInt(splitString[0]) == 0) { - functionSet.disableFunction(functionIndex); - resources.println("[Parser] Disabled function: " + functionSet.getFunction(functionIndex)); + if (!line.isEmpty()) { + if (line.substring(line.length() - 1).matches("[0-9]")) { + String[] splitString = line.split("[^0-9]+"); + int functionIndex = Integer.parseInt(splitString[splitString.length - 1]); + + if (functionIndex < functionSet.getTotalFunctionCount()) { + if (Integer.parseInt(splitString[0]) != 0) { + functionSet.enableFunction(functionIndex); + resources.println("[Parser] Enabled function: " + functionSet.getFunction(functionIndex)); + } else if (Integer.parseInt(splitString[0]) == 0) { + functionSet.disableFunction(functionIndex); + resources.println("[Parser] Disabled function: " + functionSet.getFunction(functionIndex)); + } + } else { + excessFunctions = true; } - } else { - excessFunctions = true; } } + } - + // warn the user function index went out of bounds if (excessFunctions) { resources.println("[Parser] Warning: the parameter file contained more functions than the current function set"); } - + in.close(); resources.println("[Parser] Finished parsing functions"); } |