1 | static L<S> javaTokC(S s) { |
2 | if (s == null) null; |
3 | int l = s.length(); |
4 | new ArrayList<S> tok; |
5 | |
6 | int i = 0; |
7 | while (i < l) { |
8 | int j = i; |
9 | char c, d; |
10 | |
11 | // scan for whitespace |
12 | while (j < l) { |
13 | c = s.charAt(j); |
14 | d = j+1 >= l ? '\0' : s.charAt(j+1); |
15 | if (c == ' ' || c == '\t' || c == '\r' || c == '\n') |
16 | ++j; |
17 | else if (c == '/' && d == '*') { |
18 | do ++j; while (j < l && !s.substring(j, Math.min(j+2, l)).equals("*/")); |
19 | j = Math.min(j+2, l); |
20 | } else if (c == '/' && d == '/') { |
21 | do ++j; while (j < l && "\r\n".indexOf(s.charAt(j)) < 0); |
22 | } else |
23 | break; |
24 | } |
25 | |
26 | i = j; |
27 | if (i >= l) break; |
28 | c = s.charAt(i); |
29 | d = i+1 >= l ? '\0' : s.charAt(i+1); |
30 | |
31 | // scan for non-whitespace |
32 | if (c == '\'' || c == '"') { |
33 | char opener = c; |
34 | ++j; |
35 | while (j < l) { |
36 | if (s.charAt(j) == opener || s.charAt(j) == '\n') { // end at \n to not propagate unclosed string literal errors |
37 | ++j; |
38 | break; |
39 | } else if (s.charAt(j) == '\\' && j+1 < l) |
40 | j += 2; |
41 | else |
42 | ++j; |
43 | } |
44 | } else if (Character.isJavaIdentifierStart(c)) |
45 | do ++j; while (j < l && (Character.isJavaIdentifierPart(s.charAt(j)) || "'".indexOf(s.charAt(j)) >= 0)); // for stuff like "don't" |
46 | else if (Character.isDigit(c)) { |
47 | do ++j; while (j < l && Character.isDigit(s.charAt(j))); |
48 | if (j < l && s.charAt(j) == 'L') ++j; // Long constants like 1L |
49 | } else if (c == '[' && d == '[') { |
50 | do ++j; while (j+1 < l && !s.substring(j, j+2).equals("]]")); |
51 | j = Math.min(j+2, l); |
52 | } else if (c == '[' && d == '=' && i+2 < l && s.charAt(i+2) == '[') { |
53 | do ++j; while (j+2 < l && !s.substring(j, j+3).equals("]=]")); |
54 | j = Math.min(j+3, l); |
55 | } else |
56 | ++j; |
57 | |
58 | tok.add(javaTok_substringC(s, i, j)); |
59 | i = j; |
60 | } |
61 | |
62 | return tok; |
63 | } |
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, whxojlpjdney
No comments. add comment
Snippet ID: | #1004582 |
Snippet name: | javaTokC - codeTokensOnly+javaTok |
Eternal ID of this version: | #1004582/5 |
Text MD5: | 45076a1d00d1ecc2a47a2ecd0aa21dc2 |
Author: | stefan |
Category: | javax / parsing |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-11-05 04:45:17 |
Source code size: | 1952 bytes / 63 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 702 / 944 |
Version history: | 4 change(s) |
Referenced in: | [show references] |