Libraryless. Click here for Pure Java version (4634L/26K).
1 | ifclass ListAndIndex |
2 | static LineAndColumn tokenToLineAndColumn(ListAndIndex<S> ptr) { |
3 | ret ptr == null ?: tokenToLineAndColumn(ptr.list(), ptr.idx()); |
4 | } |
5 | endif |
6 | |
7 | static LineAndColumn tokenToLineAndColumn(LS tok, int tokenIndex) { |
8 | int line = 1, col = 1; |
9 | tokenIndex = min(tokenIndex, l(tok)); |
10 | for i to tokenIndex: { |
11 | S t = tok.get(i); |
12 | int n = l(t); |
13 | for j to n: |
14 | if (t.charAt(j) == '\n') { |
15 | ++line; |
16 | col = 1; |
17 | } else |
18 | ++col; |
19 | } |
20 | ret LineAndColumn(line, col); |
21 | } |
Began life as a copy of #1008636
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, ekrmjmnbrukm, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1033994 |
Snippet name: | tokenToLineAndColumn |
Eternal ID of this version: | #1033994/4 |
Text MD5: | f1bb477b3916e07c0d65a23dc5f05beb |
Transpilation MD5: | fc06193bcdd40b4a24c397f6369f6694 |
Author: | stefan |
Category: | javax / parsing |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-01-15 20:20:41 |
Source code size: | 526 bytes / 21 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 166 / 230 |
Version history: | 3 change(s) |
Referenced in: | [show references] |