Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

37
LINES

< > BotCompany Repo | #1034243 // TokenRangeWithSrc

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (23717L/144K).

1  
sclass TokenRangeWithSrc extends TokenRange {
2  
  LS tok;
3  
  settable O sourceInfo; // e.g. script ID
4  
  
5  
  *() {}
6  
  *(LS tok, int *start) { end = start; }
7  
  *(LS tok, int *start, int *end) {}
8  
  *(TokPtr startPtr, TokPtr endPtr) {
9  
    assertNotNull(+startPtr);
10  
    assertNotNull(+endPtr);
11  
    assertSame(tok = startPtr.list(), endPtr.list());
12  
    start = startPtr.idx();
13  
    end = endPtr.idx();
14  
  }
15  
  
16  
  TokPtr startPtr() { ret ListAndIndex(tok, start); }
17  
  TokPtr endPtr() { ret ListAndIndex(tok, end); }
18  
  
19  
  LineAndColumn startLineAndCol() { ret tokenToLineAndColumn(startPtr()); }
20  
  LineAndColumn endLineAndCol() { ret tokenToLineAndColumn(endPtr()); }
21  
  
22  
  S text() {
23  
    ret joinSubList(tok, start, end);
24  
  }
25  
  
26  
  S renderRange() {
27  
    ret renderLineAndColumnRange(startLineAndCol(), endLineAndCol());
28  
  }
29  
  
30  
  toString {
31  
    ret spaceCombine(sourceInfo(), renderRange());
32  
  }
33  
  
34  
  S fullSourceText() {
35  
    ret join(tok);
36  
  }
37  
}

Author comment

Began life as a copy of #1027942

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1034243
Snippet name: TokenRangeWithSrc
Eternal ID of this version: #1034243/12
Text MD5: 53d17691137e2c4b075c46990826c0d5
Transpilation MD5: c71564ec460afa8dbbb0edc83f5a4705
Author: stefan
Category: javax / parsing
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-12-11 19:44:15
Source code size: 965 bytes / 37 lines
Pitched / IR pitched: No / No
Views / Downloads: 255 / 440
Version history: 11 change(s)
Referenced in: [show references]