summaryrefslogtreecommitdiff
path: root/RGens/src/main/java/bjc/rgens/newparser/Rule.java
diff options
context:
space:
mode:
Diffstat (limited to 'RGens/src/main/java/bjc/rgens/newparser/Rule.java')
-rw-r--r--RGens/src/main/java/bjc/rgens/newparser/Rule.java50
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