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

21
LINES

< > BotCompany Repo | #1018425 // ai_spreadCertainIndicesC - works on lists of code tokens

JavaX fragment (include)

static LL<S> ai_spreadCertainIndicesC(L<S> tokPat, L<S> tokS, L<Int> indices) {
  int extra = l(tokS)-l(tokPat);
  if (extra < 0 || empty(indices)) ret emptyList();

  new LL<S> results;
  for (L<Int> spread : allSpreads(extra, l(indices))) {
    new L<S> tok;
    int pos = 0, iSpread = 0, iIndices = 0;
    for i over tokPat:
      if (!eq(get(indices, iIndices), i))
        tok.add(tokS.get(pos++));
      else {
        ++iIndices;
        int take = spread.get(iSpread++);
        tok.add(joinWithSpace(subList(tokS, pos, pos+take+1)));
        pos += take+1;
      }
    results.add(tok);
  }
  ret results;
}

Author comment

Began life as a copy of #1017287

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1018425
Snippet name: ai_spreadCertainIndicesC - works on lists of code tokens
Eternal ID of this version: #1018425/1
Text MD5: fa831745f9aa36a0b6d57fb7458870a1
Author: stefan
Category: javax / parsing
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-09-30 02:26:19
Source code size: 636 bytes / 21 lines
Pitched / IR pitched: No / No
Views / Downloads: 378 / 406
Referenced in: [show references]