Libraryless. Click here for Pure Java version (8640L/49K).
| 1 | // "replace var x with" is like "replace x with" except it doesn't | 
| 2 | // replace .x (this.x etc) | 
| 3 | svoid tok_replaceVarWith(L<S> tok) {
 | 
| 4 | int i; | 
| 5 |   while ping ((i = jfind(tok, "replace var <id> with")) >= 0) {
 | 
| 6 | S token = tok.get(i+4); | 
| 7 | int repStart = i+8; | 
| 8 | int repEnd = repStart; | 
| 9 | |
| 10 | // Find . with space or line break or EOF afterwards | 
| 11 | while ping (repEnd < l(tok) && !( | 
| 12 | eqGet(tok, repEnd, ".") && // end when there is a dot | 
| 13 | (nempty(get(tok, repEnd+1)) || repEnd == l(tok)-2))) // ...and it's the end of the text OR there is a space or newline after the dot | 
| 14 | repEnd += 2; | 
| 15 |     print("tok_replaceWith: Found " + joinSubList(tok, repStart, repEnd));
 | 
| 16 | //int repEnd = smartIndexOf(tok, repStart, "."); | 
| 17 | |
| 18 | S replacement = joinSubList(tok, repStart, repEnd-1); | 
| 19 | clearTokens(tok, i, repEnd+1); | 
| 20 |     print("Replacing " + token + " with " + replacement + ".");
 | 
| 21 | int end = findEndOfBlock(tok, repEnd)-1; | 
| 22 | for ping (int j = repEnd+2; j < end; j += 2) | 
| 23 | if (eq(tok.get(j), token) && !eqGet(tok, j-2, ".")) tok.set(j, replacement); | 
| 24 | reTok(tok, i, end); | 
| 25 | } | 
| 26 | } | 
Began life as a copy of #1013759
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
| Snippet ID: | #1035205 | 
| Snippet name: | tok_replaceVarWith - process "replace var * with *." statements; applies to current block only | 
| Eternal ID of this version: | #1035205/2 | 
| Text MD5: | 7f30eba47b237be6f1f3be538b835a96 | 
| Transpilation MD5: | 510e602af27d1d976ab4db84ae1371c4 | 
| Author: | stefan | 
| Category: | javax / parsing | 
| Type: | JavaX fragment (include) | 
| Public (visible to everyone): | Yes | 
| Archived (hidden from active list): | No | 
| Created/modified: | 2022-04-15 03:07:01 | 
| Source code size: | 1120 bytes / 26 lines | 
| Pitched / IR pitched: | No / No | 
| Views / Downloads: | 376 / 462 | 
| Version history: | 1 change(s) | 
| Referenced in: | [show references] |