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

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< BundleDefBundle
 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< BigInttry_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.
 

Detailed Description

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

Function Documentation

◆ array()

Node rego::array ( const std::initializer_list< Node > & array_members)

Converts the value to an array node.

Parameters
array_membersThe members of the array.
Returns
The array node (array (term) (term) ...)

◆ err() [1/2]

Node rego::err ( Node node,
const std::string & msg,
const std::string & code = UnknownError )

Generates an error node.

Parameters
nodeThe node for which the error occurred.
msgThe error message.
codeThe error code.
Returns
The generated error node.

◆ err() [2/2]

Node rego::err ( NodeRange & r,
const std::string & msg,
const std::string & code = UnknownError )

Generates an error node.

Parameters
rThe range of nodes over which the error occurred.
msgThe error message.
codeThe error code.
Returns
The generated error node.

◆ file_to_rego()

Reader rego::file_to_rego ( )

Parses Rego queries and virtual documents.

Bundle

◆ get_bool()

bool rego::get_bool ( const Node & node)

Extracts the value of a node as a boolean.

Parameters
nodeThe node to extract from.
Returns
The boolean value of the node.

◆ get_double()

double rego::get_double ( const Node & node)

Extracts the value of a node as an double.

Parameters
nodeThe node to extract from.
Returns
The double value of the node.

◆ get_int()

BigInt rego::get_int ( const Node & node)

Extracts the value of a node as an integer.

Parameters
nodeThe node to extract from.
Returns
The integer value of the node.

◆ get_string()

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.

Parameters
nodeThe node to extract from.
Returns
The string value of the node.

◆ log_level_from_string()

LogLevel rego::log_level_from_string ( const std::string & value)

Converts a string to a log level (case insensitive).

Parameters
valueOne of Error, Warn, Output, Info, Debug, Trace.
Returns
the corresponding log level, or LogLevel::Unsupported.

◆ object()

Node rego::object ( const std::initializer_list< Node > & object_items)

Converts the value to an object node.

Parameters
object_itemsThe object items of the object.
Returns
The object node (object (object_item) (object_item) ...)

◆ object_item()

Node rego::object_item ( const Node & key_term,
const Node & val_term )

Converts the key and val terms to an object item.

Parameters
key_termThe key term.
val_termThe value term.
Returns
The object item node (object_item (key_term) (val_term))

◆ scalar() [1/6]

Node rego::scalar ( )

Creates a null scalar.

Returns
The scalar node (scalar (NULL)))

◆ scalar() [2/6]

Node rego::scalar ( BigInt value)

Converts the value to a scalar node.

Parameters
valueThe value to convert.
Returns
The scalar node (scalar (INT

)))

◆ scalar() [3/6]

Node rego::scalar ( bool value)

Converts the value to a scalar node.

Parameters
valueThe value to convert.
Returns
The scalar node (scalar (TRUE|FALSE)))

◆ scalar() [4/6]

Node rego::scalar ( const char * value)

Converts the value to a scalar node.

Parameters
valueThe value to convert.
Returns
The scalar node (scalar (STRING

)))

◆ scalar() [5/6]

Node rego::scalar ( const std::string & value)

Converts the value to a scalar node.

Parameters
valueThe value to convert.
Returns
The scalar node (scalar (STRING

)))

◆ scalar() [6/6]

Node rego::scalar ( double value)

Converts the value to a scalar node.

Parameters
valueThe value to convert.
Returns
The scalar node (scalar (FLOAT

)))

◆ set()

Node rego::set ( const std::initializer_list< Node > & set_members)

Converts the value to a set node.

Parameters
set_membersThe members of the set.
Returns
The set node (set (term) (term) ...)

◆ to_key()

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.

Parameters
nodeThe node to convert.
set_as_arrayWhether to represent sets as arrays.
sort_arraysWhether to sort array elements.
list_delimThe delimiter to use when joining array elements.
Returns
The key representation of the node.

◆ try_get_int()

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.

Parameters
nodeThe node to extract from.
Returns
The integer value of the node

◆ try_get_item()

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.

Parameters
nodeThe object to search.
keyThe key to search for.
Returns
The item node if found, otherwise std::nullopt.

◆ unwrap() [1/2]

UnwrapResult rego::unwrap ( const Node & term,
const std::set< Token > & types )

Attempts to unwrap an argument to a specified type.

Parameters
termThe term to unwrap.
typesThe acceptable types.
Returns
An unwrap result or an appropriate error node.

◆ unwrap() [2/2]

UnwrapResult rego::unwrap ( const Node & term,
const Token & type )

Attempts to unwrap a node to a specified type.

Parameters
termThe term to unwrap.
typeThe acceptable type.
Returns
An unwrap result or an appropriate error node.

◆ unwrap_arg()

Node rego::unwrap_arg ( const Nodes & args,
const UnwrapOpt & options )

Unwraps an argument from the provided vector of nodes.

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

◆ version()

Node rego::version ( )

Returns a node representing the version of the library.

The resulting node will be an object containing:

  • The Git commit hash ("commit")
  • The library version ("regocpp_version")
  • The supported OPA Rego version ("version")
  • The environment variables ("env")