Libraryless. Click here for Pure Java version (10756L/76K).
scope gazelle_addVarDiscriminators. sclass #MechListContains extends F1<S, Bool> { S list; *() {} *(S *list) {} Bool get(S s) { bool ok = mechCISetContains(list, s); print("MechListContains: " + list + " / " + s + " => " + ok); ret ok; } } sclass #VarDiscriminator { S var; O discriminator; // func(S value) -> bool bool debug; *() {} *(S *var, O *discriminator, bool *debug) {} SS get(SS map, LS tokC, LS tokI, RuleEngine2_MatchedRule matched) { if (map == null) null; S value = map.get(var); if (value != null && !isTrue(callAndMake_orF1(discriminator, value))) { if (debug) print("Rejecting var: " + var + " -> " + value + " because of " + discriminator); null; } ret map; } } svoid gazelle_addVarDiscriminators(RuleEngine2 engine, O... _) { bool debug = boolPar debug(_) || boolPar debugVarDiscriminators(_); for (final RuleEngine2.Rule r : engine.rules) { for (Matches m : getJMatches_all("var * should satisfy *", r.comments)) { S var = $1, discriminator = $2; if (debug) print("Made discriminator for: " + var); r.addMapMassager(new VarDiscriminator(var, discriminator, debug)); } for (Matches m : getJMatches_all("var * should be in list *", r.comments)) { S var = $1, list = $2; r.addMapMassager(new VarDiscriminator(var, MechListContains(list), debug)); } for (Matches m : getJMatches_all("* has to be between * and *", r.comments)) { S var = $1; double min = parseDouble($2), max = parseDouble($3); if (debug) print("Made discriminator for: " + var); r.addMapMassager(new VarDiscriminator(var, func(S value) -> bool { pcall-silent { ret isBetween_double(parseDouble(or(value, var)), min, max); } false; }, debug)); } for (Matches m : getJMatches_all("* has to be * or *", r.comments)) { S var = $1; Set<S> values = litciset($2, $3); if (debug) print("Made discriminator for: " + var); r.addMapMassager(new VarDiscriminator(var, func(S value) -> bool { contains(values, or(value, var)) }, debug)); } } } 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: | 278 / 400 |
Version history: | 15 change(s) |
Referenced in: | #1006654 - Standard functions list 2 (LIVE, continuation of #761) #1021968 - gazelle_addRespondToHumanOnlyHelpers |