summaryrefslogtreecommitdiff
path: root/src/main/java/bjc/rgens/parser/elements/InlineRuleCaseElement.java
diff options
context:
space:
mode:
authorBenjamin J. Culkin <bjculkin@mix.wvu.edu>2019-07-21 16:24:47 -0300
committerBenjamin J. Culkin <bjculkin@mix.wvu.edu>2019-07-21 16:24:47 -0300
commit8c289f05ca36c3def6a4e4ab2414b7469c03339e (patch)
tree9e97b6ea73b94ad831258b9bede0136a43530a39 /src/main/java/bjc/rgens/parser/elements/InlineRuleCaseElement.java
parent89668d36167846e002d0f6dcdc1034b5fee44ce3 (diff)
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.
Diffstat (limited to 'src/main/java/bjc/rgens/parser/elements/InlineRuleCaseElement.java')
-rw-r--r--src/main/java/bjc/rgens/parser/elements/InlineRuleCaseElement.java17
1 files changed, 12 insertions, 5 deletions
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<CaseElement> elements;
public InlineRuleCaseElement(String... parts) {
+ this(new Tree<>(), parts);
+ }
+
+ public InlineRuleCaseElement(ITree<String> errs, String... parts) {
super(true);
this.elements = new WeightedRandom<>();
@@ -26,10 +33,10 @@ public class InlineRuleCaseElement extends CaseElement {
partArr = new String[] {part};
}
- IPair<IList<CaseElement>, Integer> par = RGrammarParser.parseElementString(partArr);
- int prob = par.getRight();
+ List<CaseElement> elms = new ArrayList<>();
+ int prob = RGrammarParser.parseElementString(partArr, elms, errs);
- for(CaseElement elm : par.getLeft()) {
+ for(CaseElement elm : elms) {
elements.addProbability(prob, elm);
}
}