blob: e1620965ab55280d379d35d4fa5d63274bff3ccd (
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
/* FIXME: Finer imports */
import java.io.*;
import java.util.regex.*;
import java.util.*;
public class QuickSolParser
{
private static final Pattern SOL_ITEM_PATTERN;
private final BufferedReader buffered_reader;
static
{
SOL_ITEM_PATTERN = Pattern.compile("\\((?<list>[a-zA-Z_0-9 \t]+)\\)");
}
public QuickSolParser (final String filename)
throws FileNotFoundException
{
buffered_reader = new BufferedReader(new FileReader(filename));
}
public void finalize ()
throws IOException
{
buffered_reader.close();
}
public List<String[]> next_solution ()
throws IOException
{
final List<String[]> result;
final Matcher matcher;
boolean has_started_sol;
String line;
result = new ArrayList<String[]>();
has_started_sol = false;
matcher = SOL_ITEM_PATTERN.matcher("");
for (;;)
{
line = buffered_reader.readLine();
if (line == null)
{
return null;
}
line = line.replaceAll("\\s+"," ");
if (line.equals(")"))
{
if (!has_started_sol)
{
throw
new IOException
(
"[E] Incorrect solution structure. (found a \")\" before a"
+ " \"(solution\""
);
}
return result;
}
else if (line.equals("(solution"))
{
if (has_started_sol)
{
throw
new IOException
(
"[E] Incorrect solution structure. (found a second"
+ "\"(solution\" before the \")\" ending the previous one."
);
}
has_started_sol = true;
}
else if (line.startsWith(";") || line.length() < 3)
{
continue;
}
else
{
final String[] item;
matcher.reset(line);
if (!matcher.find())
{
throw
new IOException
(
"[E] Incorrect solution structure. \""
+ line
+ "\" does not form a correct solution item."
);
}
item = matcher.group(1).split(" |\t");
if (item.length != 3)
{
throw
new IOException
(
"[E] Incorrect solution item. \""
+ line
+ "\" should match the form \"(NAME ID TAG)\"."
);
}
result.add(item);
}
}
}
}
|