Spicy
Public Types | Public Member Functions | Protected Member Functions | List of all members
spicy::rt::driver::ParsingState Class Referenceabstract

#include <driver.h>

Inheritance diagram for spicy::rt::driver::ParsingState:
spicy::rt::driver::ParsingStateForDriver

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)
 

Detailed Description

Abstract base class maintaining the parsing state during incremental input processing.

Member Enumeration Documentation

◆ State

Helper type for capturing return value of process().

Enumerator
Done 

parsing has fully finished

Continue 

parsing remains ongoing and ready to accept for data

Constructor & Destructor Documentation

◆ ParsingState()

spicy::rt::driver::ParsingState::ParsingState ( ParsingType  type,
const Parser parser = nullptr,
std::optional< UnitContext context = {} 
)
inline

Constructor.

Parameters
typeof parsing; this determines how subsequent chunks of input data are handled (stream-wise vs independent blocks)
parserparser 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.
contextcontext to make available to unit instance during parsing

Member Function Documentation

◆ debug() [1/2]

virtual void spicy::rt::driver::ParsingState::debug ( const std::string &  msg)
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.

◆ debug() [2/2]

void driver::ParsingState::debug ( const std::string &  msg,
size_t  size,
const char *  data 
)
protected

Forwards to debug(msg), also including a hexdump of the given data.

◆ finish()

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.

Exceptions
anyexceptions (including in particular final parse errors) are passed through to caller

◆ hasParser()

bool spicy::rt::driver::ParsingState::hasParser ( ) const
inline

Returns false if a parser has neither been passed into the constructor nor explicitly set through setParser().

◆ isFinished()

bool spicy::rt::driver::ParsingState::isFinished ( ) const
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.

◆ isSkipping()

bool spicy::rt::driver::ParsingState::isSkipping ( ) const
inline

Returns true if skipRemaining() has been called previously.

◆ process()

State spicy::rt::driver::ParsingState::process ( size_t  size,
const char *  data 
)
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.

Parameters
sizelength of data
datapointer to size bytes to feed into parsing. If this is a nullptr a gap of length size will be processed.
Returns
Returns State indicating if parsing remains ongoing or has finished.
Exceptions
anyexceptions (including in particular parse errors) are passed through to caller

◆ reset()

void spicy::rt::driver::ParsingState::reset ( )
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.

◆ setParser()

void spicy::rt::driver::ParsingState::setParser ( const Parser parser,
std::optional< UnitContext context = {} 
)
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.

Parameters
parserparser to use; can be left unset to either not perform any parsing at all, or set it later through setParser().
contextcontext to make available to unit instance during parsing

◆ skipRemaining()

void spicy::rt::driver::ParsingState::skipRemaining ( )
inline

Explicitly skips any remaining input. Further calls to process() and finish() will be ignored.


The documentation for this class was generated from the following files: