diff options
| author | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2019-07-21 16:24:47 -0300 |
|---|---|---|
| committer | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2019-07-21 16:24:47 -0300 |
| commit | 8c289f05ca36c3def6a4e4ab2414b7469c03339e (patch) | |
| tree | 9e97b6ea73b94ad831258b9bede0136a43530a39 /src/main/java/bjc/rgens/parser/RGrammar.java | |
| parent | 89668d36167846e002d0f6dcdc1034b5fee44ce3 (diff) | |
Refactor front-end error-handling
This refactors the front-end to use a tree for capturing errors, instead
of throwing exceptions.
This has the benefit that you will receive notifications about all of
the error messages you have, instead of only the first.
I'm a bit fuzzy on the details, since it's been a while since I wrote
these changes.
Diffstat (limited to 'src/main/java/bjc/rgens/parser/RGrammar.java')
| -rwxr-xr-x | src/main/java/bjc/rgens/parser/RGrammar.java | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/main/java/bjc/rgens/parser/RGrammar.java b/src/main/java/bjc/rgens/parser/RGrammar.java index 20ce320..018f2f0 100755 --- a/src/main/java/bjc/rgens/parser/RGrammar.java +++ b/src/main/java/bjc/rgens/parser/RGrammar.java @@ -1,7 +1,9 @@ package bjc.rgens.parser; import bjc.utils.data.IPair; +import bjc.utils.data.ITree; import bjc.utils.data.Pair; +import bjc.utils.data.Tree; import bjc.utils.funcutils.StringUtils; import bjc.utils.ioutils.ReportWriter; @@ -291,18 +293,27 @@ public class RGrammar { * initial rule. */ public void setInitialRule(String initRule) { + setInitialRule(initRule, new Tree<>()); + } + + public void setInitialRule(String initRule, ITree<String> errs) { /* Passing null, nulls our initial rule. */ if (initRule == null) { this.initialRule = null; + return; } if (initRule.equals("")) { - throw new GrammarException("The empty string is not a valid rule name"); + errs.addChild("ERROR: The empty string is not a valid rule name"); + + return; } else if (!rules.containsKey(initRule)) { - String msg = String.format("No rule '%s' local to this grammar (%s) defined.", initRule, name); + String msg = String.format("ERROR: No rule '%s' local to this grammar (%s) defined.", initRule, name); + + errs.addChild(msg); - throw new GrammarException(msg); + return; } initialRule = initRule; |
