![]() |
rego-cpp 1.0.0
A C++ implementation of the Rego language and runtime
|
Namespaces | |
| namespace | bundle |
Classes | |
| class | BigInt |
| Big Integer implemention based on strings. More... | |
| struct | BuiltInDef |
| Struct which defines a built-in function. More... | |
| class | BuiltInsDef |
| Manages the set of builtins used by an interpreter to resolve built-in calls. More... | |
| struct | BundleDef |
| Represents a compiled Rego bundle. More... | |
| class | Interpreter |
| This class forms the main interface to the Rego library. More... | |
| class | UnwrapOpt |
| Options for unwrapping an argument. More... | |
| struct | UnwrapResult |
| Result of unwrapping a node. More... | |
| class | VirtualMachine |
| This class implements a virtual machine that can execute compiled Rego bundles. More... | |
Typedefs | |
| using | BuiltIn = std::shared_ptr<BuiltInDef> |
| A pointer to a BuiltInDef. | |
| using | BuiltInBehavior = std::function<Node(const Nodes&)> |
| The function pointer to the behavior of the built-in. | |
| typedef std::shared_ptr< BundleDef > | Bundle |
| A pointer to a BundleDef. | |
Enumerations | |
| enum class | LogLevel : regoEnum { None = REGO_LOG_LEVEL_NONE , Error = REGO_LOG_LEVEL_ERROR , Output = REGO_LOG_LEVEL_OUTPUT , Warn = REGO_LOG_LEVEL_WARN , Info = REGO_LOG_LEVEL_INFO , Debug = REGO_LOG_LEVEL_DEBUG , Trace = REGO_LOG_LEVEL_TRACE } |
| The logging level. | |
Functions | |
| Node | unwrap_arg (const Nodes &args, const UnwrapOpt &options) |
| Unwraps an argument from the provided vector of nodes. | |
| UnwrapResult | unwrap (const Node &term, const Token &type) |
| Attempts to unwrap a node to a specified type. | |
| UnwrapResult | unwrap (const Node &term, const std::set< Token > &types) |
| Attempts to unwrap an argument to a specified type. | |
| BigInt | get_int (const Node &node) |
| Extracts the value of a node as an integer. | |
| double | get_double (const Node &node) |
| Extracts the value of a node as an double. | |
| std::optional< BigInt > | try_get_int (const Node &node) |
| Attempts to extract the value of a node as an integer. In the case that the node is a double, it will check if the double is integral, i.e. 5.0 will be considered the integer 5. | |
| std::string | get_string (const Node &node) |
| Extracts the value of a node as a string. The resulting string will have any enclosing quotes removed. | |
| bool | get_bool (const Node &node) |
| Extracts the value of a node as a boolean. | |
| std::optional< Node > | try_get_item (const Node &node, const std::string_view &key) |
| Tries to get an item within an object using its key. | |
| Node | scalar (BigInt value) |
| Converts the value to a scalar node. | |
| Node | scalar (double value) |
| Converts the value to a scalar node. | |
| Node | scalar (bool value) |
| Converts the value to a scalar node. | |
| Node | scalar (const char *value) |
| Converts the value to a scalar node. | |
| Node | scalar (const std::string &value) |
| Converts the value to a scalar node. | |
| Node | scalar () |
| Creates a null scalar. | |
| Node | object_item (const Node &key_term, const Node &val_term) |
| Converts the key and val terms to an object item. | |
| Node | object (const std::initializer_list< Node > &object_items) |
| Converts the value to an object node. | |
| Node | array (const std::initializer_list< Node > &array_members) |
| Converts the value to an array node. | |
| Node | set (const std::initializer_list< Node > &set_members) |
| Converts the value to a set node. | |
| Node | err (NodeRange &r, const std::string &msg, const std::string &code=UnknownError) |
| Generates an error node. | |
| Node | err (Node node, const std::string &msg, const std::string &code=UnknownError) |
| Generates an error node. | |
| Node | version () |
| Returns a node representing the version of the library. | |
| std::string | to_key (const trieste::Node &node, bool set_as_array=false, bool sort_arrays=false, const char *list_delim=",") |
| Converts a node to a unique key representation that can be used for comparison. | |
| LogLevel | log_level_from_string (const std::string &value) |
| Converts a string to a log level (case insensitive). | |
| Reader | file_to_rego () |
| Parses Rego queries and virtual documents. | |
| Rewriter | rego_to_input () |
| Rewrites a Query AST to an input term. | |
| Rewriter | json_to_rego (bool as_term=false) |
| Rewrites a JSON AST to a Rego data input AST. | |
| Rewriter | rego_to_json () |
| Rewrites a Rego binding term to a JSON AST. | |
| Rewriter | rego_to_yaml () |
| Rewrites a Rego binding term to a YAML AST. | |
| Rewriter | json_to_bundle () |
| Rewrites an OPA bundle JSON to a Bundle AST. | |
| Rewriter | bundle_to_json () |
| Rewrites a Bundle AST to a JSON AST in OPA bundle JSON format. | |
| Rewriter | rego_to_bundle (BuiltIns builtins=BuiltInsDef::create()) |
| Rewrites a Rego AST to a Bundle AST. | |
This namespace provides the C++ API for the library. It includes all the token types for nodes in the AST, the well-formedness definitions for each pass, the built-in system and custom types for handling various kinds of data (e.g. the BigInt class).
| Node rego::array | ( | const std::initializer_list< Node > & | array_members | ) |
Converts the value to an array node.
| array_members | The members of the array. |
| Node rego::err | ( | Node | node, |
| const std::string & | msg, | ||
| const std::string & | code = UnknownError ) |
Generates an error node.
| node | The node for which the error occurred. |
| msg | The error message. |
| code | The error code. |
| Node rego::err | ( | NodeRange & | r, |
| const std::string & | msg, | ||
| const std::string & | code = UnknownError ) |
Generates an error node.
| r | The range of nodes over which the error occurred. |
| msg | The error message. |
| code | The error code. |
| Reader rego::file_to_rego | ( | ) |
Parses Rego queries and virtual documents.
Bundle
| bool rego::get_bool | ( | const Node & | node | ) |
Extracts the value of a node as a boolean.
| node | The node to extract from. |
| double rego::get_double | ( | const Node & | node | ) |
Extracts the value of a node as an double.
| node | The node to extract from. |
| BigInt rego::get_int | ( | const Node & | node | ) |
Extracts the value of a node as an integer.
| node | The node to extract from. |
| std::string rego::get_string | ( | const Node & | node | ) |
Extracts the value of a node as a string. The resulting string will have any enclosing quotes removed.
| node | The node to extract from. |
| LogLevel rego::log_level_from_string | ( | const std::string & | value | ) |
Converts a string to a log level (case insensitive).
| value | One of Error, Warn, Output, Info, Debug, Trace. |
| Node rego::object | ( | const std::initializer_list< Node > & | object_items | ) |
Converts the value to an object node.
| object_items | The object items of the object. |
| Node rego::object_item | ( | const Node & | key_term, |
| const Node & | val_term ) |
Converts the key and val terms to an object item.
| key_term | The key term. |
| val_term | The value term. |
| Node rego::scalar | ( | ) |
Creates a null scalar.
| Node rego::scalar | ( | BigInt | value | ) |
Converts the value to a scalar node.
| value | The value to convert. |
)))
| Node rego::scalar | ( | bool | value | ) |
Converts the value to a scalar node.
| value | The value to convert. |
| Node rego::scalar | ( | const char * | value | ) |
Converts the value to a scalar node.
| value | The value to convert. |
)))
| Node rego::scalar | ( | const std::string & | value | ) |
Converts the value to a scalar node.
| value | The value to convert. |
)))
| Node rego::scalar | ( | double | value | ) |
Converts the value to a scalar node.
| value | The value to convert. |
)))
| Node rego::set | ( | const std::initializer_list< Node > & | set_members | ) |
Converts the value to a set node.
| set_members | The members of the set. |
| std::string rego::to_key | ( | const trieste::Node & | node, |
| bool | set_as_array = false, | ||
| bool | sort_arrays = false, | ||
| const char * | list_delim = "," ) |
Converts a node to a unique key representation that can be used for comparison.
| node | The node to convert. |
| set_as_array | Whether to represent sets as arrays. |
| sort_arrays | Whether to sort array elements. |
| list_delim | The delimiter to use when joining array elements. |
| std::optional< BigInt > rego::try_get_int | ( | const Node & | node | ) |
Attempts to extract the value of a node as an integer. In the case that the node is a double, it will check if the double is integral, i.e. 5.0 will be considered the integer 5.
| node | The node to extract from. |
| std::optional< Node > rego::try_get_item | ( | const Node & | node, |
| const std::string_view & | key ) |
Tries to get an item within an object using its key.
| node | The object to search. |
| key | The key to search for. |
| UnwrapResult rego::unwrap | ( | const Node & | term, |
| const std::set< Token > & | types ) |
Attempts to unwrap an argument to a specified type.
| term | The term to unwrap. |
| types | The acceptable types. |
| UnwrapResult rego::unwrap | ( | const Node & | term, |
| const Token & | type ) |
Attempts to unwrap a node to a specified type.
| term | The term to unwrap. |
| type | The acceptable type. |
| Node rego::unwrap_arg | ( | const Nodes & | args, |
| const UnwrapOpt & | options ) |
Unwraps an argument from the provided vector of nodes.
| args | The vector of nodes to unwrap from. |
| options | The options for unwrapping. |
| Node rego::version | ( | ) |
Returns a node representing the version of the library.
The resulting node will be an object containing: