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

Options for unwrapping an argument. More...

#include <rego.hh>

Public Member Functions

 UnwrapOpt (std::size_t index)
 Construct an UnwrapOpt.
 
bool exclude_got () const
 Whether the statement indicating what was received instead of the expected type should be excluded.
 
UnwrapOptexclude_got (bool exclude_got)
 Sets whether to exclude the "got" statement in the error message.
 
bool specify_number () const
 Whether to specify in the error message which kind of number was received (i.e. integer or floating point)
 
UnwrapOptspecify_number (bool specify_number)
 Sets whether to specify in the error message which kind of number was received.
 
const std::string & code () const
 The error code for the error message. Default value if omitted is EvalTypeError.
 
UnwrapOptcode (const std::string &value)
 Sets the error code for the error message.
 
const std::string & 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>".
 
UnwrapOptpre (const std::string &value)
 Sets the error preamble.
 
const std::string & message () const
 The full error message. If this is set, no message will be generated and instead this will be returned verbatim.
 
UnwrapOptmessage (const std::string &value)
 Sets the full error message. If this is set, no message will be generated and instead this will be returned verbatim.
 
const std::string & func () const
 The name of the function. If provide, will be a prefix on the message as "<func-name>:".
 
UnwrapOptfunc (const std::string &value)
 Sets the name of the function.
 
const std::vector< Token > & types () const
 The types to match against. The operand must be one of the provided types or else an error node will be returned.
 
UnwrapOpttypes (const std::vector< Token > &value)
 Sets the types to match against.
 
const Token & type () const
 The singular type to match against.
 
UnwrapOpttype (const Token &value)
 Sets the singular type to match against.
 
Node unwrap (const Nodes &args) const
 Unwraps an argument from the provided vector of nodes.
 

Detailed Description

Options for unwrapping an argument.

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()
Creates a null scalar.

Would all be successfully unwrapped as (int 5) if the type Int 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()

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

Sets the error code for the error message.

Parameters
valueThe error code.
Returns
A reference to this UnwrapOpt.

◆ exclude_got()

UnwrapOpt & rego::UnwrapOpt::exclude_got ( bool exclude_got)

Sets whether to exclude the "got" statement in the error message.

Parameters
exclude_gotTrue to exclude the "got" statement, false to include it.
Returns
A reference to this UnwrapOpt.

◆ func() [1/2]

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

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

Returns
A reference to this UnwrapOpt.

◆ func() [2/2]

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

Sets the name of the function.

Parameters
valueThe name of the function.
Returns
A reference to this UnwrapOpt.

◆ message()

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

Sets the full error message. If this is set, no message will be generated and instead this will be returned verbatim.

Parameters
valueThe full error message.
Returns
A reference to this UnwrapOpt.

◆ pre()

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

Sets the error preamble.

Parameters
valueThe error preamble.
Returns
A reference to this UnwrapOpt.

◆ specify_number()

UnwrapOpt & rego::UnwrapOpt::specify_number ( bool specify_number)

Sets whether to specify in the error message which kind of number was received.

Parameters
specify_numberTrue to specify the kind of number, false to omit it.
Returns
A reference to this UnwrapOpt.

◆ type() [1/2]

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

The singular type to match against.

Returns
A reference to the type.

◆ type() [2/2]

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

Sets the singular type to match against.

Note
Setting this will clear the UnwrapOpt::types() vector.
Parameters
valueThe singular type to match against.
Returns
A reference to this UnwrapOpt.

◆ types() [1/2]

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 returned.

Returns
A vector of require types

◆ types() [2/2]

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

Sets the types to match against.

Note
If only a single type is provided, the type() interface will be used instead.
Parameters
valueThe types to match against.
Returns
A reference to this UnwrapOpt.

◆ 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: