summaryrefslogtreecommitdiff
path: root/src/main/java/bjc/rgens/parser/RGrammarParser.java
diff options
context:
space:
mode:
authorBenjamin J. Culkin <bjculkin@mix.wvu.edu>2018-09-05 23:47:34 -0300
committerBenjamin J. Culkin <bjculkin@mix.wvu.edu>2018-09-05 23:49:26 -0300
commite9ff21333162f6b3a516d91d4c814d5ebb78d88c (patch)
tree4528022d0d8471aa8186646f1522e5232e35c8d1 /src/main/java/bjc/rgens/parser/RGrammarParser.java
parent22512137d4c5f6d0335887b6887d0f72215f2219 (diff)
Finally do something with regexizeRule
It now works, but is called find-replace-rule instead. There is also reject-rule, to say to reject any rule that doesn't match a provided regex. NOTE: For providing the regexes, if they contain spaces, they must be quoted.
Diffstat (limited to 'src/main/java/bjc/rgens/parser/RGrammarParser.java')
-rwxr-xr-xsrc/main/java/bjc/rgens/parser/RGrammarParser.java30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/main/java/bjc/rgens/parser/RGrammarParser.java b/src/main/java/bjc/rgens/parser/RGrammarParser.java
index 4014baa..a95cefc 100755
--- a/src/main/java/bjc/rgens/parser/RGrammarParser.java
+++ b/src/main/java/bjc/rgens/parser/RGrammarParser.java
@@ -169,18 +169,32 @@ public class RGrammarParser {
build.setBinomial(parts.get(0), Integer.parseInt(parts.get(1)), Integer.parseInt(parts.get(2)), Integer.parseInt(parts.get(3)));
});
- pragmas.put("regex-rule", (body, build, level) -> {
- int nameIndex = body.indexOf(" ");
+ /*
+ * @NOTE 4/9/18
+ *
+ * Consider if we want to replace this with something more akin
+ * to the `definer` feature from DiceLang. This will work fine
+ * in most cases, but there are some cases where you'd want the
+ * extra power. No examples are apparent at the moment.
+ */
+ pragmas.put("find-replace-rule", (body, build, level) -> {
+ List<String> bits = StringUtils.levelSplit(body, " ");
- if(nameIndex == -1) {
- throw new GrammarException("Regex-rule pragma takes two arguments: the name of the rule to process, then the regex to apply after the rule has been generated.");
+ if(bits.size() != 3) {
+ throw new GrammarException("Regex-rule pragma takes three arguments: the name of the rule to process, then the find/replace pair to apply after the rule has been generated.");
}
- String name = body.substring(0, nameIndex).trim();
- String patt = body.substring(nameIndex + 1).trim();
+ build.findReplaceRule(bits.get(0), bits.get(1), bits.get(2));
+ });
+
+ pragmas.put("reject-rule", (body, build, level) -> {
+ List<String> bits = StringUtils.levelSplit(body, " ");
+
+ if(bits.size() != 3) {
+ throw new GrammarException("Reject-rule pragma takes two arguments: the name of the rule to process, then the rejection pattern to apply after the rule has been generated.");
+ }
- throw new GrammarException("Regexize-rule pragma not yet supported");
- //build.regexizeRule(name, patt);
+ build.rejectRule(bits.get(0), bits.get(1));
});
pragmas.put("prefix-with", (body, build, level) -> {