Libraryless. Click here for Pure Java version (3890L/22K).
scope tok_findRewrites // finds: rewrite <id> [=|with|to] <definition> // (a global version of "replace <id> with") sclass #Found { LS tok; S token; int cIdx, repStart, repEnd; S replacement() { ret joinSubList(tok, repStart, repEnd-1); } int startCIdx() { ret cIdx; } int endNIdx() { ret repEnd+1; } } static SS tok_findRewrites(LS tok) { SS rewrites = orderedMap(); tok_findRewrites(tok, rewrites, null); ret rewrites; } svoid tok_findRewrites(LS tok, SS rewrites default null, IVF1<Found> callback) { for (int i : jfindAll(tok, "rewrite <id>", (_tok, nIdx) -> eqGetOneOf(_tok, nIdx+5, "with", "=", "to"))) { new Found f; f.tok = tok; f.cIdx = i; f.token = tok.get(i+2); f.repStart = i+6; f.repEnd = smartIndexOf(tok, f.repStart, "."); // TODO: allow expressions with brackets callF(callback, f); rewrites?.put(f.token, f.replacement()); } }
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: | 393 / 538 |
| Version history: | 6 change(s) |
| Referenced in: | #1006654 - Standard functions list 2 (LIVE, continuation of #761) |