The input to parse, wrapped in a DataView.
Protected ReadonlysourceThe raw input buffer. Accessible to subclasses so they can decode slices.
ProtectedadvanceMoves the current position forward by one byte. Has no effect when already at end of input.
ProtectedatReturns true when the parser has reached the end of input.
Implemented by subclasses based on their input representation.
ProtectedcaptureReturns a zero-copy DataView slice of the source buffer.
Start byte offset (inclusive), relative to the start of source.
End byte offset (exclusive), relative to the start of source.
ProtectedconsumeProtecteddescribeReturns a human-readable description of the input element at pos for
use in error messages. In scannerless parsers this describes a byte; in
token parsers it describes a token.
The position index to describe.
ProtectederrorProtectederrorThrows a RDParserException naming the unexpected input element at the furthest position reached during parsing.
Call this from the top-level parse() method when the first rule returns
null, to give callers a precise error location rather than a generic
"Failed to parse input (at position 0)" message.
ProtectedexpectProtectedgetReturns the furthest position at which a terminal match was attempted and failed. Useful for producing informative error messages when the overall parse fails.
ProtectedgetReturns the current position within the input.
ProtectedmatchIf the current byte equals expectedByte, consumes it and returns true.
Otherwise leaves the position unchanged and returns false.
The byte value to match.
ProtectednotifyCall at the entry of each production method to notify the observer.
Name of the production rule being entered.
ProtectednotifyCall before each return in a production method to notify the observer.
Name of the production rule being exited.
Whether the production successfully matched input.
ProtectedpeekReturns the byte at the current position without consuming it,
or null if the parser has reached the end of input.
ProtectedreadIf the current byte equals expectedByte, consumes it and returns it as a one-character string.
Otherwise leaves the position unchanged and returns null.
This is the value-returning counterpart of matchChar, used by generated parsers to capture terminal characters directly into the parse tree.
The byte value to match.
ProtectedreadIf the current byte falls within [lowerBound, upperBound] (inclusive), consumes it and returns it
as a one-character string. Otherwise leaves the position unchanged and returns null.
Used by generated parsers to capture character-range terminals into the parse tree.
Lower bound (inclusive) of the byte range.
Upper bound (inclusive) of the byte range.
ProtectedrestoreRestores the current position to a previously saved value.
Used with getPosition to implement backtracking in parser alternatives.
The position to restore to.
ProtectedupdateRecords the current position as a fail point if it is further than any previously recorded fail. Subclasses call this when a terminal match fails.
Attaches an observer that will receive parse events during parsing.
Returns this for chaining: new MyParser(source).withObserver(obs).parse().
The observer to attach.
A scannerless ScannerlessRDParser subclass with opt-in observer support for tracing and debugging.
Extend
ObservableRDParserinstead ofScannerlessRDParserwhen parse tracing is needed. CallwithObserver()to attach a ParseObserver before parsing. Parsers that extendScannerlessRDParserdirectly carry zero observer overhead.Use withObservable to add observer support to TokenRDParser or other custom RDParser subclasses.
Generated parsers use this base class when
rdp-genis run with--observable.