diff options
| author | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2018-09-05 13:45:22 -0300 |
|---|---|---|
| committer | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2018-09-05 13:45:22 -0300 |
| commit | dee4d326c7ab5b353813877e452cd72103e644b0 (patch) | |
| tree | 2f667be78f579dbcf2c80dabb8825b5e0fb0125e /src/main/java/bjc/rgens/parser/GenerationState.java | |
| parent | 7d84d243009e92f2a0ade353555cae824d5b2352 (diff) | |
Make variable grammar dependant
This makes variables scoped by grammar. Previously, you could set a
variable in one grammar, and access it from any grammar, as long as the
rule case that defined it was executed before hand. Now, only cases in
that grammar can use it.
There are still issues to do with the fact that variables can be used at
any time after they've been defined, even after their introductory rule
returned. I'm not certain that this is enough of an issue to bother
trying to fix it though.
The next step is an autovivify pragma for rules to solve several corner
cases, with the main one being wanting to use exhaustible variables from
prefix/suffix pragmas.
Diffstat (limited to 'src/main/java/bjc/rgens/parser/GenerationState.java')
| -rw-r--r-- | src/main/java/bjc/rgens/parser/GenerationState.java | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/main/java/bjc/rgens/parser/GenerationState.java b/src/main/java/bjc/rgens/parser/GenerationState.java index f5cbc60..382fba3 100644 --- a/src/main/java/bjc/rgens/parser/GenerationState.java +++ b/src/main/java/bjc/rgens/parser/GenerationState.java @@ -1,5 +1,6 @@ package bjc.rgens.parser; +import bjc.utils.esodata.MapSet; import bjc.utils.data.IPair; import bjc.utils.data.Pair; @@ -25,8 +26,8 @@ public class GenerationState { public Map<String, Rule> importRules; /** The current set of variables. */ - public Map<String, String> vars; - public Map<String, Rule> rlVars; + public MapSet<String, String> vars; + public MapSet<String, Rule> rlVars; private static final Random BASE = new Random(); @@ -44,10 +45,14 @@ public class GenerationState { */ public GenerationState(StringBuilder cont, Random rand, Map<String, String> vs, Map<String, Rule> rvs, RGrammar gram) { + vars = new MapSet<>(); + rlVars = new MapSet<>(); + contents = cont; rnd = rand; - vars = vs; - rlVars = rvs; + + vars.setPutMap(gram.name, vs); + rlVars.setPutMap(gram.name, rvs); this.gram = gram; @@ -71,6 +76,9 @@ public class GenerationState { rules = gram.getRules(); importRules = gram.getImportRules(); + + vars.setCreateMap(gram.name); + rlVars.setCreateMap(gram.name); } public GenerationState newBuf() { |
