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 --- src/main/java/bjc/rgens/parser/RGrammarSet.java | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'src/main/java/bjc/rgens/parser/RGrammarSet.java') diff --git a/src/main/java/bjc/rgens/parser/RGrammarSet.java b/src/main/java/bjc/rgens/parser/RGrammarSet.java index a192da7..b110d21 100755 --- a/src/main/java/bjc/rgens/parser/RGrammarSet.java +++ b/src/main/java/bjc/rgens/parser/RGrammarSet.java @@ -15,14 +15,13 @@ public class RGrammarSet { public ConfigSet belongsTo; + public RGrammar exportGrammar; + /* Contains all the grammars in this set. */ private Map grammars; /* Contains all the exported rules from grammars. */ - private Map exportedRules; - - /* Contains which export came from which grammar. */ - private Map exportFrom; + private Map exportedRules; /* Contains which file a grammar was loaded from. */ public Map loadedFrom; @@ -36,8 +35,9 @@ public class RGrammarSet { exportedRules = new TreeMap<>(); - exportFrom = new HashMap<>(); loadedFrom = new HashMap<>(); + + exportGrammar = new RGrammar(exportedRules); } /** @@ -68,11 +68,9 @@ public class RGrammarSet { /* Process exports from the grammar. */ for (Rule export : gram.getExportedRules()) { if(exportedRules.containsKey(export.name)) - System.err.printf("WARN: Shadowing rule %s in %s from %s\n", export.name, exportFrom.get(export.name), grammarName); + System.err.printf("WARN: Shadowing rule %s in %s from %s\n", export.name, export.belongsTo.name, grammarName); - exportedRules.put(export.name, gram); - - exportFrom.put(export.name, grammarName); + exportedRules.put(export.name, export); if(DEBUG) System.err.printf("\t\tDEBUG: %s (%d cases) exported from %s\n", export.name, export.getCases().getSize(), grammarName); @@ -132,7 +130,7 @@ public class RGrammarSet { throw new IllegalArgumentException(msg); } - return exportedRules.get(exportName); + return exportedRules.get(exportName).belongsTo; } /** @@ -161,7 +159,12 @@ public class RGrammarSet { throw new IllegalArgumentException(msg); } - return exportFrom.getOrDefault(exportName, "Unknown"); + String nm = exportedRules.get(exportName).belongsTo.name; + if(nm == null) { + return "Unknown"; + } + + return nm; } /** -- cgit v1.2.3