summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorBenjamin J. Culkin <bjculkin@mix.wvu.edu>2018-05-29 16:02:15 -0300
committerBenjamin J. Culkin <bjculkin@mix.wvu.edu>2018-05-29 16:02:57 -0300
commit986870048e06fa0de2dd81d244a78c43cd2aa769 (patch)
tree117a97ac40f95295b6fd115ae1ddf69f8073b38b /src/main
parentf1a762044a68c39465c89491fca94ec75651639c (diff)
Fix pragma error messages.
Malformed pragmas should now give better error messages.
Diffstat (limited to 'src/main')
-rwxr-xr-xsrc/main/java/bjc/rgens/parser/RGrammarBuilder.java28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/main/java/bjc/rgens/parser/RGrammarBuilder.java b/src/main/java/bjc/rgens/parser/RGrammarBuilder.java
index b4cb04a..284d1a2 100755
--- a/src/main/java/bjc/rgens/parser/RGrammarBuilder.java
+++ b/src/main/java/bjc/rgens/parser/RGrammarBuilder.java
@@ -46,9 +46,9 @@ public class RGrammarBuilder {
else if(rName.equals(""))
throw new IllegalArgumentException("The empty string is not a valid rule name");
- if(rules.containsKey(rName))
+ if(rules.containsKey(rName)) {
return rules.get(rName);
- else {
+ } else {
Rule ret = new Rule(rName);
rules.put(rName, ret);
@@ -87,6 +87,8 @@ 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("The rule '%s' doesn't exist", init));
}
initialRule = init;
@@ -106,6 +108,8 @@ 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("The rule '%s' doesn't exist", rules));
}
exportedRules.add(export);
@@ -130,7 +134,7 @@ public class RGrammarBuilder {
} else if (ruleName.equals("")) {
throw new IllegalArgumentException("The empty string is not a valid rule name");
} else if(!rules.containsKey(ruleName)) {
- String msg = String.format("Rule '%s' is not a valid rule name.");
+ String msg = String.format("Rule '%s' is not a valid rule name");
throw new IllegalArgumentException(msg);
}
@@ -149,6 +153,12 @@ public class RGrammarBuilder {
newCase.add(element);
+ /*
+ * @NOTE :AffixCasing
+ *
+ * Is this correct, or should we be mirroring the
+ * existing case type?
+ */
newCases.add(new RuleCase(NORMAL, newCase));
}
@@ -177,7 +187,7 @@ public class RGrammarBuilder {
} else if (ruleName.equals("")) {
throw new IllegalArgumentException("The empty string is not a valid rule name");
} else if(!rules.containsKey(ruleName)) {
- String msg = String.format("Rule '%s' is not a valid rule name.");
+ String msg = String.format("Rule '%s' is not a valid rule name");
throw new IllegalArgumentException(msg);
}
@@ -196,6 +206,12 @@ public class RGrammarBuilder {
newCase.add(elm);
}
+ /*
+ * @NOTE :AffixCasing
+ *
+ * Is this correct, or should we be mirroring the
+ * existing case type?
+ */
newCases.add(new RuleCase(NORMAL, newCase));
}
@@ -210,6 +226,8 @@ public class RGrammarBuilder {
throw new NullPointerException("ruleName 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("The rule '%s' doesn't exist", ruleName));
}
IList<RuleCase> caseList = rules.get(ruleName).getCases();
@@ -230,6 +248,8 @@ public class RGrammarBuilder {
throw new NullPointerException("pattern must not be null");
} else if (rule.equals("")) {
throw new IllegalArgumentException("The empty string is not a valid rule name");
+ } else if(!rules.containsKey(rule)) {
+ throw new IllegalArgumentException(String.format("The rule '%s' doesn't exist", rule));
}
IList<RuleCase> caseList = rules.get(rule).getCases();