![]() |
Spicy
|
#include <driver.h>
Public Types | |
enum | State { Done, Continue } |
Public Member Functions | |
ParsingState (ParsingType type, const Parser *parser=nullptr, std::optional< UnitContext > context={}) | |
bool | hasParser () const |
void | setParser (const Parser *parser, std::optional< UnitContext > context={}) |
bool | isFinished () const |
void | skipRemaining () |
bool | isSkipping () const |
State | process (size_t size, const char *data) |
std::optional< hilti::rt::stream::Offset > | finish () |
void | reset () |
Protected Member Functions | |
virtual void | debug (const std::string &msg)=0 |
void | debug (const std::string &msg, size_t size, const char *data) |
Abstract base class maintaining the parsing state during incremental input processing.
Helper type for capturing return value of process()
.
Enumerator | |
---|---|
Done | parsing has fully finished |
Continue | parsing remains ongoing and ready to accept for data |
|
inline |
Constructor.
type | of parsing; this determines how subsequent chunks of input data are handled (stream-wise vs independent blocks) |
parser | parser to use; can be left unset to either not perform any parsing at all, or set it later through setParser() ; only parsers that do not take any unit parameters are supported, otherwise a InvalidUnitType exception will be thrown at runtime. |
context | context to make available to unit instance during parsing |
|
protectedpure virtual |
Virtual method to override by derived classed for recording debug output. Note that in a release mode compile the driver code will not actually call this (nor should user code probably).
Implemented in spicy::rt::driver::ParsingStateForDriver.
|
protected |
Forwards to debug(msg)
, also including a hexdump of the given data.
std::optional< hilti::rt::stream::Offset > driver::ParsingState::finish | ( | ) |
Finalizes parsing, signaling end-of-data to the parser. After calling this, process()
can no longer be called.
any | exceptions (including in particular final parse errors) are passed through to caller |
|
inline |
Returns false if a parser has neither been passed into the constructor nor explicitly set through setParser()
.
|
inline |
Returns true if parsing has finished due to either: regularly reaching the end of input or end of grammar, a parsing error, explicit skipping of remaining input.
|
inline |
Returns true if skipRemaining()
has been called previously.
|
inline |
Feeds one chunk of data into parsing. If we're doing stream-based parsing, this sends the data into the stream processing as the next piece of input. If we're doing block-based parsing, the data must constitute a complete self-contained block of input, so that the parser can fully consume it as one unit instance.
size | length of data |
data | pointer to size bytes to feed into parsing |
State
indicating if parsing remains ongoing or has finished. any | exceptions (including in particular parse errors) are passed through to caller |
|
inline |
Resets parsing back to its original state as if no input had been sent yet. Initialization information passed into the constructor, as well as any parser explicitly set, is retained.
|
inline |
Explicitly sets a parser to use. Once stream-based matching has started, changing a parser won't have any effect. Only parsers that do not take any unit parameters are supported, otherwise a InvalidUnitType
exception will be thrown at runtime.
parser | parser to use; can be left unset to either not perform any parsing at all, or set it later through setParser() . |
context | context to make available to unit instance during parsing |
|
inline |