Libraryless. Click here for Pure Java version (10756L/76K).
1 | scope gazelle_addVarDiscriminators. |
2 | |
3 | sclass #MechListContains extends F1<S, Bool> { |
4 | S list; |
5 | |
6 | *() {} |
7 | *(S *list) {} |
8 | |
9 | Bool get(S s) { |
10 | bool ok = mechCISetContains(list, s); |
11 | print("MechListContains: " + list + " / " + s + " => " + ok); |
12 | ret ok; |
13 | } |
14 | } |
15 | |
16 | sclass #VarDiscriminator { |
17 | S var; |
18 | O discriminator; // func(S value) -> bool |
19 | bool debug; |
20 | |
21 | *() {} |
22 | *(S *var, O *discriminator, bool *debug) {} |
23 | |
24 | SS get(SS map, LS tokC, LS tokI, RuleEngine2_MatchedRule matched) { |
25 | if (map == null) null; |
26 | S value = map.get(var); |
27 | if (value != null && !isTrue(callAndMake_orF1(discriminator, value))) { |
28 | if (debug) print("Rejecting var: " + var + " -> " + value + " because of " + discriminator); |
29 | null; |
30 | } |
31 | ret map; |
32 | } |
33 | } |
34 | |
35 | svoid gazelle_addVarDiscriminators(RuleEngine2 engine, O... _) { |
36 | bool debug = boolPar debug(_) || boolPar debugVarDiscriminators(_); |
37 | for (final RuleEngine2.Rule r : engine.rules) { |
38 | for (Matches m : getJMatches_all("var * should satisfy *", r.comments)) { |
39 | S var = $1, discriminator = $2; |
40 | if (debug) print("Made discriminator for: " + var); |
41 | r.addMapMassager(new VarDiscriminator(var, discriminator, debug)); |
42 | } |
43 | |
44 | for (Matches m : getJMatches_all("var * should be in list *", r.comments)) { |
45 | S var = $1, list = $2; |
46 | r.addMapMassager(new VarDiscriminator(var, MechListContains(list), debug)); |
47 | } |
48 | |
49 | for (Matches m : getJMatches_all("* has to be between * and *", r.comments)) { |
50 | S var = $1; |
51 | double min = parseDouble($2), max = parseDouble($3); |
52 | if (debug) print("Made discriminator for: " + var); |
53 | r.addMapMassager(new VarDiscriminator(var, func(S value) -> bool { |
54 | pcall-silent { |
55 | ret isBetween_double(parseDouble(or(value, var)), min, max); |
56 | } |
57 | false; |
58 | }, debug)); |
59 | } |
60 | |
61 | for (Matches m : getJMatches_all("* has to be * or *", r.comments)) { |
62 | S var = $1; |
63 | Set<S> values = litciset($2, $3); |
64 | if (debug) print("Made discriminator for: " + var); |
65 | r.addMapMassager(new VarDiscriminator(var, func(S value) -> bool { |
66 | contains(values, or(value, var)) |
67 | }, debug)); |
68 | } |
69 | } |
70 | } |
71 | |
72 | end scope |
Began life as a copy of #1021811
download show line numbers debug dex old transpilations
Travelled to 8 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1021865 |
Snippet name: | gazelle_addVarDiscriminators |
Eternal ID of this version: | #1021865/16 |
Text MD5: | 9f0dfceaa7694871253fe05cb2a59059 |
Transpilation MD5: | 61a3c67ef21db5b5bcd25383b9a9a2be |
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-21 12:35:08 |
Source code size: | 2262 bytes / 72 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 277 / 398 |
Version history: | 15 change(s) |
Referenced in: | [show references] |