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

49
LINES

< > BotCompany Repo | #1013522 // quotelessJavaTok function - Java tokenizer without quoted things. TODO: is it up to date with javaTok?

JavaX fragment (include)

1  
static List<String> quotelessJavaTok(String s) {
2  
  ArrayList<String> tok = new ArrayList();
3  
  int l = l(s);
4  
  
5  
  int i = 0, n = 0;
6  
  while (i < l) {
7  
    int j = i;
8  
    char c, d;
9  
    
10  
    // scan for whitespace
11  
    while (j < l) {
12  
      c = s.charAt(j);
13  
      d = j+1 >= l ? '\0' : s.charAt(j+1);
14  
      if (c == ' ' || c == '\t' || c == '\r' || c == '\n')
15  
        ++j;
16  
      else if (c == '/' && d == '*') {
17  
        do ++j; while (j < l && !s.substring(j, Math.min(j+2, l)).equals("*/"));
18  
        j = Math.min(j+2, l);
19  
      } else if (c == '/' && d == '/') {
20  
        do ++j; while (j < l && "\r\n".indexOf(s.charAt(j)) < 0);
21  
      } else
22  
        break;
23  
    }
24  
    
25  
    tok.add(javaTok_substringN(s, i, j));
26  
    ++n;
27  
    i = j;
28  
    if (i >= l) break;
29  
    c = s.charAt(i);
30  
    d = i+1 >= l ? '\0' : s.charAt(i+1);
31  
32  
    // scan for non-whitespace
33  
    
34  
    if (Character.isJavaIdentifierStart(c))
35  
      do ++j; while (j < l && (Character.isJavaIdentifierPart(s.charAt(j)) || "'".indexOf(s.charAt(j)) >= 0)); // for stuff like "don't"
36  
    else if (Character.isDigit(c)) {
37  
      do ++j; while (j < l && Character.isDigit(s.charAt(j)));
38  
      if (j < l && s.charAt(j) == 'L') ++j; // Long constants like 1L
39  
    } else
40  
      ++j;
41  
      
42  
    tok.add(javaTok_substringC(s, i, j));
43  
    ++n;
44  
    i = j;
45  
  }
46  
  
47  
  if ((tok.size() % 2) == 0) tok.add("");
48  
  return tok;
49  
}

Author comment

Began life as a copy of #1000688

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1013522
Snippet name: quotelessJavaTok function - Java tokenizer without quoted things. TODO: is it up to date with javaTok?
Eternal ID of this version: #1013522/5
Text MD5: 4d98b04f69c7a2d8ff5d2fd1698f35cf
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-07-05 21:29:34
Source code size: 1403 bytes / 49 lines
Pitched / IR pitched: No / No
Views / Downloads: 404 / 467
Version history: 4 change(s)
Referenced in: [show references]