From a13f1f396d28c0b900a10bede57f30be3a35003a Mon Sep 17 00:00:00 2001 From: "Benjamin J. Culkin" Date: Sun, 3 Jun 2018 19:27:43 -0300 Subject: Enable multi-prefixing/suffixing You can now provide multiple prefix/suffix elements, and all of the permutations of them will be applied. For example, providing the elements A & B, will yield the following permutations * A * B * A B * B A --- src/main/java/bjc/rgens/parser/RGrammarSet.java | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src/main/java/bjc/rgens/parser/RGrammarSet.java') diff --git a/src/main/java/bjc/rgens/parser/RGrammarSet.java b/src/main/java/bjc/rgens/parser/RGrammarSet.java index 975510a..c797b8c 100755 --- a/src/main/java/bjc/rgens/parser/RGrammarSet.java +++ b/src/main/java/bjc/rgens/parser/RGrammarSet.java @@ -7,6 +7,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.HashMap; import java.util.Map; +import java.util.TreeMap; import java.util.Scanner; import java.util.Set; @@ -34,7 +35,7 @@ public class RGrammarSet { exportedRules = new HashMap<>(); - exportFrom = new HashMap<>(); + exportFrom = new TreeMap<>(); loadedFrom = new HashMap<>(); } @@ -256,14 +257,16 @@ public class RGrammarSet { */ Path convPath = cfgParent.resolve(path.toString()); - //if(Files.isDirectory(convPath)) { - // /* @TODO implement subset grammars */ - // throw new GrammarException("Sub-grammar sets aren't implemented yet"); - //} else if (convPath.getFileName().endsWith(".gram")) { + if(Files.isDirectory(convPath)) { + /* @TODO implement subset grammars */ + throw new GrammarException("Sub-grammar sets aren't implemented yet"); + } else if (convPath.getFileName().toString().endsWith(".gram")) { /* Load grammar file. */ try { + BufferedReader fis = Files.newBufferedReader(convPath); RGrammar gram = RGrammarParser.readGrammar(fis); + fis.close(); /* Add grammar to the set. */ @@ -278,10 +281,10 @@ public class RGrammarSet { String msg = String.format("Error loading file '%s'", path); throw new GrammarException(msg, gex); } - //} else { - // String msg = String.format("Unrecognized file type '%s'", convPath.getFileName()); - // throw new GrammarException(msg); - //} + } else { + String msg = String.format("Unrecognized file type '%s'", convPath.getFileName()); + throw new GrammarException(msg); + } } } -- cgit v1.2.3