From 3b760ca916c6a88265e348d77ee1f6497dace0a4 Mon Sep 17 00:00:00 2001 From: "Benjamin J. Culkin" Date: Mon, 4 Jun 2018 16:47:54 -0300 Subject: Add line offset Blocks should now properly give absolute numbers as to where they are from --- .../java/bjc/rgens/parser/RGrammarBuilder.java | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) (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 20cba93..59f3a4c 100755 --- a/src/main/java/bjc/rgens/parser/RGrammarBuilder.java +++ b/src/main/java/bjc/rgens/parser/RGrammarBuilder.java @@ -272,9 +272,23 @@ public class RGrammarBuilder { newCaseList.add(new Pair<>(cse.getLeft(), new FlatRuleCase(cse.getRight().getElements()))); } + System.err.printf("\tTRACE: Despacing %d cases of rule %s\n", caseList.getSize(), ruleName); + rules.get(ruleName).replaceCases(newCaseList); } + public void setWeight(String ruleName) { + if (ruleName == null) { + throw new NullPointerException("ruleName must not be null"); + } else if (ruleName.equals("")) { + throw new IllegalArgumentException("The empty string is not a valid rule name"); + } else if (!rules.containsKey(ruleName)) { + throw new IllegalArgumentException(String.format("The rule '%s' doesn't exist", ruleName)); + } + + rules.get(ruleName).prob = Rule.ProbType.NORMAL; + } + public void setRuleRecur(String ruleName, int recurLimit) { if (ruleName == null) { throw new NullPointerException("ruleName must not be null"); @@ -286,6 +300,39 @@ public class RGrammarBuilder { rules.get(ruleName).recurLimit = recurLimit; } + + public void setDescent(String ruleName, int descentFactor) { + if (ruleName == null) { + throw new NullPointerException("ruleName must not be null"); + } else if (ruleName.equals("")) { + throw new IllegalArgumentException("The empty string is not a valid rule name"); + } else if (!rules.containsKey(ruleName)) { + throw new IllegalArgumentException(String.format("The rule '%s' doesn't exist", ruleName)); + } + + Rule rl = rules.get(ruleName); + + rl.prob = Rule.ProbType.DESCENDING; + rl.descentFactor = descentFactor; + } + + public void setBinomial(String ruleName, int target, int bound, int trials) { + if (ruleName == null) { + throw new NullPointerException("ruleName must not be null"); + } else if (ruleName.equals("")) { + throw new IllegalArgumentException("The empty string is not a valid rule name"); + } else if (!rules.containsKey(ruleName)) { + throw new IllegalArgumentException(String.format("The rule '%s' doesn't exist", ruleName)); + } + + Rule rl = rules.get(ruleName); + + rl.prob = Rule.ProbType.BINOMIAL; + + rl.target = target; + rl.bound = bound; + rl.trials = trials; + } /* * @TODO * -- cgit v1.2.3