From 8c289f05ca36c3def6a4e4ab2414b7469c03339e Mon Sep 17 00:00:00 2001 From: "Benjamin J. Culkin" Date: Sun, 21 Jul 2019 16:24:47 -0300 Subject: Refactor front-end error-handling This refactors the front-end to use a tree for capturing errors, instead of throwing exceptions. This has the benefit that you will receive notifications about all of the error messages you have, instead of only the first. I'm a bit fuzzy on the details, since it's been a while since I wrote these changes. --- src/main/java/bjc/rgens/parser/Rule.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/main/java/bjc/rgens/parser/Rule.java') diff --git a/src/main/java/bjc/rgens/parser/Rule.java b/src/main/java/bjc/rgens/parser/Rule.java index 1a74352..377da9e 100755 --- a/src/main/java/bjc/rgens/parser/Rule.java +++ b/src/main/java/bjc/rgens/parser/Rule.java @@ -1,6 +1,8 @@ package bjc.rgens.parser; import bjc.utils.data.IPair; +import bjc.utils.data.ITree; +import bjc.utils.data.Tree; import bjc.utils.funcdata.FunctionalList; import bjc.utils.funcdata.IList; import bjc.utils.gen.WeightedRandom; @@ -121,20 +123,32 @@ public class Rule { } public void addRejection(String reject) { + addRejection(reject, new Tree<>()); + } + + public void addRejection(String reject, ITree errs) { try { Pattern.compile(reject); } catch (PatternSyntaxException psex) { - throw new GrammarException(String.format("String %s is not a valid regex for rejection", reject), psex); + String msg = String.format("ERROR: '%s' is not a valid regex for rejection (%s)", reject, psex.getMessage()); } rejectionPreds.add(reject); } public void addFindReplace(String find, String replace) { + addFindReplace(find, replace, new Tree<>()); + } + + public void addFindReplace(String find, String replace, ITree errs) { try { Pattern.compile(find); } catch (PatternSyntaxException psex) { - throw new GrammarException(String.format("String %s is not a valid regex for finding", find), psex); + String msg = String.format("ERROR: '%s' is not a valid regex for finding (%s)", find, psex.getMessage()); + + errs.addChild(msg); + + return; } findReplaces.add(pair(find, replace)); -- cgit v1.2.3