![]() |
rego-cpp 0.4.5
A C++ implementation of the Rego language and runtime
|
Classes | |
class | BigInt |
struct | BuiltInDef |
class | BuiltInsDef |
class | Interpreter |
class | UnwrapOpt |
struct | UnwrapResult |
Typedefs | |
using | BuiltIn = std::shared_ptr<BuiltInDef> |
using | BuiltInBehavior = std::function<Node(const Nodes&)> |
using | BuiltIns = std::shared_ptr<BuiltInsDef> |
Enumerations | |
enum class | LogLevel : char { 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 } |
Functions | |
Node | unwrap_arg (const Nodes &args, const UnwrapOpt &options) |
UnwrapResult | unwrap (const Node &term, const Token &type) |
UnwrapResult | unwrap (const Node &term, const std::set< Token > &types) |
BigInt | get_int (const Node &node) |
double | get_double (const Node &node) |
std::optional< BigInt > | try_get_int (const Node &node) |
std::string | get_string (const Node &node) |
bool | get_bool (const Node &node) |
std::optional< Node > | try_get_item (const Node &node, const std::string_view &key) |
Node | scalar (BigInt value) |
Node | scalar (double value) |
Node | scalar (bool value) |
Node | scalar (const char *value) |
Node | scalar (const std::string &value) |
Node | scalar () |
Node | object_item (const Node &key_term, const Node &val_term) |
Node | object (const Nodes &object_items) |
Node | array (const Nodes &array_members) |
Node | set (const Nodes &set_members) |
void | set_tzdata_path (const std::filesystem::path &path) |
Node | err (NodeRange &r, const std::string &msg, const std::string &code=UnknownError) |
Node | err (Node node, const std::string &msg, const std::string &code=UnknownError) |
Node | version () |
std::string | to_key (const trieste::Node &node, bool set_as_array=false, bool sort_arrays=false) |
void | set_log_level (LogLevel level) |
std::string | set_log_level_from_string (const std::string &level) |
Reader | reader (bool v1_compatible=false) |
Rewriter | to_input () |
Rewriter | unify (BuiltIns builtins=BuiltInsDef::create()) |
Rewriter | from_json (bool as_term=false) |
Rewriter | to_json () |
Rewriter | to_yaml () |
Variables | |
const auto | Module = TokenDef("rego-module", flag::symtab) |
const auto | Package = TokenDef("rego-package") |
const auto | Policy = TokenDef("rego-policy") |
const auto | Rule = TokenDef("rego-rule", flag::symtab) |
const auto | RuleHead = TokenDef("rego-rulehead") |
const auto | RuleHeadComp = TokenDef("rego-ruleheadcomp") |
const auto | RuleHeadFunc = TokenDef("rego-ruleheadfunc") |
const auto | RuleHeadSet = TokenDef("rego-ruleheadset") |
const auto | RuleHeadObj = TokenDef("rego-ruleheadobj") |
const auto | RuleArgs = TokenDef("rego-ruleargs") |
const auto | Query = TokenDef("rego-query") |
const auto | Literal = TokenDef("rego-literal") |
const auto | Expr = TokenDef("rego-expr") |
const auto | ExprInfix = TokenDef("rego-exprinfix") |
const auto | ExprCall = TokenDef("rego-exprcall") |
const auto | ExprEvery = TokenDef("rego-exprevery") |
const auto | ExprParens = TokenDef("rego-exprparens") |
const auto | UnaryExpr = TokenDef("rego-unaryexpr") |
const auto | NotExpr = TokenDef("rego-not-expr") |
const auto | Term = TokenDef("rego-term") |
const auto | InfixOperator = TokenDef("rego-infixoperator") |
const auto | BoolOperator = TokenDef("rego-booloperator") |
const auto | ArithOperator = TokenDef("rego-arithoperator") |
const auto | AssignOperator = TokenDef("rego-assignoperator") |
const auto | BinOperator = TokenDef("rego-binoperator") |
const auto | Ref = TokenDef("rego-ref") |
const auto | RefArgBrack = TokenDef("rego-refargbrack") |
const auto | RefArgDot = TokenDef("rego-refargdot") |
const auto | Var = TokenDef("rego-var", flag::print) |
const auto | Scalar = TokenDef("rego-scalar") |
const auto | String = TokenDef("rego-string") |
const auto | Array = TokenDef("rego-array") |
const auto | Object = TokenDef("rego-object") |
const auto | Set = TokenDef("rego-set") |
const auto | ObjectItem = TokenDef("rego-objectitem") |
const auto | RawString = TokenDef("rego-rawstring", flag::print) |
const auto | JSONString = TokenDef("rego-STRING", flag::print) |
const auto | Int = TokenDef("rego-INT", flag::print) |
const auto | Float = TokenDef("rego-FLOAT", flag::print) |
const auto | True = TokenDef("rego-true") |
const auto | False = TokenDef("rego-false") |
const auto | Null = TokenDef("rego-null") |
const auto | Equals = TokenDef("rego-equals") |
const auto | NotEquals = TokenDef("rego-notequals") |
const auto | LessThan = TokenDef("rego-lessthan") |
const auto | GreaterThan = TokenDef("rego-greaterthan") |
const auto | LessThanOrEquals = TokenDef("rego-lessthanorequals") |
const auto | GreaterThanOrEquals = TokenDef("rego-greaterthanorequals") |
const auto | Add = TokenDef("rego-add") |
const auto | Subtract = TokenDef("rego-subtract") |
const auto | Multiply = TokenDef("rego-multiply") |
const auto | Divide = TokenDef("rego-divide") |
const auto | Modulo = TokenDef("rego-modulo") |
const auto | And = TokenDef("rego-and") |
const auto | Or = TokenDef("rego-or") |
const auto | Assign = TokenDef("rego-assign") |
const auto | Unify = TokenDef("rego-unify") |
const auto | Default = TokenDef("rego-default") |
const auto | Some = TokenDef("rego-some") |
const auto | SomeDecl = TokenDef("rego-somedecl") |
const auto | If = TokenDef("rego-if") |
const auto | IsIn = TokenDef("rego-in") |
const auto | Contains = TokenDef("rego-contains") |
const auto | Else = TokenDef("rego-else") |
const auto | As = TokenDef("rego-as") |
const auto | With = TokenDef("rego-with") |
const auto | Every = TokenDef("rego-every") |
const auto | ArrayCompr = TokenDef("rego-arraycompr") |
const auto | ObjectCompr = TokenDef("rego-objectcompr") |
const auto | SetCompr = TokenDef("rego-setcompr") |
const auto | Membership = TokenDef("rego-membership") |
const auto | Not = TokenDef("rego-not") |
const auto | Import |
const auto | Placeholder = TokenDef("rego-placeholder") |
const auto | Version = TokenDef("rego-version", flag::print) |
const auto | RuleBodySeq = TokenDef("rego-rulebodyseq") |
const auto | ImportSeq = TokenDef("rego-importseq") |
const auto | RuleRef = TokenDef("rego-ruleref") |
const auto | RuleHeadType = TokenDef("rego-ruleheadtype") |
const auto | WithSeq = TokenDef("rego-withseq") |
const auto | TermSeq = TokenDef("rego-termseq") |
const auto | ExprSeq = TokenDef("rego-exprseq") |
const auto | VarSeq = TokenDef("rego-varseq") |
const auto | RefHead = TokenDef("rego-refhead") |
const auto | RefArgSeq = TokenDef("rego-refargseq") |
const auto | Key = TokenDef("rego-key", flag::print) |
const auto | Val = TokenDef("rego-value") |
const auto | Undefined = TokenDef("rego-undefined") |
const auto | Results = TokenDef("rego-results", flag::symtab) |
const auto | Result = TokenDef("rego-result", flag::symtab) |
const auto | Bindings = TokenDef("rego-bindings") |
const auto | Terms = TokenDef("rego-terms") |
const auto | Binding = TokenDef("rego-binding", flag::lookdown) |
const auto | ErrorCode = TokenDef("rego-errorcode") |
const auto | ErrorSeq = TokenDef("rego-errorseq") |
const auto | wf_assign_op = Assign | Unify |
const auto | wf_arith_op = Add | Subtract | Multiply | Divide | Modulo |
const auto | wf_bin_op = And | Or | Subtract |
const auto | wf_bool_op |
const auto | wf_exprs |
const auto | wf |
const auto | wf_result |
const std::size_t | AnyArity = std::numeric_limits<std::size_t>::max() |
const std::string | UnknownError = "unknown_error" |
const std::string | EvalTypeError = "eval_type_error" |
const std::string | EvalBuiltInError = "eval_builtin_error" |
const std::string | RegoTypeError = "rego_type_error" |
const std::string | RegoParseError = "rego_parse_error" |
const std::string | RegoCompileError = "rego_compile_error" |
const std::string | EvalConflictError = "eval_conflict_error" |
const std::string | WellFormedError = "wellformed_error" |
const std::string | RuntimeError = "runtime_error" |
const std::string | RecursionError = "rego_recursion_error" |
const std::string | DefaultVersion = "v0" |
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).
using rego::BuiltIn = std::shared_ptr<BuiltInDef> |
A pointer to a BuiltInDef.
using rego::BuiltInBehavior = std::function<Node(const Nodes&)> |
The function pointer to the behavior of the built-in.
|
strong |
The logging level.
Node rego::array | ( | const Nodes & | 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. |
Rewriter rego::from_json | ( | bool | as_term = false | ) |
Rewrites a JSON AST to a Rego data input AST.
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 a 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. |
Node rego::object | ( | const Nodes & | 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. |
Reader rego::reader | ( | bool | v1_compatible = false | ) |
Parses Rego queries and virtual documents.
Node rego::scalar | ( | ) |
Converts the value to a scalar node.
value | The value to convert. |
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 Nodes & | set_members | ) |
Converts the value to a set node.
set_members | The members of the set. |
void rego::set_log_level | ( | LogLevel | level | ) |
Sets the logging level for the library.
level | The logging level. |
std::string rego::set_log_level_from_string | ( | const std::string & | level | ) |
Sets the logging level for the library.
level | The logging level. One of "None", "Error", "Output", "Warn", "Info", "Debug", or "Trace". |
void rego::set_tzdata_path | ( | const std::filesystem::path & | path | ) |
Sets the location where rego-cpp will look for timezone database information.
The timezone database will be interpreted as one obtained from the IANA (https://www.iana.org/time-zones) which has been downloaded and unpacked into at the path provided. If the library was built without manual tzdata support, this function will throw an exception.
path | The path to the timezone database. |
Rewriter rego::to_input | ( | ) |
Rewrites a Query AST to an input term.
Rewriter rego::to_json | ( | ) |
Rewrites a Rego binding term to a JSON AST.
std::string rego::to_key | ( | const trieste::Node & | node, |
bool | set_as_array = false, | ||
bool | sort_arrays = false ) |
Converts a node to a unique key representation.
node | The node to convert. |
set_as_array | Whether to represent sets as arrays. |
Rewriter rego::to_yaml | ( | ) |
Rewrites a Rego binding term to a YAML AST.
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. |
Rewriter rego::unify | ( | BuiltIns | builtins = BuiltInsDef::create() | ) |
Unifies a set of base and virtual documents, an input term, and a query.
UnwrapResult rego::unwrap | ( | const Node & | term, |
const std::set< Token > & | types ) |
Attempts to unwrap an argument to one of the specified types.
term | The term to unwrap. |
types | The acceptable types. |
UnwrapResult rego::unwrap | ( | const Node & | term, |
const Token & | type ) |
Attempts to unwrap an argument 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:
const std::size_t rego::AnyArity = std::numeric_limits<std::size_t>::max() |
This constant indicates that a built-in can receive any number of arguments.
|
inline |
|
inline |
|
inline |
|
inline |