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