Libraryless. Click here for Pure Java version (3890L/22K).
1 | scope tok_findRewrites |
2 | |
3 | // finds: rewrite <id> [=|with|to] <definition> |
4 | // (a global version of "replace <id> with") |
5 | |
6 | sclass #Found { |
7 | LS tok; |
8 | S token; |
9 | int cIdx, repStart, repEnd; |
10 | |
11 | S replacement() { ret joinSubList(tok, repStart, repEnd-1); } |
12 | |
13 | int startCIdx() { ret cIdx; } |
14 | int endNIdx() { ret repEnd+1; } |
15 | } |
16 | |
17 | |
18 | static SS tok_findRewrites(LS tok) { |
19 | SS rewrites = orderedMap(); |
20 | tok_findRewrites(tok, rewrites, null); |
21 | ret rewrites; |
22 | } |
23 | |
24 | svoid tok_findRewrites(LS tok, SS rewrites default null, IVF1<Found> callback) { |
25 | for (int i : jfindAll(tok, "rewrite <id>", (_tok, nIdx) -> |
26 | eqGetOneOf(_tok, nIdx+5, "with", "=", "to"))) { |
27 | new Found f; |
28 | f.tok = tok; |
29 | f.cIdx = i; |
30 | f.token = tok.get(i+2); |
31 | f.repStart = i+6; |
32 | f.repEnd = smartIndexOf(tok, f.repStart, "."); // TODO: allow expressions with brackets |
33 | callF(callback, f); |
34 | rewrites?.put(f.token, f.replacement()); |
35 | } |
36 | } |
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
Snippet ID: | #1031503 |
Snippet name: | tok_findRewrites |
Eternal ID of this version: | #1031503/7 |
Text MD5: | 9dfd90067083bd19b422b12b41b18feb |
Transpilation MD5: | ed3104bcd880319c0bb926aae375c7e0 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-09-05 06:31:24 |
Source code size: | 948 bytes / 36 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 170 / 263 |
Version history: | 6 change(s) |
Referenced in: | [show references] |