From e279644fc59f46916c20b0b4f941fd37b4f07675 Mon Sep 17 00:00:00 2001 From: bjculkin Date: Tue, 21 Mar 2017 14:04:17 -0400 Subject: Finish basic implementation This finishes a basic implementation. It now handles literal strings and rule references, allowing it to handle basic grammars. --- RGens/src/main/java/bjc/rgens/newparser/Rule.java | 50 +++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 RGens/src/main/java/bjc/rgens/newparser/Rule.java (limited to 'RGens/src/main/java/bjc/rgens/newparser/Rule.java') 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 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 -- cgit v1.2.3