summaryrefslogtreecommitdiff
path: root/RGens/src/main/java/bjc/rgens/newparser/RGrammarTest.java
blob: 7d8ed9ce301889dd0fad4ab9815c5e5fa16876bc (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
package bjc.rgens.newparser;

import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Paths;

/**
 * Test for new grammar syntax.
 * 
 * @author EVE
 *
 */
public class RGrammarTest {
	/**
	 * Main method.
	 * 
	 * @param args
	 *                Unused CLI args.
	 */
	public static void main(String[] args) {
		URL rsc = RGrammarTest.class.getResource("/server-config-sample.cfg");

		try {
			RGrammarSet gramSet = RGrammarSet.fromConfigFile(Paths.get(rsc.toURI()));

			for(String gramName : gramSet.getGrammars()) {
				gramSet.getGrammar(gramName).generateSuggestions();
			}

			for(String exportName : gramSet.getExportedRules()) {
				RGrammar grammar = gramSet.getExportSource(exportName);

				for(int i = 0; i < 10; i++) {
					try {
						grammar.generate(exportName);
					} catch(GrammarException gex) {
						System.out.println("Error in exported rule " + exportName
								+ " (loaded from "
								+ gramSet.loadedFrom(gramSet.exportedFrom(exportName)));

						System.out.println();

						gex.printStackTrace();

						System.out.println();
						System.out.println();
					}
				}
			}
		} catch(IOException ioex) {
			ioex.printStackTrace();
		} catch(URISyntaxException urisex) {
			urisex.printStackTrace();
		}
	}
}