diff options
| author | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2018-05-29 16:02:15 -0300 |
|---|---|---|
| committer | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2018-05-29 16:02:57 -0300 |
| commit | 986870048e06fa0de2dd81d244a78c43cd2aa769 (patch) | |
| tree | 117a97ac40f95295b6fd115ae1ddf69f8073b38b | |
| parent | f1a762044a68c39465c89491fca94ec75651639c (diff) | |
Fix pragma error messages.
Malformed pragmas should now give better error messages.
| -rwxr-xr-x | data/todos.txt | 6 | ||||
| -rwxr-xr-x | src/main/java/bjc/rgens/parser/RGrammarBuilder.java | 28 | ||||
| -rwxr-xr-x | todos.txt | 10 |
3 files changed, 32 insertions, 12 deletions
diff --git a/data/todos.txt b/data/todos.txt index 1de8841..9ea08a2 100755 --- a/data/todos.txt +++ b/data/todos.txt @@ -1,2 +1,8 @@ :TODO 5/10/18 Ben Culkin :EasternSun Finish up the new-style Diablo generator, using Eastern Sun things + +@TODO 10/11/17 Ben Culkin :GrammarReorg + Better organize the provided sample grammars. + +@TODO 5/29/18 Ben Culkin :Spacing + Convert grammars into using despace-rule where possible. 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(); @@ -1,6 +1,3 @@ -@TODO 10/11/17 Ben Culkin :GrammarReorg - Better organize the provided sample grammars. - @TODO 10/11/17 Ben Culkin :Determinism Add a way to get the grammar to pick rules in a deterministic fashion, so as to be able to iterate all of the rules. @@ -23,8 +20,8 @@ kind of pragma to convert a rule to a single-level spacer? ADDENDA: 10/24/17 - We now have a partial solution in 'despace-rule'. Now, grammars need to - be adapted to use it. + We now have a partial solution in 'despace-rule'. However, this doesn't + quite work in some cases. Why is that? @TODO 10/23/17 Ben Culkin :Pluralizing Add some way to say to pluralize the contents of a rule @@ -51,6 +48,3 @@ @TODO 5/10/18 Ben Culkin :RuleInclusion Add some way to sort of 'import' a rules body into another rule so as to not throw off probability by splitting. - -@TODO 5/18/18 Ben Culkin :PragmaErrors - Give better error messages for malformed pragmas |
