diff options
| author | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2018-06-05 22:09:23 -0300 |
|---|---|---|
| committer | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2018-06-05 22:09:23 -0300 |
| commit | 05c9922b30cd0dcd2a452673c2e155215d074b19 (patch) | |
| tree | 80f2cc1cfd239761f3d74d20159f780c1673781b /src/main/java/bjc/rgens/parser/elements/CaseElement.java | |
| parent | f25d1062a56a81b17348b799e6d4d7e1dc12a1cc (diff) | |
Templates pt. 3
Templates should now work, though there is no syntax to reference them
from rules yet
In addition, several internal things have been changed so as to improve
code quality
Diffstat (limited to 'src/main/java/bjc/rgens/parser/elements/CaseElement.java')
| -rwxr-xr-x | src/main/java/bjc/rgens/parser/elements/CaseElement.java | 50 |
1 files changed, 8 insertions, 42 deletions
diff --git a/src/main/java/bjc/rgens/parser/elements/CaseElement.java b/src/main/java/bjc/rgens/parser/elements/CaseElement.java index d86d2d3..68f5368 100755 --- a/src/main/java/bjc/rgens/parser/elements/CaseElement.java +++ b/src/main/java/bjc/rgens/parser/elements/CaseElement.java @@ -79,54 +79,20 @@ public abstract class CaseElement { //System.out.printf("\t\tTRACE: special body is '%s'\n", specialBody); - if (specialBody.matches("\\$\\S+:=\\S+")) { - /* Handle expanding variable definitions. */ + if (specialBody.matches("\\S+:=\\S+")) { String[] parts = specialBody.split(":="); - - if (parts.length != 2) { - String msg = "Expanded variables must be a name and a definition, seperated by :="; - - throw new GrammarException(msg); - } - - /* Trim $ */ - return new ExpVariableCaseElement(parts[0].substring(1), parts[1]); - } else if (specialBody.matches("\\$\\S+=\\S+")) { - /* Handle regular variable definitions. */ - String[] parts = specialBody.split("="); - - if (parts.length != 2) { - String msg = "Variables must be a name and a definition, seperated by ="; - - throw new GrammarException(msg); + if(parts.length != 2) { + throw new GrammarException("Colon variables must have a name and a definition"); } - /* Trim $ */ - return new LitVariableCaseElement(parts[0].substring(1), parts[1]); - } else if (specialBody.matches("\\@\\S+:=\\S+")) { - /* Handle exhaustible rule variable definitions. */ - String[] parts = specialBody.split(":="); - - if (parts.length != 2) { - String msg = "Rule variables must be a name and a definition, seperated by ="; - - throw new GrammarException(msg); - } - - /* Trim $ */ - return new RuleVariableCaseElement(parts[0].substring(1), parts[1], true); - } else if (specialBody.matches("\\@\\S+=\\S+")) { - /* Handle rule variable definitions. */ + return VariableCaseElement.parseVariable(parts[0], parts[1], true); + } else if (specialBody.matches("\\S+=\\S+")) { String[] parts = specialBody.split("="); - - if (parts.length != 2) { - String msg = "Rule variables must be a name and a definition, seperated by ="; - - throw new GrammarException(msg); + if(parts.length != 2) { + throw new GrammarException("Variables must have a name and a definition"); } - /* Trim $ */ - return new RuleVariableCaseElement(parts[0].substring(1), parts[1], false); + return VariableCaseElement.parseVariable(parts[0], parts[1], false); } else if (specialBody.matches("empty")) { /* Literal blank, for empty cases. */ return new BlankCaseElement(); |
