diff options
| author | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2018-05-29 15:44:57 -0300 |
|---|---|---|
| committer | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2018-05-29 15:44:57 -0300 |
| commit | 03b9ed1601acfe323dc9b5360b8f2c2c972c8e04 (patch) | |
| tree | 72e33eec337b386e6d536f128da03a9d4f2f12fe /RGens/src/main/java/bjc/rgens/parser/RGrammars.java | |
| parent | d22367abbb07f020dfb387032e9b72a040a170f5 (diff) | |
| parent | 0faa5175b6f0de8835ed514615ac64135f406b29 (diff) | |
Merge branch 'working'
Diffstat (limited to 'RGens/src/main/java/bjc/rgens/parser/RGrammars.java')
| -rwxr-xr-x | RGens/src/main/java/bjc/rgens/parser/RGrammars.java | 67 |
1 files changed, 0 insertions, 67 deletions
diff --git a/RGens/src/main/java/bjc/rgens/parser/RGrammars.java b/RGens/src/main/java/bjc/rgens/parser/RGrammars.java deleted file mode 100755 index f74a756..0000000 --- a/RGens/src/main/java/bjc/rgens/parser/RGrammars.java +++ /dev/null @@ -1,67 +0,0 @@ -package bjc.rgens.parser; - -import java.io.IOException; -import java.net.URISyntaxException; -import java.net.URI; -import java.nio.file.FileSystem; -import java.nio.file.FileSystems; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.HashMap; -import java.util.Map; - -/** - * Get access to the included grammars. - * - * @author Ben Culkin - */ -public class RGrammars { - private static RGrammarSet gramSet; - - private static void loadSet() { - try { - URI rsc = RGrammarTest.class.getResource("/server-config-sample.cfg").toURI(); - - Map<String, String> env = new HashMap<>(); - env.put("create", "true"); - @SuppressWarnings("unused") - FileSystem zipfs = FileSystems.newFileSystem(rsc, env); - - Path cfgPath = Paths.get(rsc); - - gramSet = RGrammarSet.fromConfigFile(cfgPath); - } catch (IOException | URISyntaxException ex) { - RuntimeException rtex = new RuntimeException("Could not load grammars"); - - rtex.initCause(ex); - - throw rtex; - } - } - - /** - * Generate an exported rule. - * - * @param exportName - * The rule to generate. - * @return The generated rule - * @throws GrammarException - * If something went wrong. - */ - public static String generateExport(String exportName) throws GrammarException { - if (gramSet == null) - loadSet(); - - if (!gramSet.getExportedRules().contains(exportName)) { - throw new GrammarException(String.format("No exported rule named %s", exportName)); - } - - RGrammar gram = gramSet.getExportSource(exportName); - - String res = gram.generate(exportName); - if (exportName.contains("+")) - res = res.replaceAll("\\s+", ""); - - return res; - } -} |
