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

35
LINES

< > BotCompany Repo | #1010313 - tok_unpair - "S a, S b = unpair ...;" construct

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Compilation Failed (2360L/16K).

static void tok_unpair(L<S> tok) {
  if (!tok.contains("unpair")) ret;
  
  int i;
  
  jreplace(tok, "<id> <id>, <id> = unpair", "$1 $2, $1 $4 = unpair");
  
  while ((i = jfind(tok, "<id> <id>, <id> <id> = unpair")) >= 0) {
    int idx = indexOf(tok, "unpair", i);
    int j = findEndOfStatement(tok, idx);
    S type1 = tok.get(i), var1 = tok.get(i+2);
    S type2 = tok.get(i+6), var2 = tok.get(i+8);
    S v = makeVar();
    tok.set(i+4, ";");
    tok.set(idx-2, ";");
    tok.set(idx, "Pair<" + tok_toNonPrimitiveTypes(type1) + "," + tok_toNonPrimitiveTypes(type2) + "> " + v + "=");
    tok.set(j-1, "; " + var1 + " = " + v + ".a; " + var2 + " = " + v + ".b;");
    reTok(tok, i, j);
  }
  
  while ((i = jfind(tok, "<id> <id>, <id> < <id>,<id> > <id> = unpair")) >= 0 || (i = jfind(tok, "<id> <id>, <id><<id>> <id> = unpair")) >= 0) {
    print("unpair");
    int idx = indexOf(tok, "unpair", i);
    int j = findEndOfStatement(tok, idx);
    S type1 = tok.get(i), var1 = tok.get(i+2);
    S type2 = joinSubList(tok, i+5, idx-5), var2 = tok.get(idx-4);
    S v = makeVar();
    tok.set(i+4, ";");
    tok.set(idx-2, ";");
    tok.set(idx-1, "");
    tok.set(idx, "Pair<" + type1 + "," + type2 + "> " + v + "=");
    tok.set(j-1, "; " + var1 + " = " + v + ".a; " + var2 + " = " + v + ".b;");
    reTok(tok, i, j);
  }
}

download  show line numbers  debug dex   

Travelled to 9 computer(s): aoiabmzegqzx, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, tslmcundralx, tvejysmllsmz

No comments. add comment

Snippet ID: #1010313
Snippet name: tok_unpair - "S a, S b = unpair ...;" construct
Eternal ID of this version: #1010313/15
Text MD5: b4fe7d4cc79220d108043f4fadb3b745
Transpilation MD5: 318b343228cdcb3c3e09c22442ade841
Author: stefan
Category: javax / parsing
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-06-29 04:57:45
Source code size: 1360 bytes / 35 lines
Pitched / IR pitched: No / No
Views / Downloads: 225 / 242
Version history: 14 change(s)
Referenced in: [show references]

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