diff options
| author | bjculkin <bjculkin@mix.wvu.edu> | 2017-03-21 14:04:17 -0400 |
|---|---|---|
| committer | bjculkin <bjculkin@mix.wvu.edu> | 2017-03-21 14:04:17 -0400 |
| commit | e279644fc59f46916c20b0b4f941fd37b4f07675 (patch) | |
| tree | 7782b229f6482039ad0739079807294c14928085 /RGens/src/main/java/bjc/rgens/newparser/Rule.java | |
| parent | ba7e0a2c1efe4203f766f3192b8852c3bb7d3369 (diff) | |
Finish basic implementation
This finishes a basic implementation. It now handles literal strings and
rule references, allowing it to handle basic grammars.
Diffstat (limited to 'RGens/src/main/java/bjc/rgens/newparser/Rule.java')
| -rw-r--r-- | RGens/src/main/java/bjc/rgens/newparser/Rule.java | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/RGens/src/main/java/bjc/rgens/newparser/Rule.java b/RGens/src/main/java/bjc/rgens/newparser/Rule.java new file mode 100644 index 0000000..c479c87 --- /dev/null +++ b/RGens/src/main/java/bjc/rgens/newparser/Rule.java @@ -0,0 +1,50 @@ +package bjc.rgens.newparser; + +import bjc.utils.funcdata.FunctionalList; +import bjc.utils.funcdata.IList; + +/** + * A rule in a randomized grammar. + * + * @author EVE + * + */ +public class Rule { + /** + * The name of this grammar rule. + */ + public final String ruleName; + + private IList<RuleCase> ruleCases; + + /** + * Create a new grammar rule. + * + * @param ruleName + * The name of the grammar rule. + */ + public Rule(String ruleName) { + this.ruleName = ruleName; + + ruleCases = new FunctionalList<>(); + } + + /** + * Adds a case to the rule. + * + * @param cse + * The case to add. + */ + public void addCase(RuleCase cse) { + ruleCases.add(cse); + } + + /** + * Get a random case from this rule. + * + * @return A random case from this rule. + */ + public RuleCase getCase() { + return ruleCases.randItem(); + } +}
\ No newline at end of file |
