// 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 extends Var {
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 remaining() { ret ListAndIndex(tok, iRemaining); }
ListAndIndex start() { ret ListAndIndex(tok, iStart); }
int length() { ret iRemaining-iStart; }
ParsedWithTokens withValue(B b) {
ret new ParsedWithTokens(b, tok, iStart, iRemaining);
}
toString {
ret "Parsed " + quote(parsedText()) + " as " + super.toString();
}
void replaceTokens(S s) {
main replaceTokens(tok, iStart, iRemaining, s);
}
}