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).

1  
!752
2  
3  
p {
4  
  S s = "L<S> list2 = [S s in list | isIdentifier(s)];";
5  
  L<S> tok = javaTok(s);
6  
  Map<Integer, Integer> bracketMap = getBracketMap(tok);
7  
  int i = jfind(tok, "[<id> <id> in");
8  
  if (i >= 0) {
9  
    S type = tok.get(i+2), id = tok.get(i+4);
10  
    int j = scanOverExpression(tok, bracketMap, i+8, "|");
11  
    S exp = join(tok.subList(i+8, j));
12  
    j += 2;
13  
    int k = scanOverExpression(tok, bracketMap, j, "]");
14  
    S where = join(tok.subList(j, k));
15  
    ++k;
16  
    S rest = join(subList(tok, k));
17  
    
18  
    S temp = "temp";
19  
    /*
20  
    S code = "new L<" + type + "> " + temp + ";\n"
21  
      + "for (" + type + " " + id + " : " + exp + ")\n"
22  
      + "  if (" + where + ") " + temp + ".add(" + id + ");\n";*/
23  
    S code = "filter(" + exp + ", func(" + type + " " + id + ") { " + where + " })";
24  
    
25  
    print(join(tok.subList(0, i)) + code + rest);
26  
  }
27  
}

download  show line numbers  debug dex   

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

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: 284 / 296
Referenced in: [show references]

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