From 05c9922b30cd0dcd2a452673c2e155215d074b19 Mon Sep 17 00:00:00 2001 From: "Benjamin J. Culkin" Date: Tue, 5 Jun 2018 22:09:23 -0300 Subject: 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 --- .../bjc/rgens/parser/elements/CaseElement.java | 50 ++++------------------ 1 file changed, 8 insertions(+), 42 deletions(-) (limited to 'src/main/java/bjc/rgens/parser/elements/CaseElement.java') 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(); -- cgit v1.2.3