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. --- .../rgens/parser/elements/InlineRuleCaseElement.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/main/java/bjc/rgens/parser/elements/InlineRuleCaseElement.java') diff --git a/src/main/java/bjc/rgens/parser/elements/InlineRuleCaseElement.java b/src/main/java/bjc/rgens/parser/elements/InlineRuleCaseElement.java index 917dd33..269cc4f 100644 --- a/src/main/java/bjc/rgens/parser/elements/InlineRuleCaseElement.java +++ b/src/main/java/bjc/rgens/parser/elements/InlineRuleCaseElement.java @@ -3,16 +3,23 @@ package bjc.rgens.parser.elements; import bjc.rgens.parser.GenerationState; import bjc.rgens.parser.RGrammarParser; -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.funcutils.StringUtils; import bjc.utils.gen.WeightedRandom; +import java.util.ArrayList; +import java.util.List; + public class InlineRuleCaseElement extends CaseElement { public final WeightedRandom elements; public InlineRuleCaseElement(String... parts) { + this(new Tree<>(), parts); + } + + public InlineRuleCaseElement(ITree errs, String... parts) { super(true); this.elements = new WeightedRandom<>(); @@ -26,10 +33,10 @@ public class InlineRuleCaseElement extends CaseElement { partArr = new String[] {part}; } - IPair, Integer> par = RGrammarParser.parseElementString(partArr); - int prob = par.getRight(); + List elms = new ArrayList<>(); + int prob = RGrammarParser.parseElementString(partArr, elms, errs); - for(CaseElement elm : par.getLeft()) { + for(CaseElement elm : elms) { elements.addProbability(prob, elm); } } -- cgit v1.2.3