diff options
| author | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2018-06-05 15:52:44 -0300 |
|---|---|---|
| committer | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2018-06-05 15:52:44 -0300 |
| commit | f25d1062a56a81b17348b799e6d4d7e1dc12a1cc (patch) | |
| tree | 1e2966389381204cf799732742b135fa85fad923 /src/main/java/bjc/rgens/parser/RGrammar.java | |
| parent | 0164b842d14675b0a28dd143d36923e690e75d27 (diff) | |
Templates pt.2
More work that leads towards getting templates working
Diffstat (limited to 'src/main/java/bjc/rgens/parser/RGrammar.java')
| -rwxr-xr-x | src/main/java/bjc/rgens/parser/RGrammar.java | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/main/java/bjc/rgens/parser/RGrammar.java b/src/main/java/bjc/rgens/parser/RGrammar.java index 381eac1..5ca26a4 100755 --- a/src/main/java/bjc/rgens/parser/RGrammar.java +++ b/src/main/java/bjc/rgens/parser/RGrammar.java @@ -31,6 +31,8 @@ import edu.gatech.gtri.bktree.MutableBkTree; * @author EVE */ public class RGrammar { + public RGrammarSet belongsTo; + public String name; /* The max distance between possible alternate rules. */ @@ -54,7 +56,7 @@ public class RGrammar { } /* The rules of the grammar. */ - private Map<String, Rule> rules; + public Map<String, Rule> rules; /* The rules imported from other grammars. */ private Map<String, RGrammar> importRules; /* The rules exported from this grammar. */ @@ -158,10 +160,16 @@ public class RGrammar { } } - Rule rl = rules.get(fromRule); + /* + * We don't search imports, so it will always belong to this + * grammar. + */ + Rule rl = state.findRule(fromRule, false).getRight(); + if(rl == null) + throw new GrammarException("Could not find rule " + rl.name); if(rl.doRecur()) { - RuleCase start = rules.get(fromRule).getCase(state.rnd); + RuleCase start = rl.getCase(state.rnd); System.err.printf("\tFINE: Generating %s (from %s in %s)\n", start, fromRule, name); generateCase(start, state); @@ -177,12 +185,11 @@ public class RGrammar { * * Do we want to perform this post-processing here, or elsewhere? */ - String body = state.contents.toString(); + return postprocessRes(state.contents.toString()); + } - /* - * Collapse duplicate spaces. - */ - body = body.replaceAll("\\s+", " "); + private String postprocessRes(String strang) { + String body = strang.replaceAll("\\s+", " "); /* * Remove extraneous spaces around punctutation marks. @@ -221,7 +228,6 @@ public class RGrammar { return body.trim(); } - /** * Generate a rule case. * |
