parser 1.0.0
UTF-8 CEL expression compilation and checked library extensions
Loading...
Searching...
No Matches
cel::op_lookup Class Reference

Owns exact registrations, nominal schemas, and LIFO scope callbacks. Owns copied names, retained descriptors, and stored callbacks, not references inside captures. register_op retains its runtime callback in emitted code after this lookup dies. Custom scope callbacks and operation emitters must retain state in the code they emit. Client-captured references must outlive every execution that uses them. Mutable callbacks are not made thread-safe by registry ownership. Registration matches complete compatible input descriptors, including nominal identity and ownership representation; equal layouts or display names do not establish a match. Copies are unavailable; moves transfer registry ownership. Register a receiver operation before transferring the lookup into a parser: More...

#include <cel/parser/lookup.hpp>

Public Member Functions

std::optional< value_type > find_type (std::string_view name) const
 Returns a retained descriptor for extension signatures, or nullopt for an unknown name. Complexity: O(name bytes), expected hash lookup. Example: auto point = lookup.find_type("Point").
 op_lookup ()
 Creates only core operators, casts, and the persistent full-range constructor. Standard-library functions are separate client registrations. Complexity: O(retained signature count) metadata and callback storage.
 op_lookup (const op_lookup &)=delete
 Disallows copying this registry.
op_lookup & operator= (const op_lookup &)=delete
 Disallows copy assignment of this registry.
 op_lookup (op_lookup &&) noexcept=default
 Transfers owned registration and scope state.
op_lookup & operator= (op_lookup &&) noexcept=default
 Transfers state and releases old registrations. Complexity: O(old owned state).
template<class T>
void register_type (std::string_view name)
 Registers an opaque trivially-copyable leaf under an owned nonempty name. Throws std::invalid_argument for empty/duplicate/reserved names or a structural adapter. Complexity: O(name bytes), expected map insertion. Example: lookup.register_type<my_trivial_type>("Point").
void register_record (std::string_view name, std::span< const record_field > fields)
 Registers an owned complete nominal record schema, never a guessed native layout. Throws invalid_argument for empty/duplicate/reserved names or invalid field names. Complexity: O(fields + field-name bytes + name bytes), expected map insertion. Example: lookup.register_record("Flag", std::array{record_field{"on", value_type::leaf<bool>()}}).
void register_operation (std::string_view name, std::span< const value_type > inputs, value_type result, operation_emitter emit)
 Registers one exact complete operation; a return type never distinguishes overloads. Copies the name and input descriptors and owns result and emit. emit follows operation_emitter's ownership and emission contract. Throws std::invalid_argument for empty names, absent emitters, or duplicate inputs. Compilation checks the emitted stack depth and result compatibility after selection. Complexity: O(overloads * arity * distinct compared plans + name bytes). Example: lookup.register_operation("first", inputs, result, [](dyn_segment& b, source_span) { b.project_tuple(0); }).
void register_structural_op (std::string_view name, std::span< const value_type > inputs, value_type result, operation_emitter emit)
 Registers a lower-priority structural signature with complete recursive identities. Persistent operations precede this tier; core built-ins follow it. Follows register_operation's error, emitter, and complexity contract. Example: lookup.register_structural_op("first", inputs, result, project).
template<class R, class... A, class F>
requires (!std::is_void_v<R> && requires(dyn_segment & b, F&& callback) { b.template op<R, A...>(std::forward<F>(callback)); })
void register_op (std::string_view name, F &&callback)
 Registers an owned const-invocable callback with exactly the declared result type. Arguments must satisfy the runtime's declared A... invocation constraints. Concrete vectors/tuples use trusted public adapters; opaque leaves are trivially copyable. Use std::tuple<> for source unit; void is not a source value. Throws std::invalid_argument for an empty name or duplicate operands, even if R differs. Callback references stay client-owned; emitted code retains the stored callback. Lvalue callbacks are copied; rvalue callbacks are moved into owned decayed storage. Complexity: O(overloads * arity * distinct compared plans + name/capture storage + first-use complete structural descriptor construction). Example: lookup.register_op<double, double>("negate", [](double x) { return -x; }).
template<class M>
void register_function (std::string_view name, M &&marker)
 Binds an ordinary name to its first owned trivially-copyable marker. Repeated installers may use another marker for the same name; the first remains selected. Throws std::invalid_argument for an empty name, a structural marker, or a marker type already bound to a distinct function. Register matching register_op overloads separately; a marker alone supplies no operation. Failure leaves existing bindings and marker reservations unchanged. Complexity: O(name bytes + marker size), expected hash insertion. Example: lookup.register_function("convert", my_marker{}).
void push_library_scope (scope_callback callback)
 Owns a persistent LIFO library scope visible in independent closure bodies. Precondition: no transient scopes are active. Precondition: callback follows scope_callback's emission and capture-lifetime contract. Throws invalid_argument for an empty callback. Complexity: amortized O(1), plus callback ownership. Example: lookup.push_library_scope(library_callback).

Friends

struct parser_detail::lookup_access

Detailed Description

Owns exact registrations, nominal schemas, and LIFO scope callbacks. Owns copied names, retained descriptors, and stored callbacks, not references inside captures. register_op retains its runtime callback in emitted code after this lookup dies. Custom scope callbacks and operation emitters must retain state in the code they emit. Client-captured references must outlive every execution that uses them. Mutable callbacks are not made thread-safe by registry ownership. Registration matches complete compatible input descriptors, including nominal identity and ownership representation; equal layouts or display names do not establish a match. Copies are unavailable; moves transfer registry ownership. Register a receiver operation before transferring the lookup into a parser:

#include <cel/parser.hpp>
lookup.register_op<double, double>("twice", [](double x) { return x * 2; });
cel::parser compiler(std::move(lookup));
auto code = compiler.parse_str("3.0.twice()");
Owns exact registrations, nominal schemas, and LIFO scope callbacks. Owns copied names,...
Definition lookup.hpp:81
void register_op(std::string_view name, F &&callback)
Registers an owned const-invocable callback with exactly the declared result type....
Definition lookup.hpp:277
Owns lookup state and compiles CEL expressions into reusable checked programs. Each successful call r...
Definition compiler.hpp:37
Provides UTF-8 expression compilation, checked library extensions, and source diagnostics.

The documentation for this class was generated from the following file: