1use crate::absl::{Status, StringView, MutSpan};
2use crate::common::{Expr, ListExprElement, StructExprField, MapExprEntry};
3use std::pin::Pin;
4
5#[cxx::bridge]
6mod ffi {
7 #[namespace = "absl"]
8 unsafe extern "C++" {
9 include!(<absl/status/status.h>);
10 type Status = super::Status;
11
12 include!(<absl/strings/string_view.h>);
13 type string_view<'a> = super::StringView<'a>;
14 }
15
16 #[namespace = "cel"]
17 unsafe extern "C++" {
18 include!(<parser/parser.h>);
19 type GlobalMacroExpander;
20 type ReceiverMacroExpander;
21
22 type Macro;
23 fn function<'a>(self: &Macro) -> string_view<'a>;
24 fn argument_count(self: &Macro) -> usize;
25 fn is_receiver_style(self: &Macro) -> bool;
26 fn is_variadic(self: &Macro) -> bool;
27 fn key<'a>(self: &Macro) -> string_view<'a>;
28
29 type MacroExprFactory;
30 #[rust_name = "accu_var_name"]
31 fn AccuVarName<'a>(self: Pin<&'a mut MacroExprFactory>) -> string_view<'a>;
32
33 type ParserOptions;
34 type ParserBuilderConfigurer;
35 type ParserBuilder;
36 #[rust_name = "add_macro"]
37 fn AddMacro(self: Pin<&mut ParserBuilder>, m: &Macro) -> Status;
38
39 type Parser;
40 type ParserLibrary;
41 type ParserLibrarySubset;
42 }
43
44 #[namespace = "cel"]
45 unsafe extern "C++" {
46 include!(<common/expr.h>);
47 type Expr = super::Expr;
48 type ListExprElement = super::ListExprElement;
49 type StructExprField = super::StructExprField;
50 type MapExprEntry = super::MapExprEntry;
51 }
52
53 #[namespace = "rust::cel_cxx"]
54 unsafe extern "C++" {
55 include!(<cel-cxx-ffi/include/absl.h>);
56 include!(<cel-cxx-ffi/include/parser.h>);
57
58 type MacroPredicate;
59
60 type MutSpan_Expr<'a> = super::MutSpan<'a, Expr>;
61 type MutSpan_ListExprElement<'a> = super::MutSpan<'a, ListExprElement>;
62 type MutSpan_StructExprField<'a> = super::MutSpan<'a, StructExprField>;
63 type MutSpan_MapExprEntry<'a> = super::MutSpan<'a, MapExprEntry>;
64
65 fn GlobalMacroExpander_new(ffi_expander: Box<AnyFfiGlobalMacroExpander>) -> UniquePtr<GlobalMacroExpander>;
67
68 fn ReceiverMacroExpander_new(ffi_expander: Box<AnyFfiReceiverMacroExpander>) -> UniquePtr<ReceiverMacroExpander>;
70
71 fn Macro_new_global<'a, 'f>(
73 name: string_view<'a>,
74 argument_count: usize,
75 expander: UniquePtr<GlobalMacroExpander>,
76 result: &mut UniquePtr<Macro>,
77 ) -> Status;
78
79 fn Macro_new_global_var_arg<'a, 'f>(
80 name: string_view<'a>,
81 expander: UniquePtr<GlobalMacroExpander>,
82 result: &mut UniquePtr<Macro>,
83 ) -> Status;
84
85 fn Macro_new_receiver<'a, 'f>(
86 name: string_view<'a>,
87 argument_count: usize,
88 expander: UniquePtr<ReceiverMacroExpander>,
89 result: &mut UniquePtr<Macro>,
90 ) -> Status;
91
92 fn Macro_new_receiver_var_arg<'a, 'f>(
93 name: string_view<'a>,
94 expander: UniquePtr<ReceiverMacroExpander>,
95 result: &mut UniquePtr<Macro>,
96 ) -> Status;
97
98 fn MacroExprFactory_copy(
100 factory: Pin<&mut MacroExprFactory>,
101 expr: &Expr,
102 ) -> UniquePtr<Expr>;
103 fn MacroExprFactory_copy_list_element(
104 factory: Pin<&mut MacroExprFactory>,
105 list_element: &ListExprElement,
106 ) -> UniquePtr<ListExprElement>;
107 fn MacroExprFactory_copy_struct_field(
108 factory: Pin<&mut MacroExprFactory>,
109 struct_field: &StructExprField,
110 ) -> UniquePtr<StructExprField>;
111 fn MacroExprFactory_copy_map_entry(
112 factory: Pin<&mut MacroExprFactory>,
113 map_entry: &MapExprEntry,
114 ) -> UniquePtr<MapExprEntry>;
115 fn MacroExprFactory_new_unspecified(
116 factory: Pin<&mut MacroExprFactory>,
117 ) -> UniquePtr<Expr>;
118 fn MacroExprFactory_new_null_const(
119 factory: Pin<&mut MacroExprFactory>,
120 ) -> UniquePtr<Expr>;
121 fn MacroExprFactory_new_bool_const(
122 factory: Pin<&mut MacroExprFactory>,
123 value: bool,
124 ) -> UniquePtr<Expr>;
125 fn MacroExprFactory_new_int_const(
126 factory: Pin<&mut MacroExprFactory>,
127 value: i64,
128 ) -> UniquePtr<Expr>;
129 fn MacroExprFactory_new_double_const(
130 factory: Pin<&mut MacroExprFactory>,
131 value: f64,
132 ) -> UniquePtr<Expr>;
133 fn MacroExprFactory_new_bytes_const<'a>(
134 factory: Pin<&mut MacroExprFactory>,
135 value: string_view<'a>,
136 ) -> UniquePtr<Expr>;
137 fn MacroExprFactory_new_string_const<'a>(
138 factory: Pin<&mut MacroExprFactory>,
139 value: string_view<'a>,
140 ) -> UniquePtr<Expr>;
141 fn MacroExprFactory_new_ident<'a>(
142 factory: Pin<&mut MacroExprFactory>,
143 name: string_view<'a>,
144 ) -> UniquePtr<Expr>;
145 fn MacroExprFactory_new_accu_ident(
146 factory: Pin<&mut MacroExprFactory>,
147 ) -> UniquePtr<Expr>;
148 fn MacroExprFactory_new_select<'a>(
149 factory: Pin<&mut MacroExprFactory>,
150 operand: UniquePtr<Expr>,
151 field: string_view<'a>,
152 ) -> UniquePtr<Expr>;
153 fn MacroExprFactory_new_presence_test<'a>(
154 factory: Pin<&mut MacroExprFactory>,
155 operand: UniquePtr<Expr>,
156 field: string_view<'a>,
157 ) -> UniquePtr<Expr>;
158 fn MacroExprFactory_new_call<'a>(
159 factory: Pin<&mut MacroExprFactory>,
160 function: string_view<'a>,
161 args: UniquePtr<CxxVector<Expr>>,
162 ) -> UniquePtr<Expr>;
163 fn MacroExprFactory_new_member_call<'a>(
164 factory: Pin<&mut MacroExprFactory>,
165 function: string_view<'a>,
166 target: UniquePtr<Expr>,
167 args: UniquePtr<CxxVector<Expr>>,
168 ) -> UniquePtr<Expr>;
169 fn MacroExprFactory_new_list_element(
170 factory: Pin<&mut MacroExprFactory>,
171 expr: UniquePtr<Expr>,
172 optional: bool,
173 ) -> UniquePtr<ListExprElement>;
174 fn MacroExprFactory_new_list(
175 factory: Pin<&mut MacroExprFactory>,
176 elements: UniquePtr<CxxVector<ListExprElement>>,
177 ) -> UniquePtr<Expr>;
178 fn MacroExprFactory_new_struct_field<'a>(
179 factory: Pin<&mut MacroExprFactory>,
180 name: string_view<'a>,
181 value: UniquePtr<Expr>,
182 optional: bool,
183 ) -> UniquePtr<StructExprField>;
184 fn MacroExprFactory_new_struct<'a>(
185 factory: Pin<&mut MacroExprFactory>,
186 name: string_view<'a>,
187 fields: UniquePtr<CxxVector<StructExprField>>,
188 ) -> UniquePtr<Expr>;
189 fn MacroExprFactory_new_map_entry(
190 factory: Pin<&mut MacroExprFactory>,
191 key: UniquePtr<Expr>,
192 value: UniquePtr<Expr>,
193 optional: bool,
194 ) -> UniquePtr<MapExprEntry>;
195 fn MacroExprFactory_new_map(
196 factory: Pin<&mut MacroExprFactory>,
197 entries: UniquePtr<CxxVector<MapExprEntry>>,
198 ) -> UniquePtr<Expr>;
199 fn MacroExprFactory_new_comprehension<'a>(
200 factory: Pin<&mut MacroExprFactory>,
201 iter_var: string_view<'a>,
202 iter_range: UniquePtr<Expr>,
203 accu_var: string_view<'a>,
204 accu_init: UniquePtr<Expr>,
205 loop_condition: UniquePtr<Expr>,
206 loop_step: UniquePtr<Expr>,
207 result: UniquePtr<Expr>,
208 ) -> UniquePtr<Expr>;
209 fn MacroExprFactory_new_comprehension2<'a>(
210 factory: Pin<&mut MacroExprFactory>,
211 iter_var: string_view<'a>,
212 iter_var2: string_view<'a>,
213 iter_range: UniquePtr<Expr>,
214 accu_var: string_view<'a>,
215 accu_init: UniquePtr<Expr>,
216 loop_condition: UniquePtr<Expr>,
217 loop_step: UniquePtr<Expr>,
218 result: UniquePtr<Expr>,
219 ) -> UniquePtr<Expr>;
220 fn MacroExprFactory_report_error<'a>(
221 factory: Pin<&mut MacroExprFactory>,
222 message: string_view<'a>,
223 ) -> UniquePtr<Expr>;
224 fn MacroExprFactory_report_error_at<'a>(
225 factory: Pin<&mut MacroExprFactory>,
226 expr: &Expr,
227 message: string_view<'a>,
228 ) -> UniquePtr<Expr>;
229
230 fn ParserOptions_new() -> UniquePtr<ParserOptions>;
232
233 fn ParserOptions_error_recovery_limit(parser_options: &ParserOptions) -> i32;
235 fn ParserOptions_error_recovery_limit_mut(
236 parser_options: Pin<&mut ParserOptions>,
237 ) -> &mut i32;
238 fn ParserOptions_max_recursion_depth(parser_options: &ParserOptions) -> i32;
239 fn ParserOptions_max_recursion_depth_mut(
240 parser_options: Pin<&mut ParserOptions>,
241 ) -> &mut i32;
242 fn ParserOptions_expression_size_codepoint_limit(parser_options: &ParserOptions) -> i32;
243 fn ParserOptions_expression_size_codepoint_limit_mut(
244 parser_options: Pin<&mut ParserOptions>,
245 ) -> &mut i32;
246 fn ParserOptions_error_recovery_token_lookahead_limit(
247 parser_options: &ParserOptions,
248 ) -> i32;
249 fn ParserOptions_error_recovery_token_lookahead_limit_mut(
250 parser_options: Pin<&mut ParserOptions>,
251 ) -> &mut i32;
252 fn ParserOptions_add_macro_calls(parser_options: &ParserOptions) -> bool;
253 fn ParserOptions_add_macro_calls_mut(parser_options: Pin<&mut ParserOptions>) -> &mut bool;
254 fn ParserOptions_enable_optional_syntax(parser_options: &ParserOptions) -> bool;
255 fn ParserOptions_enable_optional_syntax_mut(
256 parser_options: Pin<&mut ParserOptions>,
257 ) -> &mut bool;
258 fn ParserOptions_disable_standard_macros(parser_options: &ParserOptions) -> bool;
259 fn ParserOptions_disable_standard_macros_mut(
260 parser_options: Pin<&mut ParserOptions>,
261 ) -> &mut bool;
262 fn ParserOptions_enable_hidden_accumulator_var(parser_options: &ParserOptions) -> bool;
263 fn ParserOptions_enable_hidden_accumulator_var_mut(
264 parser_options: Pin<&mut ParserOptions>,
265 ) -> &mut bool;
266 fn ParserOptions_enable_quoted_identifiers(parser_options: &ParserOptions) -> bool;
267 fn ParserOptions_enable_quoted_identifiers_mut(
268 parser_options: Pin<&mut ParserOptions>,
269 ) -> &mut bool;
270
271 fn ParserBuilderConfigurer_new(ffi_configurer: Box<AnyFfiParserBuilderConfigurer>) -> UniquePtr<ParserBuilderConfigurer>;
273
274 fn ParserLibrary_new(id: &CxxString, configurer: UniquePtr<ParserBuilderConfigurer>) -> UniquePtr<ParserLibrary>;
276 fn ParserLibrary_id<'a>(parser_library: &'a ParserLibrary) -> &'a CxxString;
277
278 fn MacroPredicate_new(ffi_predicate: Box<AnyFfiMacroPredicate>) -> UniquePtr<MacroPredicate>;
280
281 fn ParserLibrarySubset_new(library_id: &CxxString, should_include_macro: UniquePtr<MacroPredicate>) -> UniquePtr<ParserLibrarySubset>;
283 fn ParserLibrarySubset_library_id<'a>(parser_library_subset: &'a ParserLibrarySubset) -> &'a CxxString;
284
285 fn ParserBuilder_add_library(
287 parser_builder: Pin<&mut ParserBuilder>,
288 library: UniquePtr<ParserLibrary>,
289 ) -> Status;
290 fn ParserBuilder_add_library_subset(
291 parser_builder: Pin<&mut ParserBuilder>,
292 library_subset: UniquePtr<ParserLibrarySubset>,
293 ) -> Status;
294 }
295
296 #[namespace = "rust::cel_cxx"]
297 extern "Rust" {
298 #[derive(ExternType)]
299 type AnyFfiParserBuilderConfigurer<'f>;
300 #[cxx_name = "Call"]
301 unsafe fn call<'f>(
302 self: &AnyFfiParserBuilderConfigurer<'f>,
303 parser_builder: Pin<&mut ParserBuilder>,
304 ) -> Status;
305
306 #[derive(ExternType)]
307 type AnyFfiMacroPredicate<'f>;
308 #[cxx_name = "Call"]
309 unsafe fn call<'f>(
310 self: &AnyFfiMacroPredicate<'f>,
311 m: &Macro,
312 ) -> bool;
313
314 type AnyFfiGlobalMacroExpander<'f>;
315 #[cxx_name = "Call"]
316 unsafe fn call<'f>(
317 self: &AnyFfiGlobalMacroExpander<'f>,
318 factory: Pin<&mut MacroExprFactory>,
319 args: &mut [UniquePtr<Expr>],
320 ) -> UniquePtr<Expr>;
321
322 type AnyFfiReceiverMacroExpander<'f>;
323 #[cxx_name = "Call"]
324 unsafe fn call<'f>(
325 self: &AnyFfiReceiverMacroExpander<'f>,
326 factory: Pin<&mut MacroExprFactory>,
327 target: UniquePtr<Expr>,
328 args: &mut [UniquePtr<Expr>],
329 ) -> UniquePtr<Expr>;
330 }
331
332}
333
334pub use ffi::GlobalMacroExpander;
336unsafe impl Send for GlobalMacroExpander {}
337unsafe impl Sync for GlobalMacroExpander {}
338
339impl GlobalMacroExpander {
340 pub fn new<F: FfiGlobalMacroExpander + 'static>(expander: F) -> cxx::UniquePtr<Self> {
341 ffi::GlobalMacroExpander_new(Box::new(AnyFfiGlobalMacroExpander::new(expander)))
342 }
343}
344
345pub trait FfiGlobalMacroExpander
346 : Fn(Pin<&mut MacroExprFactory>, &mut [cxx::UniquePtr<Expr>]) -> cxx::UniquePtr<Expr>
347{}
348
349impl<'f, F> FfiGlobalMacroExpander for F where F
350 : Fn(Pin<&mut MacroExprFactory>, &mut [cxx::UniquePtr<Expr>]) -> cxx::UniquePtr<Expr>
351 + 'f
352{}
353
354struct AnyFfiGlobalMacroExpander<'f>(Box<dyn FfiGlobalMacroExpander + 'f>);
355impl<'f> AnyFfiGlobalMacroExpander<'f> {
356 fn new<T: FfiGlobalMacroExpander + 'f>(expander: T) -> Self {
357 Self(Box::new(expander))
358 }
359
360 fn call(&self, factory: Pin<&mut MacroExprFactory>, args: &mut [cxx::UniquePtr<Expr>]) -> cxx::UniquePtr<Expr> {
361 (self.0)(factory, args)
362 }
363}
364
365pub use ffi::ReceiverMacroExpander;
367unsafe impl Send for ReceiverMacroExpander {}
368unsafe impl Sync for ReceiverMacroExpander {}
369
370impl ReceiverMacroExpander {
371 pub fn new<F: FfiReceiverMacroExpander + 'static>(expander: F) -> cxx::UniquePtr<Self> {
372 ffi::ReceiverMacroExpander_new(Box::new(AnyFfiReceiverMacroExpander::new(expander)))
373 }
374}
375
376pub trait FfiReceiverMacroExpander
377 : Fn(Pin<&mut MacroExprFactory>, cxx::UniquePtr<Expr>, &mut [cxx::UniquePtr<Expr>]) -> cxx::UniquePtr<Expr>
378{}
379
380impl<'f, F> FfiReceiverMacroExpander for F where F
381 : Fn(Pin<&mut MacroExprFactory>, cxx::UniquePtr<Expr>, &mut [cxx::UniquePtr<Expr>]) -> cxx::UniquePtr<Expr>
382 + 'f
383{}
384
385struct AnyFfiReceiverMacroExpander<'f>(Box<dyn FfiReceiverMacroExpander + 'f>);
386impl<'f> AnyFfiReceiverMacroExpander<'f> {
387 fn new<T: FfiReceiverMacroExpander + 'f>(expander: T) -> Self {
388 Self(Box::new(expander))
389 }
390
391 fn call(&self, factory: Pin<&mut MacroExprFactory>, target: cxx::UniquePtr<Expr>, args: &mut [cxx::UniquePtr<Expr>]) -> cxx::UniquePtr<Expr> {
392 (self.0)(factory, target, args)
393 }
394}
395
396pub use ffi::Macro;
398unsafe impl Send for Macro {}
399unsafe impl Sync for Macro {}
400
401impl Macro {
402 pub fn new_global(
403 name: StringView<'_>,
404 argument_count: usize,
405 expander: cxx::UniquePtr<GlobalMacroExpander>,
406 ) -> Result<cxx::UniquePtr<Self>, Status> {
407 let mut result = cxx::UniquePtr::null();
408 let status = ffi::Macro_new_global(name, argument_count, expander, &mut result);
409 if status.is_ok() {
410 Ok(result)
411 } else {
412 Err(status)
413 }
414 }
415
416 pub fn new_global_var_arg(
417 name: StringView<'_>,
418 expander: cxx::UniquePtr<GlobalMacroExpander>,
419 ) -> Result<cxx::UniquePtr<Self>, Status> {
420 let mut result = cxx::UniquePtr::null();
421 let status = ffi::Macro_new_global_var_arg(name, expander, &mut result);
422 if status.is_ok() {
423 Ok(result)
424 } else {
425 Err(status)
426 }
427 }
428
429 pub fn new_receiver(
430 name: StringView<'_>,
431 argument_count: usize,
432 expander: cxx::UniquePtr<ReceiverMacroExpander>,
433 ) -> Result<cxx::UniquePtr<Self>, Status> {
434 let mut result = cxx::UniquePtr::null();
435 let status = ffi::Macro_new_receiver(name, argument_count, expander, &mut result);
436 if status.is_ok() {
437 Ok(result)
438 } else {
439 Err(status)
440 }
441 }
442
443 pub fn new_receiver_var_arg(
444 name: StringView<'_>,
445 expander: cxx::UniquePtr<ReceiverMacroExpander>,
446 ) -> Result<cxx::UniquePtr<Self>, Status> {
447 let mut result = cxx::UniquePtr::null();
448 let status = ffi::Macro_new_receiver_var_arg(name, expander, &mut result);
449 if status.is_ok() {
450 Ok(result)
451 } else {
452 Err(status)
453 }
454 }
455}
456
457pub use ffi::MacroExprFactory;
459unsafe impl Send for MacroExprFactory {}
460unsafe impl Sync for MacroExprFactory {}
461
462impl MacroExprFactory {
463 pub fn copy(self: Pin<&mut Self>, expr: &Expr) -> cxx::UniquePtr<Expr> {
464 ffi::MacroExprFactory_copy(self, expr)
465 }
466
467 pub fn copy_list_element(self: Pin<&mut Self>, list_element: &ListExprElement) -> cxx::UniquePtr<ListExprElement> {
468 ffi::MacroExprFactory_copy_list_element(self, list_element)
469 }
470
471 pub fn copy_struct_field(self: Pin<&mut Self>, struct_field: &StructExprField) -> cxx::UniquePtr<StructExprField> {
472 ffi::MacroExprFactory_copy_struct_field(self, struct_field)
473 }
474
475 pub fn copy_map_entry(self: Pin<&mut Self>, map_entry: &MapExprEntry) -> cxx::UniquePtr<MapExprEntry> {
476 ffi::MacroExprFactory_copy_map_entry(self, map_entry)
477 }
478
479 pub fn new_unspecified(self: Pin<&mut Self>) -> cxx::UniquePtr<Expr> {
480 ffi::MacroExprFactory_new_unspecified(self)
481 }
482
483 pub fn new_null_const(self: Pin<&mut Self>) -> cxx::UniquePtr<Expr> {
484 ffi::MacroExprFactory_new_null_const(self)
485 }
486
487 pub fn new_bool_const(self: Pin<&mut Self>, value: bool) -> cxx::UniquePtr<Expr> {
488 ffi::MacroExprFactory_new_bool_const(self, value)
489 }
490
491 pub fn new_int_const(self: Pin<&mut Self>, value: i64) -> cxx::UniquePtr<Expr> {
492 ffi::MacroExprFactory_new_int_const(self, value)
493 }
494
495 pub fn new_double_const(self: Pin<&mut Self>, value: f64) -> cxx::UniquePtr<Expr> {
496 ffi::MacroExprFactory_new_double_const(self, value)
497 }
498
499 pub fn new_bytes_const(self: Pin<&mut Self>, value: StringView<'_>) -> cxx::UniquePtr<Expr> {
500 ffi::MacroExprFactory_new_bytes_const(self, value)
501 }
502
503 pub fn new_string_const(self: Pin<&mut Self>, value: StringView<'_>) -> cxx::UniquePtr<Expr> {
504 ffi::MacroExprFactory_new_string_const(self, value)
505 }
506
507 pub fn new_ident(self: Pin<&mut Self>, name: StringView<'_>) -> cxx::UniquePtr<Expr> {
508 ffi::MacroExprFactory_new_ident(self, name)
509 }
510
511 pub fn new_accu_ident(self: Pin<&mut Self>) -> cxx::UniquePtr<Expr> {
512 ffi::MacroExprFactory_new_accu_ident(self)
513 }
514
515 pub fn new_select(self: Pin<&mut Self>, operand: cxx::UniquePtr<Expr>, field: StringView<'_>) -> cxx::UniquePtr<Expr> {
516 ffi::MacroExprFactory_new_select(self, operand, field)
517 }
518
519 pub fn new_presence_test(self: Pin<&mut Self>, operand: cxx::UniquePtr<Expr>, field: StringView<'_>) -> cxx::UniquePtr<Expr> {
520 ffi::MacroExprFactory_new_presence_test(self, operand, field)
521 }
522
523 pub fn new_call(self: Pin<&mut Self>, function: StringView<'_>, args: cxx::UniquePtr<cxx::CxxVector<Expr>>) -> cxx::UniquePtr<Expr> {
524 ffi::MacroExprFactory_new_call(self, function, args)
525 }
526
527 pub fn new_member_call(self: Pin<&mut Self>, function: StringView<'_>, target: cxx::UniquePtr<Expr>, args: cxx::UniquePtr<cxx::CxxVector<Expr>>) -> cxx::UniquePtr<Expr> {
528 ffi::MacroExprFactory_new_member_call(self, function, target, args)
529 }
530
531 pub fn new_list_element(self: Pin<&mut Self>, expr: cxx::UniquePtr<Expr>, optional: bool) -> cxx::UniquePtr<ListExprElement> {
532 ffi::MacroExprFactory_new_list_element(self, expr, optional)
533 }
534
535 pub fn new_list(self: Pin<&mut Self>, elements: cxx::UniquePtr<cxx::CxxVector<ListExprElement>>) -> cxx::UniquePtr<Expr> {
536 ffi::MacroExprFactory_new_list(self, elements)
537 }
538
539 pub fn new_struct_field(self: Pin<&mut Self>, name: StringView<'_>, value: cxx::UniquePtr<Expr>, optional: bool) -> cxx::UniquePtr<StructExprField> {
540 ffi::MacroExprFactory_new_struct_field(self, name, value, optional)
541 }
542
543 pub fn new_struct(self: Pin<&mut Self>, name: StringView<'_>, fields: cxx::UniquePtr<cxx::CxxVector<StructExprField>>) -> cxx::UniquePtr<Expr> {
544 ffi::MacroExprFactory_new_struct(self, name, fields)
545 }
546
547 pub fn new_map_entry(self: Pin<&mut Self>, key: cxx::UniquePtr<Expr>, value: cxx::UniquePtr<Expr>, optional: bool) -> cxx::UniquePtr<MapExprEntry> {
548 ffi::MacroExprFactory_new_map_entry(self, key, value, optional)
549 }
550
551 pub fn new_map(self: Pin<&mut Self>, entries: cxx::UniquePtr<cxx::CxxVector<MapExprEntry>>) -> cxx::UniquePtr<Expr> {
552 ffi::MacroExprFactory_new_map(self, entries)
553 }
554
555 pub fn new_comprehension(
556 self: Pin<&mut Self>,
557 iter_var: StringView<'_>,
558 iter_range: cxx::UniquePtr<Expr>,
559 accu_var: StringView<'_>,
560 accu_init: cxx::UniquePtr<Expr>,
561 loop_condition: cxx::UniquePtr<Expr>,
562 loop_step: cxx::UniquePtr<Expr>,
563 result: cxx::UniquePtr<Expr>,
564 ) -> cxx::UniquePtr<Expr> {
565 ffi::MacroExprFactory_new_comprehension(
566 self,
567 iter_var,
568 iter_range,
569 accu_var,
570 accu_init,
571 loop_condition,
572 loop_step,
573 result,
574 )
575 }
576
577 pub fn new_comprehension2(
578 self: Pin<&mut Self>,
579 iter_var: StringView<'_>,
580 iter_var2: StringView<'_>,
581 iter_range: cxx::UniquePtr<Expr>,
582 accu_var: StringView<'_>,
583 accu_init: cxx::UniquePtr<Expr>,
584 loop_condition: cxx::UniquePtr<Expr>,
585 loop_step: cxx::UniquePtr<Expr>,
586 result: cxx::UniquePtr<Expr>,
587 ) -> cxx::UniquePtr<Expr> {
588 ffi::MacroExprFactory_new_comprehension2(
589 self,
590 iter_var,
591 iter_var2,
592 iter_range,
593 accu_var,
594 accu_init,
595 loop_condition,
596 loop_step,
597 result,
598 )
599 }
600
601 pub fn report_error(self: Pin<&mut Self>, message: StringView<'_>) -> cxx::UniquePtr<Expr> {
602 ffi::MacroExprFactory_report_error(self, message)
603 }
604
605 pub fn report_error_at(self: Pin<&mut Self>, expr: &Expr, message: StringView<'_>) -> cxx::UniquePtr<Expr> {
606 ffi::MacroExprFactory_report_error_at(self, expr, message)
607 }
608}
609
610pub use ffi::ParserOptions;
611unsafe impl Send for ParserOptions {}
612unsafe impl Sync for ParserOptions {}
613
614impl ParserOptions {
615 pub fn new() -> cxx::UniquePtr<Self> {
616 ffi::ParserOptions_new()
617 }
618
619 pub fn error_recovery_limit(&self) -> i32 {
620 ffi::ParserOptions_error_recovery_limit(self)
621 }
622
623 pub fn error_recovery_limit_mut<'a>(self: Pin<&'a mut Self>) -> &'a mut i32 {
624 ffi::ParserOptions_error_recovery_limit_mut(self)
625 }
626
627 pub fn max_recursion_depth(&self) -> i32 {
628 ffi::ParserOptions_max_recursion_depth(self)
629 }
630
631 pub fn max_recursion_depth_mut<'a>(self: Pin<&'a mut Self>) -> &'a mut i32 {
632 ffi::ParserOptions_max_recursion_depth_mut(self)
633 }
634
635 pub fn expression_size_codepoint_limit(&self) -> i32 {
636 ffi::ParserOptions_expression_size_codepoint_limit(self)
637 }
638
639 pub fn expression_size_codepoint_limit_mut<'a>(self: Pin<&'a mut Self>) -> &'a mut i32 {
640 ffi::ParserOptions_expression_size_codepoint_limit_mut(self)
641 }
642
643 pub fn error_recovery_token_lookahead_limit(&self) -> i32 {
644 ffi::ParserOptions_error_recovery_token_lookahead_limit(self)
645 }
646
647 pub fn error_recovery_token_lookahead_limit_mut<'a>(self: Pin<&'a mut Self>) -> &'a mut i32 {
648 ffi::ParserOptions_error_recovery_token_lookahead_limit_mut(self)
649 }
650
651 pub fn add_macro_calls(&self) -> bool {
652 ffi::ParserOptions_add_macro_calls(self)
653 }
654
655 pub fn add_macro_calls_mut<'a>(self: Pin<&'a mut Self>) -> &'a mut bool {
656 ffi::ParserOptions_add_macro_calls_mut(self)
657 }
658
659 pub fn enable_optional_syntax(&self) -> bool {
660 ffi::ParserOptions_enable_optional_syntax(self)
661 }
662
663 pub fn enable_optional_syntax_mut<'a>(self: Pin<&'a mut Self>) -> &'a mut bool {
664 ffi::ParserOptions_enable_optional_syntax_mut(self)
665 }
666
667 pub fn disable_standard_macros(&self) -> bool {
668 ffi::ParserOptions_disable_standard_macros(self)
669 }
670
671 pub fn disable_standard_macros_mut<'a>(self: Pin<&'a mut Self>) -> &'a mut bool {
672 ffi::ParserOptions_disable_standard_macros_mut(self)
673 }
674
675 pub fn enable_hidden_accumulator_var(&self) -> bool {
676 ffi::ParserOptions_enable_hidden_accumulator_var(self)
677 }
678
679 pub fn enable_hidden_accumulator_var_mut<'a>(self: Pin<&'a mut Self>) -> &'a mut bool {
680 ffi::ParserOptions_enable_hidden_accumulator_var_mut(self)
681 }
682
683 pub fn enable_quoted_identifiers(&self) -> bool {
684 ffi::ParserOptions_enable_quoted_identifiers(self)
685 }
686
687 pub fn enable_quoted_identifiers_mut<'a>(self: Pin<&'a mut Self>) -> &'a mut bool {
688 ffi::ParserOptions_enable_quoted_identifiers_mut(self)
689 }
690}
691
692pub use ffi::ParserBuilderConfigurer;
694unsafe impl Send for ParserBuilderConfigurer {}
695unsafe impl Sync for ParserBuilderConfigurer {}
696
697impl ParserBuilderConfigurer {
698 pub fn new<F: FfiParserBuilderConfigurer + 'static>(configurer: F) -> cxx::UniquePtr<Self> {
699 ffi::ParserBuilderConfigurer_new(Box::new(AnyFfiParserBuilderConfigurer::new(configurer)))
700 }
701}
702
703pub trait FfiParserBuilderConfigurer: Fn(Pin<&mut ParserBuilder>) -> Status {}
704impl<'f, F> FfiParserBuilderConfigurer for F where
705 F: 'f + Fn(Pin<&mut ParserBuilder>) -> Status {}
706
707struct AnyFfiParserBuilderConfigurer<'f>(Box<dyn FfiParserBuilderConfigurer + 'f>);
708impl<'f> AnyFfiParserBuilderConfigurer<'f> {
709 fn new<T: FfiParserBuilderConfigurer + 'f>(configurer: T) -> Self {
710 Self(Box::new(configurer))
711 }
712
713 fn call(&self, parser_builder: Pin<&mut ParserBuilder>) -> Status {
714 (self.0)(parser_builder)
715 }
716}
717
718pub use ffi::ParserLibrary;
720unsafe impl Send for ParserLibrary {}
721unsafe impl Sync for ParserLibrary {}
722
723impl ParserLibrary {
724 pub fn new(id: &cxx::CxxString, configurer: cxx::UniquePtr<ParserBuilderConfigurer>) -> cxx::UniquePtr<Self> {
725 ffi::ParserLibrary_new(id, configurer)
726 }
727
728 pub fn id(&self) -> &cxx::CxxString {
729 ffi::ParserLibrary_id(&self)
730 }
731}
732
733pub use ffi::MacroPredicate;
735unsafe impl Send for MacroPredicate {}
736unsafe impl Sync for MacroPredicate {}
737
738impl MacroPredicate {
739 pub fn new<F: FfiMacroPredicate + 'static>(predicate: F) -> cxx::UniquePtr<Self> {
740 ffi::MacroPredicate_new(Box::new(AnyFfiMacroPredicate::new(predicate)))
741 }
742}
743
744pub trait FfiMacroPredicate: Fn(&Macro) -> bool {}
745impl<'f, F> FfiMacroPredicate for F where
746 F: 'f + Fn(&Macro) -> bool {}
747
748struct AnyFfiMacroPredicate<'f>(Box<dyn FfiMacroPredicate + 'f>);
749impl<'f> AnyFfiMacroPredicate<'f> {
750 fn new<T: FfiMacroPredicate + 'f>(predicate: T) -> Self {
751 Self(Box::new(predicate))
752 }
753
754 fn call(&self, m: &Macro) -> bool {
755 (self.0)(m)
756 }
757}
758
759pub use ffi::ParserLibrarySubset;
761unsafe impl Send for ParserLibrarySubset {}
762unsafe impl Sync for ParserLibrarySubset {}
763
764impl ParserLibrarySubset {
765 pub fn new(library_id: &cxx::CxxString, should_include_macro: cxx::UniquePtr<MacroPredicate>) -> cxx::UniquePtr<Self> {
766 ffi::ParserLibrarySubset_new(library_id, should_include_macro)
767 }
768
769 pub fn library_id(&self) -> &cxx::CxxString {
770 ffi::ParserLibrarySubset_library_id(&self)
771 }
772}
773
774pub use ffi::ParserBuilder;
776unsafe impl Send for ParserBuilder {}
777unsafe impl Sync for ParserBuilder {}
778
779impl ParserBuilder {
780 pub fn add_library(self: Pin<&mut Self>, library: cxx::UniquePtr<ParserLibrary>) -> Status {
781 ffi::ParserBuilder_add_library(self, library)
782 }
783
784 pub fn add_library_subset(self: Pin<&mut Self>, library_subset: cxx::UniquePtr<ParserLibrarySubset>) -> Status {
785 ffi::ParserBuilder_add_library_subset(self, library_subset)
786 }
787}
788
789pub use ffi::Parser;
791unsafe impl Send for Parser {}
792unsafe impl Sync for Parser {}
793
794impl std::fmt::Debug for Parser {
795 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
796 let ptr = self as *const Parser;
797 write!(f, "Parser {{ ptr: {ptr:p} }}")
798 }
799}