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

JavaX fragment (include)

static S structure_addTokenMarkers(S s) {
  ret join(structure_addTokenMarkers(javaTok(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   

Travelled to 12 computer(s): aoiabmzegqzx, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, ppjhyzlbdabe, tslmcundralx, tvejysmllsmz

No comments. add comment

Snippet ID: #1010235
Snippet name: structure_addTokenMarkers - add token markers ("m123" matching "t123") to structure for easier readability
Eternal ID of this version: #1010235/12
Text MD5: 0e859d3cad9f0e9f625a0b2181f7c7c0
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-08-13 13:41:13
Source code size: 676 bytes / 27 lines
Pitched / IR pitched: No / No
Views / Downloads: 255 / 352
Version history: 11 change(s)
Referenced in: [show references]