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/RGrammarParser.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/RGrammarParser.java')
| -rwxr-xr-x | src/main/java/bjc/rgens/parser/RGrammarParser.java | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/main/java/bjc/rgens/parser/RGrammarParser.java b/src/main/java/bjc/rgens/parser/RGrammarParser.java index 9232013..827cbb6 100755 --- a/src/main/java/bjc/rgens/parser/RGrammarParser.java +++ b/src/main/java/bjc/rgens/parser/RGrammarParser.java @@ -81,6 +81,20 @@ public class RGrammarParser { } }); + pragmas.put("recur-limit", (body, build, level) -> { + String[] parts = body.split(" "); + + if(parts.length != 2) { + throw new GrammarException("Recur-limit pragma takes two arguments: the name of the rule to set the limit for, and the new value of the limit"); + } + + if(!parts[1].matches("\\A\\d+\\Z")) { + throw new GrammarException("Limit value must be an integer"); + } + + build.setRuleRecur(parts[0], Integer.parseInt(parts[1])); + }); + pragmas.put("regex-rule", (body, build, level) -> { int nameIndex = body.indexOf(" "); |
