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

28
LINES

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

JavaX fragment (include)

sclass Rule {
  new L<S> in;
  new L<S> out;
  
  *() {}
  *(L<S> *in, L<S> *out) {}
}

static L<Rule> parseRules(S text) {
  L<S> log = toLinesTrim2(text);
  L<Int> emptyLines = concatLists(ll(-1), indexesOf(log, ""), ll(l(log)));
  new L<Rule> rules;
  for (int ii = 0; ii+1 < l(emptyLines); ii++) {
    int i = emptyLines.get(ii), j = emptyLines.get(ii+1);
    L<S> l = subList(log, i+1, j);
    continue if empty(l);
    L<Int> arrows = indexesOfLinesStartingWith(l, "->");
    if (empty(arrows)) continue;
    
    // it's a rule
    for (int ia : arrows)
      l.set(ia, dropPrefixTrim("->", l.get(ia)));
    rules.add(new Rule(
      subList(l, 0, first(arrows)),
      subList(l, first(arrows))));
  }
  ret rules;
}

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: 481 / 477
Version history: 1 change(s)
Referenced in: [show references]