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

23
LINES

< > BotCompany Repo | #1003484 // makeGrabber

JavaX fragment (include)

// preprocessor: func(S -> O)
// returns func(S -> E)
static O makeGrabber(OccTree2 tree, final O preprocessor) {
  final new StrictTreeMap<O, S> strictMap; // TODO: maybe use hashmap
  strictMap.detailedExceptions = true;
  for (OccTree2 node : tree.allNodes()) {
    if (node.e.a() && node.parent != null && node.parent.e.q()) {
      S in = node.parent.e.text(), out = node.e.text();
      O preprocessed;
      try {
        preprocessed = callFunction(preprocessor, in); // may throw exception, then we just skip
      } catch { continue; }
      
      if (preprocessed != null)
        strictMap.put(preprocessed, out);
    }
  }
  ret func(S in) {
    O preprocessed = callF(preprocessor, in);
    if (preprocessed == null) null;
    ret E.a(strictMap.get(preprocessed));
  };
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1003484
Snippet name: makeGrabber
Eternal ID of this version: #1003484/1
Text MD5: fff2b23d906cfc1e676e506103dabca6
Author: stefan
Category: javax / talking robots
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-07-05 21:05:10
Source code size: 808 bytes / 23 lines
Pitched / IR pitched: No / No
Views / Downloads: 653 / 621
Referenced in: [show references]