| summaryrefslogtreecommitdiff |
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-08-29 00:05:39 +0200 |
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-08-29 00:05:39 +0200 |
| commit | f1dfb1eb04a705521238dba64e09bb9ecdea794f (patch) | |
| tree | e8cd8d7349cd5008160e4a19c1e788241dd11b7b /instance-calculator/src/QuickParser.java | |
| parent | ee9d405bc917be3f596ccd2ffd2d7ddc01687d31 (diff) | |
Starting to get an idea of how it's going to work.
Diffstat (limited to 'instance-calculator/src/QuickParser.java')
| -rw-r--r-- | instance-calculator/src/QuickParser.java | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/instance-calculator/src/QuickParser.java b/instance-calculator/src/QuickParser.java new file mode 100644 index 0000000..47cea27 --- /dev/null +++ b/instance-calculator/src/QuickParser.java @@ -0,0 +1,58 @@ +/* FIXME: Finer imports */ +import java.io.*; +import java.util.regex.*; +import java.util.*; + +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"); + } +} |


