rego-cpp 0.4.5
A C++ implementation of the Rego language and runtime
|
#include <rego.hh>
Public Member Functions | |
Interpreter (bool v1_compatible=false) | |
Node | add_module_file (const std::filesystem::path &path) |
Node | add_module (const std::string &name, const std::string &contents) |
Node | add_data_json_file (const std::filesystem::path &path) |
Node | add_data_json (const std::string &json) |
Node | add_data (const Node &node) |
Node | set_input_json_file (const std::filesystem::path &path) |
Node | set_input_term (const std::string &term) |
Node | set_input (const Node &node) |
std::string | query (const std::string &query_expr) |
Node | raw_query (const std::string &query_expr) |
Interpreter & | debug_path (const std::filesystem::path &prefix) |
const std::filesystem::path & | debug_path () const |
Interpreter & | debug_enabled (bool enabled) |
bool | debug_enabled () const |
Interpreter & | wf_check_enabled (bool enabled) |
bool | wf_check_enabled () const |
BuiltInsDef & | builtins () const |
Friends | |
const char * | regoGetError (regoInterpreter *rego) |
void | setError (regoInterpreter *rego, const std::string &error) |
regoOutput * | regoQuery (regoInterpreter *rego, const char *query_expr) |
This class forms the main interface to the Rego library.
You can use it to assemble and then execute queries, for example:
rego::Interpreter::Interpreter | ( | bool | v1_compatible = false | ) |
Constructor.
v1_compatible | whether the Interpreter should run in rego-v1 mode. |
Node rego::Interpreter::add_data | ( | const Node & | node | ) |
Adds a base document to the interpreter.
Adds an AST node directly to the interpreter's data sequence. Use with caution.
node | The contents of the document. |
Node rego::Interpreter::add_data_json | ( | const std::string & | json | ) |
Adds a base document to the interpreter.
The document must contain a single JSON-encoded object, and will be parsed and added to the interpreter's data sequence.
json | The contents of the document. |
Node rego::Interpreter::add_data_json_file | ( | const std::filesystem::path & | path | ) |
Adds a base document to the interpreter.
This is the same as calling Interpreter::add_data_json with the contents of the file.
module | The module to add. |
Node rego::Interpreter::add_module | ( | const std::string & | name, |
const std::string & | contents ) |
Adds a module (i.e. virtual document) to the interpreter.
The module will be parsed and added to the interpreter's module sequence.
name | The name of the module. |
contents | The contents of the module. |
Node rego::Interpreter::add_module_file | ( | const std::filesystem::path & | path | ) |
Adds a module (i.e. virtual document) file to the interpreter.
This is the same as calling Interpreter::add_module with the contents of the file.
path | The path to the module file. |
BuiltInsDef & rego::Interpreter::builtins | ( | ) | const |
The built-ins used by the interpreter.
This object can be used to register custom built-ins created using BuiltInDef::create.
Interpreter & rego::Interpreter::debug_enabled | ( | bool | enabled | ) |
Whether debug mode is enabled.
If true, then the interpreter will output intermediary ASTs after each compiler pass to the debug directory set via Interpreter::debug_path.
Interpreter & rego::Interpreter::debug_path | ( | const std::filesystem::path & | prefix | ) |
The path to the debug directory.
If set, then (when in debug mode) the interpreter will output intermediary ASTs after each compiler pass to the debug directory. If the directory does not exist, it will be created.
std::string rego::Interpreter::query | ( | const std::string & | query_expr | ) |
Executes a query against the interpreter.
This method calls Interpreter::raw_query and then converts it into a human-readable string.
query_expr | The query expression. |
Node rego::Interpreter::raw_query | ( | const std::string & | query_expr | ) |
Executes a query against the interpreter.
The query expression must be a valid Rego query expression. The result will be an AST node representing the result, which will either be a list of bindings and terms, or an error sequence.
query_expr | The query expression. |
Node rego::Interpreter::set_input | ( | const Node & | node | ) |
Sets the input document to the interpreter.
Sets an AST node directly as the interpreter's input. Use with caution.
node | The contents of the document. |
Node rego::Interpreter::set_input_json_file | ( | const std::filesystem::path & | path | ) |
Sets the input document to the interpreter.
This is the same as calling Interpreter::add_input_json with the contents of the file.
path | The path to the input file. |
Node rego::Interpreter::set_input_term | ( | const std::string & | term | ) |
Sets the input term of the interpreter.
The string must contain a single valid Rego data term.
term | The contents of the term. |
Interpreter & rego::Interpreter::wf_check_enabled | ( | bool | enabled | ) |
Whether well-formed checks are enabled.
If true, then the interpreter will perform well-formedness checks after each compiler pass using the well-formedness definitions.
|
friend |
Returns the most recently thrown error.
If an error code is returned from an interface function, more error information can be obtained by calling this function.
rego | The interpreter. |
|
friend |
Performs a query against the current base and virtual documents.
The query expression should be a Rego query. The output of the query will be returned as a regoOutput object. The caller is responsible for freeing the output object with regoFreeOutput.
rego | The interpreter. |
query_expr | The query expression. |