Note: This project is a temporary solution for using the CEL language from cel-rs in C++. This library will be deprecated when using the Rust implementations from C++ becomes viable.
Compile decoded UTF-8 std::string_view expressions once, then execute the
owned programs on a reusable stack. This C++20 library supports a
bool/f64 subset of CEL and lets you add client types and
operations. JSON decoding belongs to your application.
Use CPM to build the parser and its runtime as static libraries with your application. After adding CPM to your project, declare the dependency and link your application target:
set(CPM_USE_LOCAL_PACKAGES OFF)
include(cmake/CPM.cmake)
CPMAddPackage("gh:stlab/[email protected]")
add_executable(client main.cpp)
target_link_libraries(client PRIVATE cel::parser)The build tutorial includes compiler prerequisites and configure/build commands. You do not need an installation, package prefix, or separate runtime checkout.
Include <cel/parser.hpp> to compile and execute a scalar:
#include <cel/parser.hpp>
#include <iostream>
int main() try {
cel::parser compiler(cel::op_lookup{});
auto program = compiler.parse_str("2.0 + 3.0").prepare<double>();
cel::raw_stack stack;
std::cout << program.call(stack) << '\n';
} catch (const std::exception& error) {
std::cerr << error.what() << '\n';
return 1;
}The program prints 5. Numeric values require floating syntax: 2.0, not 2.
Preparation binds the result type once; later calls reuse the program and stack.
Read these guides in order:
- Build and link the parser with CPM.
- Compile and reuse expressions.
- Add an extension library.
- Check the supported language.
The generated documentation places grouped APIs under Reference and
symbol lookup under Index. Build it with cmake --preset docs followed by
cmake --build --preset docs, then open build/docs/html/index.html.