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

23
LINES

< > BotCompany Repo | #1003484 // makeGrabber

JavaX fragment (include)

1  
// preprocessor: func(S -> O)
2  
// returns func(S -> E)
3  
static O makeGrabber(OccTree2 tree, final O preprocessor) {
4  
  final new StrictTreeMap<O, S> strictMap; // TODO: maybe use hashmap
5  
  strictMap.detailedExceptions = true;
6  
  for (OccTree2 node : tree.allNodes()) {
7  
    if (node.e.a() && node.parent != null && node.parent.e.q()) {
8  
      S in = node.parent.e.text(), out = node.e.text();
9  
      O preprocessed;
10  
      try {
11  
        preprocessed = callFunction(preprocessor, in); // may throw exception, then we just skip
12  
      } catch { continue; }
13  
      
14  
      if (preprocessed != null)
15  
        strictMap.put(preprocessed, out);
16  
    }
17  
  }
18  
  ret func(S in) {
19  
    O preprocessed = callF(preprocessor, in);
20  
    if (preprocessed == null) null;
21  
    ret E.a(strictMap.get(preprocessed));
22  
  };
23  
}

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: 654 / 622
Referenced in: [show references]