| summaryrefslogtreecommitdiff |
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-09-18 10:46:34 +0200 |
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-09-18 10:46:34 +0200 |
| commit | 2e15b9f8a8be3bea2b0ed1cb633c2f35582e39b8 (patch) | |
| tree | 88587ce79357e1791075fdf3e8afb820225df864 /instance-calculator/src/QuickParser.java | |
| parent | 079af0e3eacb62e9e0cecedef7e0c7ddffe74275 (diff) | |
| parent | 77838a1342b53ca97d842ef47ff91f44f6a5bbeb (diff) | |
Merge branch 'master' of dreamhost:~/repositories/git/tabellion
Diffstat (limited to 'instance-calculator/src/QuickParser.java')
| -rw-r--r-- | instance-calculator/src/QuickParser.java | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/instance-calculator/src/QuickParser.java b/instance-calculator/src/QuickParser.java new file mode 100644 index 0000000..383373e --- /dev/null +++ b/instance-calculator/src/QuickParser.java @@ -0,0 +1,62 @@ +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.FileNotFoundException; + +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class QuickParser +{ + private static final Pattern instr_pattern; + private final BufferedReader buffered_reader; + + static + { + instr_pattern = Pattern.compile("\\((?<list>[a-z_0-9 \"]+)\\)"); + } + public QuickParser (final String filename) + throws FileNotFoundException + { + buffered_reader = new BufferedReader(new FileReader(filename)); + } + + public void finalize () + throws IOException + { + buffered_reader.close(); + } + + public String[] parse_line () + throws IOException + { + final List<String> result; + final Matcher matcher; + String line; + + do + { + line = buffered_reader.readLine(); + + if (line == null) + { + return new String[0]; + } + + line = line.replaceAll("\\s+"," "); + } + while (line.length() < 3 || line.startsWith(";")); + + matcher = instr_pattern.matcher(line); + + if (!matcher.find()) + { + System.err.println("[E] Invalid instruction \"" + line + "\""); + + return null; + } + + return matcher.group(1).split(" |\t"); + } +} |


