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

30
LINES

< > BotCompany Repo | #1028568 // ParsedWithTokens - a value object plus parsed + remaining tokens

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

Libraryless. Click here for Pure Java version (4714L/27K).

1  
// result of a (partial) parse. combines a value and a token range in a tokenization
2  
// Good for bottom-up parsing
3  
// See pwt_initial and EnglishDateParser
4  
sclass ParsedWithTokens<A> extends Var<A> {
5  
  LS tok; // full CNC token list being parsed
6  
  int iStart; // points to first parsed C token
7  
  int iRemaining; // points to first unparsed C token
8  
  
9  
  *() {}
10  
  *(A a) { super(a); }
11  
  *(A a, LS *tok, int *iStart, int *iRemaining) { super(a); }
12  
  
13  
  S parsedText() { ret joinSubList(tok, iStart | 1, iRemaining & ~1); }
14  
  ListAndIndex<S> remaining() { ret ListAndIndex(tok, iRemaining); }
15  
  ListAndIndex<S> start() { ret ListAndIndex(tok, iStart); }
16  
  
17  
  int length() { ret iRemaining-iStart; }
18  
  
19  
  <B> ParsedWithTokens<B> withValue(B b) {
20  
    ret new ParsedWithTokens<B>(b, tok, iStart, iRemaining);
21  
  }
22  
  
23  
  toString {
24  
    ret "Parsed " + quote(parsedText()) + " as " + super.toString();
25  
  }
26  
  
27  
  void replaceTokens(S s) {
28  
    main replaceTokens(tok, iStart, iRemaining, s);
29  
  }
30  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1028568
Snippet name: ParsedWithTokens - a value object plus parsed + remaining tokens
Eternal ID of this version: #1028568/24
Text MD5: 7324f22359d66946cc008ef5e383771c
Transpilation MD5: 89911a75fe7a2a6164774e51b3ccb05e
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-01-15 00:24:02
Source code size: 1012 bytes / 30 lines
Pitched / IR pitched: No / No
Views / Downloads: 457 / 838
Version history: 23 change(s)
Referenced in: [show references]