summaryrefslogtreecommitdiff
path: root/RGens/src/main/java/bjc/rgens/newparser/RGrammarBuilder.java
diff options
context:
space:
mode:
authorbjculkin <bjculkin@mix.wvu.edu>2017-03-22 17:10:50 -0400
committerbjculkin <bjculkin@mix.wvu.edu>2017-03-22 17:10:50 -0400
commit9d06ef82f53e156334ba86fbfedbdf02eb93552f (patch)
treec4d4d9c13a4c75580aa21974ebc80df26dd8cae3 /RGens/src/main/java/bjc/rgens/newparser/RGrammarBuilder.java
parent3cd931c1317ebe49cf109673640e0b2d916f884d (diff)
Reimplement more old features
Diffstat (limited to 'RGens/src/main/java/bjc/rgens/newparser/RGrammarBuilder.java')
-rw-r--r--RGens/src/main/java/bjc/rgens/newparser/RGrammarBuilder.java33
1 files changed, 27 insertions, 6 deletions
diff --git a/RGens/src/main/java/bjc/rgens/newparser/RGrammarBuilder.java b/RGens/src/main/java/bjc/rgens/newparser/RGrammarBuilder.java
index 27a9bb3..edd7e80 100644
--- a/RGens/src/main/java/bjc/rgens/newparser/RGrammarBuilder.java
+++ b/RGens/src/main/java/bjc/rgens/newparser/RGrammarBuilder.java
@@ -154,8 +154,6 @@ public class RGrammarBuilder {
throw new NullPointerException("init must not be null");
} else if(init.equals("")) {
throw new IllegalArgumentException("The empty string is not a valid rule name");
- } else if(!rules.containsKey(init)) {
- throw new IllegalArgumentException(String.format("No local rule named '%s' found", init));
}
initialRule = init;
@@ -176,8 +174,6 @@ public class RGrammarBuilder {
throw new NullPointerException("Export name must not be null");
} else if(export.equals("")) {
throw new NullPointerException("The empty string is not a valid rule name");
- } else if(!rules.containsKey(export)) {
- throw new IllegalArgumentException(String.format("No local rule named '%s' found", export));
}
exportedRules.add(export);
@@ -201,8 +197,6 @@ public class RGrammarBuilder {
throw new NullPointerException("Rule name must not be null");
} else if(ruleName.equals("")) {
throw new IllegalArgumentException("The empty string is not a valid rule name");
- } else if(!rules.containsKey(ruleName)) {
- throw new IllegalArgumentException(String.format("No local rule named '%s' found", ruleName));
}
CaseElement element = CaseElement.createElement(suffix);
@@ -211,4 +205,31 @@ public class RGrammarBuilder {
ruleCase.getElements().add(element);
}
}
+
+ /**
+ * Prefix a given case element to every case of a specific rule.
+ *
+ * @param ruleName
+ * The rule to prefix.
+ *
+ * @param prefix
+ * The prefix to add.
+ *
+ * @throws IllegalArgumentException
+ * If the rule name is either invalid or not defined by
+ * this grammar, or if the prefix is invalid.
+ */
+ public void prefixWith(String ruleName, String prefix) {
+ if(ruleName == null) {
+ throw new NullPointerException("Rule name must not be null");
+ } else if(ruleName.equals("")) {
+ throw new IllegalArgumentException("The empty string is not a valid rule name");
+ }
+
+ CaseElement element = CaseElement.createElement(prefix);
+
+ for(RuleCase ruleCase : rules.get(ruleName).getCases()) {
+ ruleCase.getElements().add(element);
+ }
+ }
}