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

27
LINES

< > BotCompany Repo | #1010235 // structure_addTokenMarkers - add token markers ("m123" matching "t123") to structure for easier readability. Use structure_convertTokenMarkersToExplicit instead, it allows unstructuring

JavaX fragment (include)

static S structure_addTokenMarkers(S s) {
  ret join(structure_addTokenMarkers(javaTokForStructure(s)));
}
  
static L<S> structure_addTokenMarkers(L<S> tok) {
  // find references
  
  new TreeSet<Int> refs;
  for (int i = 1; i < l(tok); i += 2) {
    S t = tok.get(i);
    if (t.startsWith("t") && isInteger(t.substring(1)))
      refs.add(parseInt(t.substring(1)));
  }
  
  if (empty(refs)) ret tok;
  
  // add markers
  for (int i : refs) {
    int idx = i*2+1;
    if (idx >= l(tok)) continue; // broken structure
    S t = "";
    if (endsWithLetterOrDigit(tok.get(idx-1))) t = " ";
    tok.set(idx, t + "m" + i + " " + tok.get(idx));
  }
  
  ret tok;
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1010235
Snippet name: structure_addTokenMarkers - add token markers ("m123" matching "t123") to structure for easier readability. Use structure_convertTokenMarkersToExplicit instead, it allows unstructuring
Eternal ID of this version: #1010235/14
Text MD5: 98028cf6145ba4cce9edc9ec0123aa89
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-03-31 14:33:37
Source code size: 688 bytes / 27 lines
Pitched / IR pitched: No / No
Views / Downloads: 654 / 769
Version history: 13 change(s)
Referenced in: [show references]