Libraryless. Click here for Pure Java version (98L/1K).
1 | static Producer<S> javaTokC_noMLS_iterator(final S s) {
|
2 | ret javaTokC_noMLS_iterator(s, 0); |
3 | } |
4 | |
5 | static Producer<S> javaTokC_noMLS_iterator(final S s, final int startIndex) {
|
6 | ret new Producer<S>() {
|
7 | final int l = s.length(); |
8 | int i = startIndex; |
9 | |
10 | public S next() {
|
11 | if (i >= l) ret null; |
12 | |
13 | int j = i; |
14 | char c, d; |
15 | |
16 | // scan for whitespace |
17 | while (j < l) {
|
18 | c = s.charAt(j); |
19 | d = j+1 >= l ? '\0' : s.charAt(j+1); |
20 | if (c == ' ' || c == '\t' || c == '\r' || c == '\n') |
21 | ++j; |
22 | else if (c == '/' && d == '*') {
|
23 | do ++j; while (j < l && !s.substring(j, Math.min(j+2, l)).equals("*/"));
|
24 | j = Math.min(j+2, l); |
25 | } else if (c == '/' && d == '/') {
|
26 | do ++j; while (j < l && "\r\n".indexOf(s.charAt(j)) < 0); |
27 | } else |
28 | break; |
29 | } |
30 | |
31 | i = j; |
32 | if (i >= l) ret null; |
33 | c = s.charAt(i); |
34 | d = i+1 >= l ? '\0' : s.charAt(i+1); |
35 | |
36 | // scan for non-whitespace |
37 | if (c == '\'' || c == '"') {
|
38 | char opener = c; |
39 | ++j; |
40 | while (j < l) {
|
41 | if (s.charAt(j) == opener || s.charAt(j) == '\n') { // end at \n to not propagate unclosed string literal errors
|
42 | ++j; |
43 | break; |
44 | } else if (s.charAt(j) == '\\' && j+1 < l) |
45 | j += 2; |
46 | else |
47 | ++j; |
48 | } |
49 | } else if (Character.isJavaIdentifierStart(c)) |
50 | do ++j; while (j < l && Character.isJavaIdentifierPart(s.charAt(j))); |
51 | else if (Character.isDigit(c)) {
|
52 | do ++j; while (j < l && Character.isDigit(s.charAt(j))); |
53 | if (j < l && s.charAt(j) == 'L') ++j; // Long constants like 1L |
54 | } else |
55 | ++j; |
56 | |
57 | S t = quickSubstring(s, i, j); |
58 | i = j; |
59 | ret t; |
60 | } |
61 | }; |
62 | } |
Began life as a copy of #1005977
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: | #1008761 |
| Snippet name: | javaTokC_noMLS_iterator - javaTokC as Producer, no multi-line strings |
| Eternal ID of this version: | #1008761/5 |
| Text MD5: | 0d5ba4aa36426a1bedab409118031116 |
| Transpilation MD5: | 9c81f1e2a439e087f7f03b66a0f9ac76 |
| Author: | stefan |
| Category: | javax / parsing |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2019-10-13 20:03:21 |
| Source code size: | 1862 bytes / 62 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 778 / 961 |
| Version history: | 4 change(s) |
| Referenced in: | [show references] |