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

24
LINES

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

JavaX fragment (include)

sbool tok_doAsMethodName_strict = false;

// Strict mode:
// Sometimes you have to make sure to omit the space after "do"
//   do(...)
// as opposed to
//   do (bla+bla).something(); while ...;  << very unusual anyway

// Non-strict mode:
//   do (bla+bla).something(); while ...;
// is not possible anymore (but who does this?)
// You can use spaces however you like

static void tok_doAsMethodName(L<S> tok) {
  if (!tok.contains("do")) ret;
  for (int i = 1; i+2 < l(tok); i += 2) {
    S next = tok.get(i+2), prev = get(tok, i-2);
    if (tok.get(i).equals("do") && eq(next, "(")
      && (!tok_doAsMethodName_strict
        || eq(prev, ".") || empty(tok.get(i+1))))
      tok.set(i, "dO");
  }
}

download  show line numbers  debug dex   

Travelled to 4 computer(s): cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, tvejysmllsmz

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 / 24 lines
Pitched / IR pitched: No / No
Views / Downloads: 75 / 85
Version history: 1 change(s)
Referenced in: [show]