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

23
LINES

< > BotCompany Repo | #1009714 // tok_doAsMethodName - allow "do" as a method name (replace with "dO")

JavaX fragment (include)

1  
sbool tok_doAsMethodName_strict = false;
2  
3  
// Strict mode:
4  
// Sometimes you have to make sure to omit the space after "do"
5  
//   do(...)
6  
// as opposed to
7  
//   do (bla+bla).something(); while ...;  << very unusual anyway
8  
9  
// Non-strict mode:
10  
//   do (bla+bla).something(); while ...;
11  
// is not possible anymore (but who does this?)
12  
// You can use spaces however you like
13  
14  
static void tok_doAsMethodName(L<S> tok) {
15  
  if (!tok.contains("do")) ret;
16  
  for (int i = 1; i+2 < l(tok); i += 2) {
17  
    S next = tok.get(i+2), prev = get(tok, i-2);
18  
    if (tok.get(i).equals("do") && eq(next, "(")
19  
      && (!tok_doAsMethodName_strict
20  
        || eq(prev, ".") || empty(tok.get(i+1))))
21  
      tok.set(i, "dO");
22  
  }
23  
}

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: #1009714
Snippet name: tok_doAsMethodName - allow "do" as a method name (replace with "dO")
Eternal ID of this version: #1009714/2
Text MD5: 4d38037755ba33f329f6dc3a020702ae
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-01-12 10:23:35
Source code size: 724 bytes / 23 lines
Pitched / IR pitched: No / No
Views / Downloads: 575 / 578
Version history: 1 change(s)
Referenced in: [show references]