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

33
LINES

< > BotCompany Repo | #1002292 // mergeBracketThingies

JavaX fragment (include)

1  
// properly post-parse angle bracket things like "<quoted>"
2  
// now also allows a space, like "<exp e1>" or "<exp 1>"
3  
static L<S> mergeBracketThingies(L<S> tok) {
4  
  tok = cloneList(tok);
5  
  for (int i = 1; i+4 < l(tok); i += 2) {
6  
    // short case
7  
    if (eq(get(tok, i), "<") && eq(get(tok, i+1), "") && isIdentifier(get(tok, i+2)) && eq(get(tok, i+3), "") && eq(get(tok, i+4), ">")) {
8  
      tok.set(i, "<" + tok.get(i+2) + ">");
9  
      tok.remove(i+4);
10  
      tok.remove(i+3);
11  
      tok.remove(i+2);
12  
      tok.remove(i+1);
13  
    }
14  
    
15  
    // longer case
16  
    if (eq(get(tok, i), "<")
17  
      && eq(get(tok, i+1), "")
18  
      && isIdentifier(get(tok, i+2))
19  
      && (isIdentifier(get(tok, i+4)) || isInteger(get(tok, i+4)))
20  
      && eq(get(tok, i+5), "")
21  
      && eq(get(tok, i+6), ">")) {
22  
      tok.set(i, "<" + tok.get(i+2) + " " + tok.get(i+4) + ">");
23  
      tok.remove(i+6);
24  
      tok.remove(i+5);
25  
      tok.remove(i+4);
26  
      tok.remove(i+3);
27  
      tok.remove(i+2);
28  
      tok.remove(i+1);
29  
    }
30  
  }
31  
  
32  
  ret tok;
33  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1002292
Snippet name: mergeBracketThingies
Eternal ID of this version: #1002292/1
Text MD5: e2d1e1bfa388180b16ce51786f905efd
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-01-28 21:50:09
Source code size: 1041 bytes / 33 lines
Pitched / IR pitched: No / No
Views / Downloads: 776 / 1154
Referenced in: [show references]