Construct this with a buffer, initial offset into the buffer and an end offset.
Input datasource.
OptionalinitialOffset: numberThe initial offset in the buffer to start parsing from (will default to 0)
OptionalendOffset: numberThe (exclusive) offset to stop parsing/treat as the end of the buffer (will default to the buffer's length)
Get the current cursor address of the stream, relative the initial offset.
The cursor relative the initial offset, instead of absolute the start of the buffer.
Get the current position in the buffer this parser is at.
The cursor position in bytes.
Has this parsing buffer hit or parsed its end mark?
True if the parsing buffer has passed its end mark.
Get the current linecount for this parser.
The line count.
Has this parsing buffer hit or parsed its end mark?
True if the parsing buffer is not passed its end mark.
Match against any one of the chars in a token and return the index in the token.
The encoded token to match against
True if the match was successful.
Try and match a single matching function, with rewind semantics. (i.e. return to the initial cursor on failure).
The matching function to run.
True if a match is found. False otherwise.
Streaming support: repoint this buffer at a fresh window over the same
logical stream while keeping address file-absolute.
A moving-window parse holds only a slice of the source in memory at a
time. Between top-level records (where the rewind stack is empty) the
driver slides the window forward: it copies the unconsumed tail to the
front of a reused buffer, appends freshly-read bytes, and calls this to
repoint the parser. addressBase is the file offset that window index 0
now corresponds to; we store it as a negative initial offset so
address ( = cursor − initialOffset ) stays the file-absolute value the
non-streaming parse would have produced.
Must only be called with the rewind stack empty (i.e. at a record boundary) — the stack holds window-relative cursors that a slide would invalidate. Throws otherwise.
The new window buffer.
The cursor position within the new window.
The count of valid bytes in the new window.
The file offset that window index 0 maps to.
Reinitialize this with a new buffer, initial offset and end offset.
The buffer to initialize this with.
The initial offset in bytes to start the cursor at in the buffer.
The end offset of the buffer in bytes, relative to the start of the buffer.
Try and run a sequence of parsing operations, with rewind semantics (i.e. return to the initial cursor on failure).
Rest...against: (() => boolean)[]The sequence to run.
True if all operations in the sequence return true in order. False otherwise.
Try and run a sequence of parsing operations, with rewind semantics (i.e. return to the initial cursor on failure).
Also eats whitespace before each match.
Rest...against: (() => boolean)[]The sequence to run.
True if all operations in the sequence return true in order. False otherwise.
Match an encoded token at the current cursor, and rewind if it's not matched.
The encoded token.
True if the token is matched.
Move the cursor forwards while a particular char isn't found.
A parsing buffer class, note for convenience and brevity, a lot of the functions here are pre-bound using public fields, this means they can be used like C# style delegates, which is handy for constructive parsing, as well as providing easy access to nested parsing/parsing combinator style constructs.