-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGrammar.pde
50 lines (38 loc) · 1.22 KB
/
Grammar.pde
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
void loadDataFiles() {
databaseFiles = listFileNames(dataPath(databaseFilesLocation));
if (databaseFiles == null) {
println("Folder " + databaseFilesLocation + " does not exist or cannot be accessed.");
}
else {
println("Successfully loaded files.");
}
grammar = new RiGrammar(this, templateFile);
for (int i=0; i<databaseFiles.length; i++) {
String[] rows = loadStrings(databaseFilesLocation + "/" + databaseFiles[i]);
String definitionName = databaseFiles[i].substring(0, databaseFiles[i].lastIndexOf('.'));
grammar.setDefinition(definitionName, join(rows, " | "));
//println(databaseFiles[i] + ": " + join(rows, " | "));
}
}
void saveDataFile() {
String[] output = {
};
Map m = grammar.getDefinitions();
Iterator iterator = m.entrySet().iterator();
while (iterator.hasNext ()) {
Map.Entry mapEntry = (Map.Entry) iterator.next();
output = append(output, "{\n" + mapEntry.getKey() + "\n" + mapEntry.getValue() + "\n}");
}
saveStrings(dataFile, output);
}
String[] listFileNames(String dir) {
File file = new File(dir);
if (file.isDirectory()) {
String names[] = file.list();
return names;
}
else {
// If it’s not a directory
return null;
}
}