diff options
Diffstat (limited to 'src/main/java/bjc/rgens/parser/RGrammarTest.java')
| -rwxr-xr-x | src/main/java/bjc/rgens/parser/RGrammarTest.java | 113 |
1 files changed, 58 insertions, 55 deletions
diff --git a/src/main/java/bjc/rgens/parser/RGrammarTest.java b/src/main/java/bjc/rgens/parser/RGrammarTest.java index 0238fc0..25f76e7 100755 --- a/src/main/java/bjc/rgens/parser/RGrammarTest.java +++ b/src/main/java/bjc/rgens/parser/RGrammarTest.java @@ -24,71 +24,74 @@ public class RGrammarTest { try { /* Load a grammar set. */ Path cfgPath = Paths.get(rsc.toURI()); - RGrammarSet gramSet = ConfigLoader.fromConfigFile(cfgPath); + ConfigSet cfgSet = ConfigLoader.fromConfigFile(cfgPath); - /* Generate rule suggestions for all the grammars in the set. */ - for (String gramName : gramSet.getGrammars()) { - long startSuggTime = System.nanoTime(); + for(RGrammarSet gramSet : cfgSet.grammars.values()) { + testGrammarSet(gramSet); + } + } catch (IOException ioex) { + ioex.printStackTrace(); + } catch (URISyntaxException urisex) { + urisex.printStackTrace(); + } + } - gramSet.getGrammar(gramName).generateSuggestions(); + private static void testGrammarSet(RGrammarSet gramSet) { + /* Generate rule suggestions for all the grammars in the set. */ + for (String gramName : gramSet.getGrammars()) { + long startSuggTime = System.nanoTime(); - long endSuggTime = System.nanoTime(); + gramSet.getGrammar(gramName).generateSuggestions(); - long suggDur = endSuggTime - startSuggTime; + long endSuggTime = System.nanoTime(); - if(gramSet.PERF) - System.err.printf("PERF: Generated rule suggestions for %s in %d ns (%f s)\n", gramName, suggDur, suggDur / 1000000000.0); - } + long suggDur = endSuggTime - startSuggTime; + + System.err.printf("PERF: Generated rule suggestions for %s in %d ns (%f s)\n", gramName, suggDur, suggDur / 1000000000.0); + } + + System.err.printf("\n\n"); + + /* Generate for each exported rule. */ + for (String exportName : gramSet.getExportedRules()) { + /* Where we loaded the rule from. */ + String loadSrc = gramSet.loadedFrom(gramSet.exportedFrom(exportName)); - if(gramSet.PERF) - System.err.printf("\n\n"); - - /* Generate for each exported rule. */ - for (String exportName : gramSet.getExportedRules()) { - /* Where we loaded the rule from. */ - String loadSrc = gramSet.loadedFrom(gramSet.exportedFrom(exportName)); - - System.out.println(); - System.out.printf("Generating for exported rule '%s' from file '%s'\n", exportName, loadSrc); - - RGrammar grammar = gramSet.getExportSource(exportName); - long startGenTime = System.nanoTime(); - for (int i = 0; i < 100; i++) { - try { - String res = grammar.generate(exportName); - if(exportName.contains("+")) res = res.replaceAll("\\s+", ""); - - if(res.length() > 120) { - System.out.printf("\t\n\tContents: %s\n\t\n", res); - } else { - System.out.printf("\tContents: %s\n", res); - } - } catch (GrammarException gex) { - /* Print out errors with generation. */ - String fmt = "Error in exported rule '%s' (loaded from '%s')\n"; - - System.out.printf(fmt, exportName, loadSrc); - System.out.println(); - System.out.println(); - - System.err.printf(fmt, exportName, loadSrc); - gex.printStackTrace(); - - System.err.println(); - System.err.println(); + System.out.println(); + System.out.printf("Generating for exported rule '%s' from file '%s'\n", exportName, loadSrc); + + RGrammar grammar = gramSet.getExportSource(exportName); + long startGenTime = System.nanoTime(); + for (int i = 0; i < 100; i++) { + try { + String res = grammar.generate(exportName); + if(exportName.contains("+")) res = res.replaceAll("\\s+", ""); + + if(res.length() > 120) { + System.out.printf("\t\n\tContents: %s\n\t\n", res); + } else { + System.out.printf("\tContents: %s\n", res); } - } - long endGenTime = System.nanoTime(); + } catch (GrammarException gex) { + /* Print out errors with generation. */ + String fmt = "ERROR: Exported rule %s from %s failed (loaded from '%s')\n"; - long genDur = endGenTime - startGenTime; + System.out.printf(fmt, exportName, grammar.name, loadSrc); + System.out.println(); + System.out.println(); - if(gramSet.PERF) - System.err.printf("PERF: Generated %s 100 times in %d ns (%f s)\n\n\n", exportName, genDur, genDur / 1000000000.0); + System.err.printf(fmt, exportName, grammar.name, loadSrc); + gex.printStackTrace(); + + System.err.println(); + System.err.println(); + } } - } catch (IOException ioex) { - ioex.printStackTrace(); - } catch (URISyntaxException urisex) { - urisex.printStackTrace(); + long endGenTime = System.nanoTime(); + + long genDur = endGenTime - startGenTime; + + System.err.printf("PERF: Generated %s 100 times in %d ns (%f s)\n\n\n", exportName, genDur, genDur / 1000000000.0); } } } |
