From e9ff21333162f6b3a516d91d4c814d5ebb78d88c Mon Sep 17 00:00:00 2001 From: "Benjamin J. Culkin" Date: Wed, 5 Sep 2018 23:47:34 -0300 Subject: 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. --- .../java/bjc/rgens/parser/RGrammarBuilder.java | 37 +++++++++++++--------- 1 file changed, 22 insertions(+), 15 deletions(-) (limited to 'src/main/java/bjc/rgens/parser/RGrammarBuilder.java') diff --git a/src/main/java/bjc/rgens/parser/RGrammarBuilder.java b/src/main/java/bjc/rgens/parser/RGrammarBuilder.java index 1bc849b..535d818 100755 --- a/src/main/java/bjc/rgens/parser/RGrammarBuilder.java +++ b/src/main/java/bjc/rgens/parser/RGrammarBuilder.java @@ -350,33 +350,40 @@ public class RGrammarBuilder { public void addAutoRlVar(String name, CaseElement elm) { autoRlVars.put(name, elm); } - /* - * @TODO - * - * Figure out how this should work, and get this working. - */ - /* - public void regexizeRule(String rule, String pattern) { + + public void rejectRule(String rule, String reject) { if (rule == null) { throw new NullPointerException("rule must not be null"); - } else if(pattern == null) { - throw new NullPointerException("pattern must not be null"); + } else if(reject == null) { + throw new NullPointerException("reject must not be null"); } else if (rule.equals("")) { throw new IllegalArgumentException("The empty string is not a valid rule name"); } else if(!rules.containsKey(rule)) { throw new IllegalArgumentException(String.format("The rule '%s' doesn't exist", rule)); } - IList caseList = rules.get(rule).getCases(); + Rule rl = rules.get(rule); - IList newCaseList = new FunctionalList<>(); + rl.addRejection(reject); + } - for(RuleCase cse : caseList) { - newCaseList.add(new RegexRuleCase(cse.getElements(), pattern)); + public void findReplaceRule(String rule, String find, String replace) { + if (rule == null) { + throw new NullPointerException("rule must not be null"); + } else if(find == null) { + throw new NullPointerException("find must not be null"); + } else if(replace == null) { + throw new NullPointerException("replace must not be null"); + } else if (rule.equals("")) { + throw new IllegalArgumentException("The empty string is not a valid rule name"); + } else if(!rules.containsKey(rule)) { + throw new IllegalArgumentException(String.format("The rule '%s' doesn't exist", rule)); } - rules.get(rule).replaceCases(newCaseList); - }*/ + Rule rl = rules.get(rule); + + rl.addFindReplace(find, replace); + } /* * @NOTE -- cgit v1.2.3