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

27
LINES

< > BotCompany Repo | #1003522 // Test parsing list comprehension

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (1182L/8K/27K).

!752

p {
  S s = "L<S> list2 = [S s in list | isIdentifier(s)];";
  L<S> tok = javaTok(s);
  Map<Integer, Integer> bracketMap = getBracketMap(tok);
  int i = jfind(tok, "[<id> <id> in");
  if (i >= 0) {
    S type = tok.get(i+2), id = tok.get(i+4);
    int j = scanOverExpression(tok, bracketMap, i+8, "|");
    S exp = join(tok.subList(i+8, j));
    j += 2;
    int k = scanOverExpression(tok, bracketMap, j, "]");
    S where = join(tok.subList(j, k));
    ++k;
    S rest = join(subList(tok, k));
    
    S temp = "temp";
    /*
    S code = "new L<" + type + "> " + temp + ";\n"
      + "for (" + type + " " + id + " : " + exp + ")\n"
      + "  if (" + where + ") " + temp + ".add(" + id + ");\n";*/
    S code = "filter(" + exp + ", func(" + type + " " + id + ") { " + where + " })";
    
    print(join(tok.subList(0, i)) + code + rest);
  }
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

-
Snippet ID: #1003522
Snippet name: Test parsing list comprehension
Eternal ID of this version: #1003522/1
Text MD5: 4f63a7dd97d4da9b7bb978a74773b051
Transpilation MD5: 0de862956b5cfe7f83dfbedee2296b30
Author: stefan
Category: javax / language
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-07-11 01:27:05
Source code size: 878 bytes / 27 lines
Pitched / IR pitched: No / No
Views / Downloads: 654 / 750
Referenced in: