Parsnip
parsing library
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends
Parsnip::Evaluator Class Referenceabstract

Evaluator base class. More...

#include <parsnip_evaluate.h>

Inheritance diagram for Parsnip::Evaluator:
Parsnip::EndOfOptionEvaluator Parsnip::KeywordEvaluator Parsnip::RemainderEvaluator Parsnip::TerminatorEvaluator Parsnip::ValueEvaluator Parsnip::OptionEvaluator Parsnip::RemainingValuesEvaluator Parsnip::IntegerEvaluator Parsnip::RealEvaluator Parsnip::StringEvaluator Parsnip::RawRemainderEvaluator Parsnip::RegExEvaluator

Public Types

using StringType = std::string
 
using CommandId = int
 

Public Member Functions

 Evaluator (Evaluator *original)
 Upgrade an evaluator.
 
int evaluate (ArgvCursor *cursor, Parsnip::Data &result_dict)
 Evaluate a token in the command line, and recurse if there is more to go.
 
virtual bool operator== (const Evaluator &) const
 Check if two evaluators are the same.
 
bool operator!= (const Evaluator &other) const
 

Static Public Member Functions

static void construct (EvaluatorRef &evaluator, const ArgvCursor &cursor, CommandId id, Parser *parent_parser)
 Construct token handler from the token in a parsing definition.
 

Protected Member Functions

void setCommandId (CommandId id)
 Set the command ID in an evaluator.
 
virtual EvaluatorgetNextEvaluator (const StringType &token) const =0
 Determine if and how to evaluate additional command line tokens.
 
virtual Parsnip::Data evaluateToken (class ArgvCursor *cursor) const =0
 Evaluate command line tokens.
 
virtual void convertToOptionEvaluator ()=0
 Make any changes to the parse tree to convert it to an options evaluator.
 
virtual void constructSchema (const DictionarySchema &schema, const Schema::OptionSchemas &option_schemas, const SchemaIntegratorCallback &integrator) const =0
 Construct a schema from an evaluator tree.
 

Static Protected Member Functions

static void set_name (EvaluatorRef &target, const std::string &name)
 Assign a name by which to store values for value evaluators.
 

Protected Attributes

CommandId command_id {NoCommand}
 If this completes a command, the command ID.
 
std::string name
 If not empty, the name by which this value shall be accessed.
 

Friends

class ValueEvaluator
 
class KeywordEvaluator
 
class RemainingValuesEvaluator
 
class RemainderEvaluator
 
class OptionEvaluator
 
class OptionParser
 
class Schema
 
class SchemaSet
 

Detailed Description

Evaluator base class.

Constructor & Destructor Documentation

◆ Evaluator()

Parsnip::Evaluator::Evaluator ( Evaluator original)

Upgrade an evaluator.

The original must be a TerminatorEvaluator; other type should never be upgraded. Herein we initialize the new evaluator with the relevant bits.

Member Function Documentation

◆ construct()

void Parsnip::Evaluator::construct ( EvaluatorRef &  parser,
const ArgvCursor cursor,
CommandId  id,
Parser parent_parser 
)
static

Construct token handler from the token in a parsing definition.

Parameters
parserThe parser to update or construct with new definitions.
cursorPoints to the token defining what to construct.
idThe command ID to use for completed commands of this definition.
parent_parserPassed through; see ValueEvaluator::construct.

◆ constructSchema()

virtual void Parsnip::Evaluator::constructSchema ( const DictionarySchema schema,
const Schema::OptionSchemas &  option_schemas,
const SchemaIntegratorCallback &  integrator 
) const
protectedpure virtual

Construct a schema from an evaluator tree.

This function depth-first searches the evaluation tree, calling the integrator function at leaf nodes and other valid statement endpoints.

Parameters
schemaThe schema, as constructed from the parse tree root.
option_schemasSchemas for option parsers that may be needed.
integratorAn integrator that merges various statement patterns into a complete schema.
Exceptions
NoSuchKeyA necessary option schema was not found.
SchemaConflictStatement definitions generate schema inconsistencies.

Implemented in Parsnip::ValueEvaluator, Parsnip::KeywordEvaluator, Parsnip::RemainingValuesEvaluator, and Parsnip::OptionEvaluator.

◆ convertToOptionEvaluator()

virtual void Parsnip::Evaluator::convertToOptionEvaluator ( )
protectedpure virtual

Make any changes to the parse tree to convert it to an options evaluator.

Implemented in Parsnip::ValueEvaluator, Parsnip::KeywordEvaluator, and Parsnip::RemainderEvaluator.

◆ evaluate()

int Parsnip::Evaluator::evaluate ( ArgvCursor cursor,
Parsnip::Data result_dict 
)

Evaluate a token in the command line, and recurse if there is more to go.

Parameters
cursorProvides the command line tokens.
result_dictDictionary into which to put values.
Returns
ID code of command selected.

◆ evaluateToken()

virtual Parsnip::Data Parsnip::Evaluator::evaluateToken ( class ArgvCursor cursor) const
protectedpure virtual

Evaluate command line tokens.

Parameters
cursorProvides tokens from the command line. Must be bumped forward as they are processed.
Returns
Parsnip data object containing evaluated token.

Implemented in Parsnip::StringEvaluator, Parsnip::RegExEvaluator, Parsnip::RawRemainderEvaluator, Parsnip::IntegerEvaluator, Parsnip::RealEvaluator, Parsnip::KeywordEvaluator, Parsnip::RemainingValuesEvaluator, and Parsnip::OptionEvaluator.

◆ getNextEvaluator()

virtual Evaluator * Parsnip::Evaluator::getNextEvaluator ( const StringType &  token) const
protectedpure virtual

Determine if and how to evaluate additional command line tokens.

Parameters
tokenThe current token being evaluated.
Returns
The evaluator for the next token, or nullptr if evaluation is complete.

Implemented in Parsnip::KeywordEvaluator, Parsnip::ValueEvaluator, and Parsnip::RemainderEvaluator.

◆ operator==()

bool Parsnip::Evaluator::operator== ( const Evaluator other) const
virtual

Check if two evaluators are the same.

Subclasses should override this to check their details.

Parameters
otherAnother evaluator to which to compare.

Reimplemented in Parsnip::OptionEvaluator, Parsnip::ValueEvaluator, Parsnip::RegExEvaluator, Parsnip::IntegerEvaluator, Parsnip::RealEvaluator, Parsnip::KeywordEvaluator, and Parsnip::RemainderEvaluator.

◆ set_name()

void Parsnip::Evaluator::set_name ( EvaluatorRef &  target,
const std::string &  nam 
)
staticprotected

Assign a name by which to store values for value evaluators.

There must be no prior name, or the same as the prior name.

Parameters
targetThe evalutor whose name to set. If necessary, the target is instantiated.
namThe name. If empty the assignment is ignored.

◆ setCommandId()

void Parsnip::Evaluator::setCommandId ( CommandId  id)
protected

Set the command ID in an evaluator.

The ID must not be redefined/changed.

Parameters
idThe ID being set.

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