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

28
LINES

< > BotCompany Repo | #1004491 // parseRules (ooold)

JavaX fragment (include)

1  
sclass Rule {
2  
  new L<S> in;
3  
  new L<S> out;
4  
  
5  
  *() {}
6  
  *(L<S> *in, L<S> *out) {}
7  
}
8  
9  
static L<Rule> parseRules(S text) {
10  
  L<S> log = toLinesTrim2(text);
11  
  L<Int> emptyLines = concatLists(ll(-1), indexesOf(log, ""), ll(l(log)));
12  
  new L<Rule> rules;
13  
  for (int ii = 0; ii+1 < l(emptyLines); ii++) {
14  
    int i = emptyLines.get(ii), j = emptyLines.get(ii+1);
15  
    L<S> l = subList(log, i+1, j);
16  
    continue if empty(l);
17  
    L<Int> arrows = indexesOfLinesStartingWith(l, "->");
18  
    if (empty(arrows)) continue;
19  
    
20  
    // it's a rule
21  
    for (int ia : arrows)
22  
      l.set(ia, dropPrefixTrim("->", l.get(ia)));
23  
    rules.add(new Rule(
24  
      subList(l, 0, first(arrows)),
25  
      subList(l, first(arrows))));
26  
  }
27  
  ret rules;
28  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1004491
Snippet name: parseRules (ooold)
Eternal ID of this version: #1004491/2
Text MD5: a2fcb8c0608243d9ee06eb180231bbc3
Author: stefan
Category: javax / talking robots
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-08-19 00:37:52
Source code size: 751 bytes / 28 lines
Pitched / IR pitched: No / No
Views / Downloads: 548 / 549
Version history: 1 change(s)
Referenced in: [show references]