rego-cpp 0.4.5
A C++ implementation of the Rego language and runtime
Loading...
Searching...
No Matches
rego::UnwrapOpt Class Reference

#include <rego.hh>

Public Member Functions

 UnwrapOpt (std::size_t index)
 
bool exclude_got () const
 
UnwrapOptexclude_got (bool exclude_got)
 
bool specify_number () const
 
UnwrapOptspecify_number (bool specify_number)
 
const std::string & code () const
 
UnwrapOptcode (const std::string &value)
 
const std::string & pre () const
 
UnwrapOptpre (const std::string &value)
 
const std::string & message () const
 
UnwrapOptmessage (const std::string &value)
 
const std::string & func () const
 
UnwrapOptfunc (const std::string &value)
 
const std::vector< Token > & types () const
 
UnwrapOpttypes (const std::vector< Token > &value)
 
const Token & type () const
 
UnwrapOpttype (const Token &value)
 
Node unwrap (const Nodes &args) const
 

Detailed Description

This struct provides options for unwrapping an argument and producing an error message.

The act of unwrapping a node is the process of testing whether a node or one of its direct descendents is of one or more types. So, for example, the following nodes:

(term (scalar (int 5)))
(scalar (int 5))
(int 5)
Node scalar()

Would all be successfully unwrapped as (int 5) if the type JSONInt was specified. However, if Float was specified, the result would be an error node.

Constructor & Destructor Documentation

◆ UnwrapOpt()

rego::UnwrapOpt::UnwrapOpt ( std::size_t index)

Construct an UnwrapOpt.

Parameters
indexThe index of the argument to unwrap.

Member Function Documentation

◆ code()

const std::string & rego::UnwrapOpt::code ( ) const

The error code for the error message.

Default value if omitted is EvalTypeError.

◆ exclude_got()

bool rego::UnwrapOpt::exclude_got ( ) const

Whether the statement indicating what was received instead of the expect type should be excluded.

◆ func()

const std::string & rego::UnwrapOpt::func ( ) const

The name of the function.

If provide, will be a prefix on the message as "<func-name>:"

◆ message()

const std::string & rego::UnwrapOpt::message ( ) const

The full error message.

If this is set, no message will be generated and instead this will be returned verbatim.

◆ pre()

const std::string & rego::UnwrapOpt::pre ( ) const

The error preamble.

If omitted, a default preamble will be constructed from the operation metadata in the form "operand <i> must be <t>".

◆ specify_number()

bool rego::UnwrapOpt::specify_number ( ) const

Whether to specify in the error message which kind of number was received (i.e. integer or floating point)

◆ type()

const Token & rego::UnwrapOpt::type ( ) const

The singular type to match against.

◆ types()

const std::vector< Token > & rego::UnwrapOpt::types ( ) const

The types to match against.

The operand must be one of the provided types or else an error node will be return.

◆ unwrap()

Node rego::UnwrapOpt::unwrap ( const Nodes & args) const

Unwraps an argument from the provided vector of nodes.

Parameters
argsThe vector of nodes to unwrap from.
Returns
The unwrapped argument or an appropriate error node.

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