blob: eb1ba33dc2e75ee91e4798c2d40da30335003d83 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
/* 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-zA-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");
}
}
|