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