Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

47
LINES

< > BotCompany Repo | #1021688 // gazelle_addHelperTablesToRules

JavaX fragment (include)

scope gazelle_addHelperTablesToRules.

sclass #Massager {
  LL<S> helperTable;
  Map<S, Pair<Int>> helperIndex;
 
  *() {}
  *(LL<S> *helperTable, Map<S, Pair<Int>> *helperIndex) {}
  
  SS get(SS map, LS tokC, LS tokI, RuleEngine2_MatchedRule matched) {
    if (map == null) null;
    //print("Massaging: " + map + " " + sfu(tokC) + " / " + sfu(tokI));
    for (S t : codeTokens(matched.tokenize(matched.rule.out))) {
      //print("Checking: " + t);
      if (map.containsKey(t)) continue;
      Pair<Int> idx = helperIndex.get(t);
      if (idx == null) continue;
      //print("Found: " + t);
      for (S key, val : cloneMap(map)) {
        int idx2 = indexOfIC(helperTable.get(idx.a), key);
        if (idx2 < 0) continue;
        Pair<Int> idxVal = helperIndex.get(val);
        if (idxVal == null) continue;
        S out = _get(_get(helperTable, idxVal.a), idx.b);
        print("Massaged: " + t + " <-> " + key + " => " + out);
        mapPut(map, t, out);
      }
    }
    ret map;
  }
}

svoid gazelle_addHelperTablesToRules(RuleEngine2 engine) {
  new Matches m;
  for (final RuleEngine2.Rule r : engine.rules) {
    continue unless matchAny("use helper table mech list *", r.comments, m);
    LS entries = mL($1);
    continue if empty(entries);
    
    final LL<S> helperTable = map tok_splitAtCommaOrDoubleArrow(entries);
    final Map<S, Pair<Int>> helperIndex = indexTwoDArrayIC(helperTable);
  
    r.addMapMassager(new Massager(helperTable, helperIndex));
  }
}

end scope

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1021688
Snippet name: gazelle_addHelperTablesToRules
Eternal ID of this version: #1021688/12
Text MD5: b4cfb9cc9c91451aeed9f60592ca5030
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-02 18:48:00
Source code size: 1540 bytes / 47 lines
Pitched / IR pitched: No / No
Views / Downloads: 225 / 265
Version history: 11 change(s)
Referenced in: [show references]