1 | scope gazelle_addForbiddenBindingHelpers. |
2 | |
3 | sclass #Blocker { |
4 | S var, value; // value == null means don't change variable at all |
5 | bool debug; |
6 | |
7 | *() {} |
8 | *(S *var, S *value, bool *debug) {} |
9 | |
10 | SS get(SS map, LS tokC, LS tokI, RuleEngine2_MatchedRule matched) { |
11 | if (map == null) null; |
12 | if (value == null) { |
13 | if (map.containsKey(var)) null; |
14 | } else |
15 | if (eqic(value, map.get(var))) null; |
16 | ret map; |
17 | } |
18 | } |
19 | |
20 | sclass #TotalBlocker { |
21 | SS get(SS map, LS tokC, LS tokI, RuleEngine2_MatchedRule matched) { |
22 | if (nempty(map)) null; |
23 | ret map; |
24 | } |
25 | } |
26 | |
27 | sclass #BlockAllExcept { |
28 | Set<S> allowedVars; |
29 | |
30 | *() {} |
31 | *(Set<S> *allowedVars) {} |
32 | |
33 | SS get(SS map, LS tokC, LS tokI, RuleEngine2_MatchedRule matched) { |
34 | if (containsKeysExcept(map, allowedVars)) null; |
35 | ret map; |
36 | } |
37 | } |
38 | |
39 | svoid gazelle_addForbiddenBindingHelpers(RuleEngine2 engine, O... _) { |
40 | bool debug = boolPar debug(_) || boolPar forbiddenBindingsDebug(_); |
41 | for (final RuleEngine2.Rule r : engine.rules) { |
42 | for (Matches m : getJMatches_all("don't change * to *", r.comments)) |
43 | r.addMapMassager(new Blocker($1, $2, debug)); |
44 | for (Matches m : getJMatches_all("don't change *", r.comments)) |
45 | if (isQuoted(m.get(0))) |
46 | r.addMapMassager(new Blocker($1, null, debug)); |
47 | if (cic(r.comments, "don't change anything")) |
48 | r.addMapMassager(new TotalBlocker); |
49 | S var = matchAny_firstGroup("only var is *", r.comments); |
50 | if (var != null) |
51 | r.addMapMassager(new BlockAllExcept(litciset(var))); |
52 | } |
53 | } |
54 | |
55 | end scope |
Began life as a copy of #1021872
download show line numbers debug dex old transpilations
Travelled to 8 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, whxojlpjdney
No comments. add comment
Snippet ID: | #1021981 |
Snippet name: | gazelle_addForbiddenBindingHelpers |
Eternal ID of this version: | #1021981/9 |
Text MD5: | 0b77a589627ed4e52cd663f372e4386f |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-03-16 22:25:22 |
Source code size: | 1575 bytes / 55 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 243 / 298 |
Version history: | 8 change(s) |
Referenced in: | [show references] |