Libraryless. Click here for Pure Java version (2282L/15K).
1 | static Producer<S> javaTokC_onReader(final Reader r) { |
2 | final class X implements Producer<S> { |
3 | new StringBuilder buf; // stores from "i" |
4 | char c, d, e = 'x'; // just not '\0' |
5 | |
6 | *() { |
7 | // fill c, d and e |
8 | nc(); |
9 | nc(); |
10 | nc(); |
11 | } |
12 | |
13 | // get next character(s) into c, d and e |
14 | void nc() ctex { |
15 | c = d; |
16 | d = e; |
17 | if (e == '\0') ret; |
18 | int i = r.read(); |
19 | e = i < 0 ? '\0' : (char) i; |
20 | } |
21 | |
22 | void ncSave() { |
23 | if (c != '\0') { |
24 | buf.append(c); |
25 | nc(); |
26 | } |
27 | } |
28 | |
29 | public S next() { |
30 | // scan for whitespace |
31 | while (c != '\0') { |
32 | if (c == ' ' || c == '\t' || c == '\r' || c == '\n') |
33 | nc(); |
34 | else if (c == '/' && d == '*') { |
35 | do nc(); while (c != '\0' && !(c == '*' && d == '/')); |
36 | nc(); nc(); |
37 | } else if (c == '/' && d == '/') { |
38 | do nc(); while (c != '\0' && "\r\n".indexOf(c) < 0); |
39 | } else |
40 | break; |
41 | } |
42 | |
43 | if (c == '\0') ret null; |
44 | |
45 | // scan for non-whitespace |
46 | if (c == '\'' || c == '"') { |
47 | char opener = c; |
48 | ncSave(); |
49 | while (c != '\0') { |
50 | if (c == opener || c == '\n') { // end at \n to not propagate unclosed string literal errors |
51 | ncSave(); |
52 | break; |
53 | } else if (c == '\\') { |
54 | ncSave(); |
55 | ncSave(); |
56 | } else |
57 | ncSave(); |
58 | } |
59 | } else if (Character.isJavaIdentifierStart(c)) |
60 | do ncSave(); while (Character.isJavaIdentifierPart(c) || c == '\''); // for stuff like "don't" |
61 | else if (Character.isDigit(c)) { |
62 | do ncSave(); while (Character.isDigit(c)); |
63 | if (c == 'L') ncSave(); // Long constants like 1L |
64 | } else if (c == '[' && d == '[') { |
65 | do ncSave(); while (c != '\0' && !(c == ']' && d == ']')); |
66 | ncSave(); ncSave(); |
67 | } else if (c == '[' && d == '=' && e == '[') { |
68 | do ncSave(); while (c != '\0' && !(c == ']' && d == '=' && e == ']')); |
69 | ncSave(); ncSave(); ncSave(); |
70 | } else |
71 | ncSave(); |
72 | |
73 | S t = buf.toString(); |
74 | buf.setLength(0); |
75 | ret t; |
76 | } |
77 | } |
78 | |
79 | ret new X; |
80 | } |
Began life as a copy of #1005977
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: | #1005981 |
Snippet name: | javaTokC_onReader - javaTokC as Producer on BufferedReader |
Eternal ID of this version: | #1005981/2 |
Text MD5: | 6e5c4fd8f60f1f97060ed886de21c8fd |
Transpilation MD5: | 747cb39971630313eb280a7268bf890e |
Author: | stefan |
Category: | javax / parsing |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-03-15 14:42:34 |
Source code size: | 2257 bytes / 80 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 573 / 648 |
Version history: | 1 change(s) |
Referenced in: | [show references] |