Transpiled version (3604L) is out of date.
1 | please include function testBracketHygiene. |
2 | |
3 | static Pair<Int, S> testBracketHygiene2(S s) { |
4 | ret testBracketHygiene2(s, testBracketHygiene_op, testBracketHygiene_close); |
5 | } |
6 | |
7 | static Pair<Int, S> testBracketHygiene2(S s, S op, S close) { |
8 | LS tok = javaTok(s); |
9 | new Map<Int> map; |
10 | L<int> stack = getBracketMap2(tok, map, op, close); |
11 | |
12 | for (int i = 1; i < l(tok); i += 2) |
13 | if (isUnproperlyQuoted(tok.get(i))) { |
14 | int lineNr = tokenIndexToUserLandLineNr(tok, i); |
15 | ret pair(tokenToCharIndex(tok, i), "Unclosed string literal at line " + lineNr); |
16 | } |
17 | |
18 | for (int i : keys(map)) { |
19 | int j = map.get(i); |
20 | S a = tok.get(i), b = tok.get(j); |
21 | int ai = op.indexOf(a), bi = close.indexOf(b); |
22 | if (ai != bi) { |
23 | int lineNr1 = tokenIndexToUserLandLineNr(tok, i); |
24 | int lineNr2 = tokenIndexToUserLandLineNr(tok, j); |
25 | S msg; |
26 | if (empty(a)) |
27 | msg = "superfluous closing bracket (" + quote(b) + ") at line " + lineNr2; |
28 | else |
29 | msg = "brackets don't match (" + quote(a) + " vs " + quote(b) + ") at lines " + lineNr1 + " and " + lineNr2; |
30 | ret pair(tokenToCharIndex(tok, /*tossCoin() ?*/ i /*: j*/), |
31 | "Bad hygiene - " + msg); |
32 | } |
33 | } |
34 | |
35 | if (nempty(stack)) { |
36 | int lineNr = tokenIndexToUserLandLineNr(tok, last(stack)); |
37 | ret pair(tokenIndexToCharIndex(tok, last(stack)), "Line " + lineNr + ": " |
38 | + "Bad hygiene - " + n(l(stack), "bracket") + " not closed"); |
39 | } |
40 | |
41 | if (map.containsKey(0)) { |
42 | int lineNr = tokenIndexToUserLandLineNr(tok, map.get(0)); |
43 | ret pair(tokenToCharIndex(tok, map.get(0)), |
44 | "Bad hygiene - bracket not opened (" + quote(tok.get(map.get(0))) + ") at line " + lineNr); |
45 | } |
46 | |
47 | null; |
48 | } |
Began life as a copy of #1003922
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1009426 |
Snippet name: | testBracketHygiene2 - shows where the bad bracket is |
Eternal ID of this version: | #1009426/19 |
Text MD5: | e366eba96ef58efaa1e01f2add558498 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-08-31 18:12:24 |
Source code size: | 1734 bytes / 48 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 400 / 541 |
Version history: | 18 change(s) |
Referenced in: | [show references] |