{"id":15214463,"url":"https://github.com/microsoft/rego-cpp","last_synced_at":"2026-01-08T17:19:36.049Z","repository":{"id":158076017,"uuid":"633814000","full_name":"microsoft/rego-cpp","owner":"microsoft","description":"A C++ interpreter for the OPA policy language Rego","archived":false,"fork":false,"pushed_at":"2025-02-11T12:11:53.000Z","size":3352,"stargazers_count":34,"open_issues_count":13,"forks_count":11,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-29T22:08:08.225Z","etag":null,"topics":["c","cpp","opa","policy","policy-engine","python","rust"],"latest_commit_sha":null,"homepage":"https://microsoft.github.io/rego-cpp/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/microsoft.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":"SUPPORT.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-28T10:40:36.000Z","updated_at":"2025-03-11T15:11:59.000Z","dependencies_parsed_at":"2024-01-22T12:14:39.747Z","dependency_job_id":"c590b1ca-d2d4-4040-9a66-bfb12e6af9de","html_url":"https://github.com/microsoft/rego-cpp","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2Frego-cpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2Frego-cpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2Frego-cpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2Frego-cpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/microsoft","download_url":"https://codeload.github.com/microsoft/rego-cpp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247411231,"owners_count":20934653,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","cpp","opa","policy","policy-engine","python","rust"],"created_at":"2024-09-28T10:05:30.610Z","updated_at":"2026-01-08T17:19:36.041Z","avatar_url":"https://github.com/microsoft.png","language":"C++","readme":"# `rego-cpp`\n\nThis project is an effort to create a C++ interpreter for the OPA policy language,\n[Rego](https://www.openpolicyagent.org/docs/latest/policy-language/). Our goal is\nto build both a standalone executable and a library such that programmers who are working\nin C++ can interpret Rego programs natively. To achieve this we are building our\ninterpreter on top of the experimental term rewriter\n[Trieste](https://github.com/microsoft/trieste).\n\n## Getting Started\n\nStart by installing [CMake](https://cmake.org/) in the way appropriate for your\nenvironment.\n\n### Linux\n\nCreate a build directory and initialize the cmake project:\n\n    mkdir build\n    cd build\n    cmake .. --preset release-clang\n\nYou can then build and run the tests using:\n\n    ninja install\n    ctest\n\n### Windows\n\nCreate a build directory and initialize the cmake project:\n\n    mkdir build\n    cd build\n    cmake .. --preset release\n\nYou can then build and run the tests using:\n\n    cmake --build . --config Release --target INSTALL\n    ctest -C Release\n\n### Using the `rego` CLI\n\nThe interpreter tool will be located at `build/dist/bin/rego`. Here are\nsome example commands using the provided example files and run from the suggested\n`dist` install directory:\n\n    ./bin/rego eval -d examples/scalars.rego -q data.scalars.greeting\n    {\"expressions\":[\"Hello\"]}\n\n    ./bin/rego eval -d examples/objects.rego -q data.objects.sites[1].name\n    {\"expressions\":[\"smoke1\"]}\n\n    ./bin/rego eval -d examples/data0.json examples/data1.json examples/objects.rego -i examples/input0.json  -q \"[data.one, input.b, data.objects.sites[1]]\"\n    {\"expressions\":[[{\"bar\":\"Foo\", \"baz\":5, \"be\":true, \"bop\":23.4},\"20\",{\"name\":\"smoke1\"}]]}\n\n    ./bin/rego eval -q \"x=5; y=x + (2 - 4 * 0.25) * -3 + 7.4\"\n    {\"expressions\":[true, true], \"bindings\":{\"x\":5, \"y\":9.4}}\n\n    ./bin/rego eval -d examples/bodies.rego -i examples/input1.json -q data.bodies.e\n    {\"expressions\":[{\"one\":15, \"two\":15}]}\n\nYou can run the test driver from the same directory:\n\n    ./bin/rego_test tests/regocpp.yaml\n\n### Using the `rego` Library\n\nSee the [examples](examples/README.md) directory for examples of how to use the\nlibrary from different langauages.\n\n## Language Support {#language-support}\n\nWe support v1.8.0 of Rego as defined by OPA, with the following grammar:\n\n```ebnf\nmodule          = package { import } policy\npackage         = \"package\" ref\nimport          = \"import\" ref [ \"as\" var ]\npolicy          = { rule }\nrule            = [ \"default\" ] rule-head { rule-body }\nrule-head       = ( ref | var ) ( rule-head-set | rule-head-obj | rule-head-func | rule-head-comp )\nrule-head-comp  = [ assign-operator term ] [ \"if\" ]\nrule-head-obj   = \"[\" term \"]\" [ assign-operator term ] [ \"if\" ]\nrule-head-func  = \"(\" rule-args \")\" [ assign-operator term ] [ \"if\" ]\nrule-head-set   = \"contains\" term [ \"if\" ] | \"[\" term \"]\"\nrule-args       = term { \",\" term }\nrule-body       = [ \"else\" [ assign-operator term ] [ \"if\" ] ] ( \"{\" query \"}\" ) | literal\nquery           = literal { ( \";\" | ( [CR] LF ) ) literal }\nliteral         = ( some-decl | expr | \"not\" expr ) { with-modifier }\nwith-modifier   = \"with\" term \"as\" term\nsome-decl       = \"some\" term { \",\" term } { \"in\" expr }\nexpr            = term | expr-call | expr-infix | expr-every | expr-parens | unary-expr\nexpr-call       = var [ \".\" var ] \"(\" [ expr { \",\" expr } ] \")\"\nexpr-infix      = expr infix-operator expr\nexpr-every      = \"every\" var { \",\" var } \"in\" ( term | expr-call | expr-infix ) \"{\" query \"}\"\nexpr-parens     = \"(\" expr \")\"\nunary-expr      = \"-\" expr\nmembership      = term [ \",\" term ] \"in\" term\nterm            = ref | var | scalar | array | object | set | membership | array-compr | object-compr | set-compr\narray-compr     = \"[\" term \"|\" query \"]\"\nset-compr       = \"{\" term \"|\" query \"}\"\nobject-compr    = \"{\" object-item \"|\" query \"}\"\ninfix-operator  = assign-operator | bool-operator | arith-operator | bin-operator\nbool-operator   = \"==\" | \"!=\" | \"\u003c\" | \"\u003e\" | \"\u003e=\" | \"\u003c=\"\narith-operator  = \"+\" | \"-\" | \"*\" | \"/\" | \"%\"\nbin-operator    = \"\u0026\" | \"|\"\nassign-operator = \":=\" | \"=\"\nref             = ( var | array | object | set | array-compr | object-compr | set-compr | expr-call ) { ref-arg }\nref-arg         = ref-arg-dot | ref-arg-brack\nref-arg-brack   = \"[\" ( scalar | var | array | object | set | \"_\" ) \"]\"\nref-arg-dot     = \".\" var\nvar             = ( ALPHA | \"_\" ) { ALPHA | DIGIT | \"_\" }\nscalar          = string | NUMBER | TRUE | FALSE | NULL\nstring          = STRING | raw-string\nraw-string      = \"`\" { CHAR-\"`\" } \"`\"\narray           = \"[\" term { \",\" term } \"]\"\nobject          = \"{\" object-item { \",\" object-item } \"}\"\nobject-item     = ( scalar | ref | var ) \":\" term\nset             = empty-set | non-empty-set\nnon-empty-set   = \"{\" term { \",\" term } \"}\"\nempty-set       = \"set(\" \")\"\n```\n\nDefinitions:\n```\n[]     optional (zero or one instances)\n{}     repetition (zero or more instances)\n|      alternation (one of the instances)\n()     grouping (order of expansion)\nSTRING JSON string\nNUMBER JSON number\nTRUE   JSON true\nFALSE  JSON false\nNULL   JSON null\nCHAR   Unicode character\nALPHA  ASCII characters A-Z and a-z\nDIGIT  ASCII characters 0-9\nCR     Carriage Return\nLF     Line Feed\n```\n\n### Builtins\n\nWe support the majority of the standard Rego built-ins, and provide a robust\nmechanism for including custom built-ins (via the CPP API). The following builtins\nare NOT supported at present, though some are scheduled for future releases.\n\n- `providers.aws.sign_req` - Not planned\n- `crypto.*` - Currently slated to be released in v1.2.0\n- `glob.*` - Not planned\n- `graphql.*` - Not planned\n- `http.send` - Not planned\n- `json.match_schema`/`json.verify_schema` - Not planned\n- `jwt.*` - Currently slated to be released in v1.3.0\n- `net.*` - Not planned\n- `regex.globs_match` - Not planned\n- `rego.metadata.chain`/`rego.metadata.rule`/`rego.parse_module` - Not planned\n- `strings.render_template` - Not planned\n- `time` - This is entirely platform dependent at the moment, depending on whether\n           there is a compiler on that platform which supports `__cpp_lib_chrono \u003e= 201907L`.\n\n\n### Compatibility with the OPA Rego Go implementation\n\nOur goal is to achieve and maintain full compatibility with the reference Go\nimplementation. We have developed a test driver which runs the same tests\nand validates that we produce the same outputs. At this stage we pass all\nthe non-builtin specific test suites, which we clone from the\n[OPA repository](https://github.com/open-policy-agent/opa/tree/main/test/cases/testdata).\nTo build with the OPA tests available for testing, use one of the following presets:\n- `release-clang-opa`\n- `release-opa`\n\n## Contributing\n\nThis project welcomes contributions and suggestions.  Most contributions require you to agree to a\nContributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us\nthe rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.\n\nWhen you submit a pull request, a CLA bot will automatically determine whether you need to provide\na CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions\nprovided by the bot. You will only need to do this once across all repos using our CLA.\n\nThis project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).\nFor more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or\ncontact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.\n\n## Trademarks\n\nThis project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft \ntrademarks or logos is subject to and must follow \n[Microsoft's Trademark \u0026 Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).\nUse of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.\nAny use of third-party trademarks or logos are subject to those third-party's policies.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrosoft%2Frego-cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmicrosoft%2Frego-cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrosoft%2Frego-cpp/lists"}