![]() |
rego-cpp 1.4.0
A C++ implementation of the Rego language and runtime
|
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. | |
| UnwrapOpt & | exclude_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) | |
| UnwrapOpt & | specify_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. | |
| UnwrapOpt & | code (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>". | |
| UnwrapOpt & | pre (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. | |
| 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. | |
| const std::string & | func () const |
| The name of the function. If provide, will be a prefix on the message as "<func-name>:". | |
| UnwrapOpt & | func (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. | |
| UnwrapOpt & | types (const std::vector< Token > &value) |
| Sets the types to match against. | |
| const Token & | type () const |
| The singular type to match against. | |
| UnwrapOpt & | type (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. | |
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:
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.
| rego::UnwrapOpt::UnwrapOpt | ( | std::size_t | index | ) |
Construct an UnwrapOpt.
| index | The index of the argument to unwrap. |
Sets the error code for the error message.
| value | The error code. |
Sets whether to exclude the "got" statement in the error message.
| exclude_got | True to exclude the "got" statement, false to include it. |
| const std::string & rego::UnwrapOpt::func | ( | ) | const |
The name of the function. If provide, will be a prefix on the message as "<func-name>:".
Sets the name of the function.
| value | The name of the function. |
Sets the full error message. If this is set, no message will be generated and instead this will be returned verbatim.
| value | The full error message. |
Sets whether to specify in the error message which kind of number was received.
| specify_number | True to specify the kind of number, false to omit it. |
The singular type to match against.
Sets the singular type to match against.
| value | The singular type to match against. |
The types to match against. The operand must be one of the provided types or else an error node will be returned.
Unwraps an argument from the provided vector of nodes.
| args | The vector of nodes to unwrap from. |