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(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   

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/13
Text MD5: 98028cf6145ba4cce9edc9ec0123aa89
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-10-13 19:59:47
Source code size: 688 bytes / 27 lines
Pitched / IR pitched: No / No
Views / Downloads: 287 / 386
Version history: 12 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1010235 & http://1010235.tinybrain.de