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).

// result of a (partial) parse. combines a value and a token range in a tokenization
// Good for bottom-up parsing
// See pwt_initial and EnglishDateParser
sclass ParsedWithTokens<A> extends Var<A> {
  LS tok; // full CNC token list being parsed
  int iStart; // points to first parsed C token
  int iRemaining; // points to first unparsed C token
  
  *() {}
  *(A a) { super(a); }
  *(A a, LS *tok, int *iStart, int *iRemaining) { super(a); }
  
  S parsedText() { ret joinSubList(tok, iStart | 1, iRemaining & ~1); }
  ListAndIndex<S> remaining() { ret ListAndIndex(tok, iRemaining); }
  ListAndIndex<S> start() { ret ListAndIndex(tok, iStart); }
  
  int length() { ret iRemaining-iStart; }
  
  <B> ParsedWithTokens<B> withValue(B b) {
    ret new ParsedWithTokens<B>(b, tok, iStart, iRemaining);
  }
  
  toString {
    ret "Parsed " + quote(parsedText()) + " as " + super.toString();
  }
  
  void replaceTokens(S s) {
    main replaceTokens(tok, iStart, iRemaining, s);
  }
}

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: 456 / 836
Version history: 23 change(s)
Referenced in: [show references]