diff options
| author | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2018-06-03 23:59:30 -0300 |
|---|---|---|
| committer | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2018-06-04 00:01:28 -0300 |
| commit | 5c416488ef63b5004ca424de56894eb17712f116 (patch) | |
| tree | b16cb41e704f8046ce75d094bfe5968116d93dfe /src/main/java/bjc/rgens/parser/elements/RuleCaseElement.java | |
| parent | 63aaf20560a2c4037cab8a7ef5fd6251d6036a2d (diff) | |
Add recurrance limit
This controls the number of times a rule can be entered into during a
single generations, and is set to 5 by default
Diffstat (limited to 'src/main/java/bjc/rgens/parser/elements/RuleCaseElement.java')
| -rwxr-xr-x | src/main/java/bjc/rgens/parser/elements/RuleCaseElement.java | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/src/main/java/bjc/rgens/parser/elements/RuleCaseElement.java b/src/main/java/bjc/rgens/parser/elements/RuleCaseElement.java index b4a4b58..0869a2f 100755 --- a/src/main/java/bjc/rgens/parser/elements/RuleCaseElement.java +++ b/src/main/java/bjc/rgens/parser/elements/RuleCaseElement.java @@ -33,9 +33,17 @@ public abstract class RuleCaseElement extends StringCaseElement { /* :Postprocessing */ newState.contents = new StringBuilder(dst.generate(actName, state.rnd, state.vars)); } else if (state.rules.containsKey(actName)) { - RuleCase cse = state.rules.get(actName).getCase(state.rnd); + Rule rl = state.rules.get(actName); - state.gram.generateCase(cse, newState); + if(rl.doRecur()) { + RuleCase cse = rl.getCase(state.rnd); + + state.gram.generateCase(cse, newState); + + rl.endRecur(); + } else { + throw new RecurLimitException("Rule recurrence limit exceeded"); + } } else if (state.importRules.containsKey(actName)) { RGrammar dst = state.importRules.get(actName); @@ -50,17 +58,17 @@ public abstract class RuleCaseElement extends StringCaseElement { * Re-get this working again. */ /* - if (ruleSearcher != null) { - Set<Match<? extends String>> results = ruleSearcher.search(actName, MAX_DISTANCE); + if (ruleSearcher != null) { + Set<Match<? extends String>> results = ruleSearcher.search(actName, MAX_DISTANCE); - String[] resArray = results.stream().map(Match::getMatch).toArray((i) -> new String[i]); + String[] resArray = results.stream().map(Match::getMatch).toArray((i) -> new String[i]); - String msg = String.format("No rule '%s' defined (perhaps you meant %s?)", actName, - StringUtils.toEnglishList(resArray, false)); + String msg = String.format("No rule '%s' defined (perhaps you meant %s?)", actName, + StringUtils.toEnglishList(resArray, false)); - throw new GrammarException(msg); - } - */ + throw new GrammarException(msg); + } + */ String msg = String.format("No rule '%s' defined", actName); throw new GrammarException(msg); |
