cel-cxx-ffi 0.2.5

FFI bindings for the cel-cxx crate
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
use crate::absl::{Status, StringView};
use crate::common::{Expr, ListExprElement, StructExprField, MapExprEntry};
use std::pin::Pin;

#[cxx::bridge]
mod ffi {
    #[namespace = "absl"]
    unsafe extern "C++" {
        include!(<absl/status/status.h>);
        type Status = super::Status;

        include!(<absl/strings/string_view.h>);
        type string_view<'a> = super::StringView<'a>;
    }

    #[namespace = "cel"]
    unsafe extern "C++" {
        include!(<parser/parser.h>);
        type GlobalMacroExpander;
        type ReceiverMacroExpander;

        type Macro;
        fn function<'a>(self: &Macro) -> string_view<'a>;
        fn argument_count(self: &Macro) -> usize;
        fn is_receiver_style(self: &Macro) -> bool;
        fn is_variadic(self: &Macro) -> bool;
        fn key<'a>(self: &Macro) -> string_view<'a>;

        type MacroExprFactory;
        #[rust_name = "accu_var_name"]
        fn AccuVarName<'a>(self: Pin<&'a mut MacroExprFactory>) -> string_view<'a>;

        type ParserOptions;
        type ParserBuilderConfigurer;
        type ParserBuilder;
        #[rust_name = "add_macro"]
        fn AddMacro(self: Pin<&mut ParserBuilder>, m: &Macro) -> Status;

        type Parser;
        type ParserLibrary;
        type ParserLibrarySubset;
    }

    #[namespace = "cel"]
    unsafe extern "C++" {
        include!(<common/expr.h>);
        type Expr = super::Expr;
        type ListExprElement = super::ListExprElement;
        type StructExprField = super::StructExprField;
        type MapExprEntry = super::MapExprEntry;
    }

    #[namespace = "rust::cel_cxx"]
    unsafe extern "C++" {
        include!(<cel-cxx-ffi/include/absl.h>);
        include!(<cel-cxx-ffi/include/parser.h>);

        type MacroPredicate;

        // GlobalMacroExpander
        fn GlobalMacroExpander_new(ffi_expander: Box<AnyFfiGlobalMacroExpander>) -> UniquePtr<GlobalMacroExpander>;

        // ReceiverMacroExpander
        fn ReceiverMacroExpander_new(ffi_expander: Box<AnyFfiReceiverMacroExpander>) -> UniquePtr<ReceiverMacroExpander>;

        // Macro
        fn Macro_new_global<'a, 'f>(
            name: string_view<'a>,
            argument_count: usize,
            expander: UniquePtr<GlobalMacroExpander>,
            result: &mut UniquePtr<Macro>,
        ) -> Status;

        fn Macro_new_global_var_arg<'a, 'f>(
            name: string_view<'a>,
            expander: UniquePtr<GlobalMacroExpander>,
            result: &mut UniquePtr<Macro>,
        ) -> Status;

        fn Macro_new_receiver<'a, 'f>(
            name: string_view<'a>,
            argument_count: usize,
            expander: UniquePtr<ReceiverMacroExpander>,
            result: &mut UniquePtr<Macro>,
        ) -> Status;

        fn Macro_new_receiver_var_arg<'a, 'f>(
            name: string_view<'a>,
            expander: UniquePtr<ReceiverMacroExpander>,
            result: &mut UniquePtr<Macro>,
        ) -> Status;

        // MacroExprFactory
        fn MacroExprFactory_copy(
            factory: Pin<&mut MacroExprFactory>,
            expr: &Expr,
        ) -> UniquePtr<Expr>;
        fn MacroExprFactory_copy_list_element(
            factory: Pin<&mut MacroExprFactory>,
            list_element: &ListExprElement,
        ) -> UniquePtr<ListExprElement>;
        fn MacroExprFactory_copy_struct_field(
            factory: Pin<&mut MacroExprFactory>,
            struct_field: &StructExprField,
        ) -> UniquePtr<StructExprField>;
        fn MacroExprFactory_copy_map_entry(
            factory: Pin<&mut MacroExprFactory>,
            map_entry: &MapExprEntry,
        ) -> UniquePtr<MapExprEntry>;
        fn MacroExprFactory_new_unspecified(
            factory: Pin<&mut MacroExprFactory>,
        ) -> UniquePtr<Expr>;
        fn MacroExprFactory_new_null_const(
            factory: Pin<&mut MacroExprFactory>,
        ) -> UniquePtr<Expr>;
        fn MacroExprFactory_new_bool_const(
            factory: Pin<&mut MacroExprFactory>,
            value: bool,
        ) -> UniquePtr<Expr>;
        fn MacroExprFactory_new_int_const(
            factory: Pin<&mut MacroExprFactory>,
            value: i64,
        ) -> UniquePtr<Expr>;
        fn MacroExprFactory_new_double_const(
            factory: Pin<&mut MacroExprFactory>,
            value: f64,
        ) -> UniquePtr<Expr>;
        fn MacroExprFactory_new_bytes_const<'a>(
            factory: Pin<&mut MacroExprFactory>,
            value: string_view<'a>,
        ) -> UniquePtr<Expr>;
        fn MacroExprFactory_new_string_const<'a>(
            factory: Pin<&mut MacroExprFactory>,
            value: string_view<'a>,
        ) -> UniquePtr<Expr>;
        fn MacroExprFactory_new_ident<'a>(
            factory: Pin<&mut MacroExprFactory>,
            name: string_view<'a>,
        ) -> UniquePtr<Expr>;
        fn MacroExprFactory_new_accu_ident(
            factory: Pin<&mut MacroExprFactory>,
        ) -> UniquePtr<Expr>;
        fn MacroExprFactory_new_select<'a>(
            factory: Pin<&mut MacroExprFactory>,
            operand: UniquePtr<Expr>,
            field: string_view<'a>,
        ) -> UniquePtr<Expr>;
        fn MacroExprFactory_new_presence_test<'a>(
            factory: Pin<&mut MacroExprFactory>,
            operand: UniquePtr<Expr>,
            field: string_view<'a>,
        ) -> UniquePtr<Expr>;
        fn MacroExprFactory_new_call<'a>(
            factory: Pin<&mut MacroExprFactory>,
            function: string_view<'a>,
            args: UniquePtr<CxxVector<Expr>>,
        ) -> UniquePtr<Expr>;
        fn MacroExprFactory_new_member_call<'a>(
            factory: Pin<&mut MacroExprFactory>,
            function: string_view<'a>,
            target: UniquePtr<Expr>,
            args: UniquePtr<CxxVector<Expr>>,
        ) -> UniquePtr<Expr>;
        fn MacroExprFactory_new_list_element(
            factory: Pin<&mut MacroExprFactory>,
            expr: UniquePtr<Expr>,
            optional: bool,
        ) -> UniquePtr<ListExprElement>;
        fn MacroExprFactory_new_list(
            factory: Pin<&mut MacroExprFactory>,
            elements: UniquePtr<CxxVector<ListExprElement>>,
        ) -> UniquePtr<Expr>;
        fn MacroExprFactory_new_struct_field<'a>(
            factory: Pin<&mut MacroExprFactory>,
            name: string_view<'a>,
            value: UniquePtr<Expr>,
            optional: bool,
        ) -> UniquePtr<StructExprField>;
        fn MacroExprFactory_new_struct<'a>(
            factory: Pin<&mut MacroExprFactory>,
            name: string_view<'a>,
            fields: UniquePtr<CxxVector<StructExprField>>,
        ) -> UniquePtr<Expr>;
        fn MacroExprFactory_new_map_entry(
            factory: Pin<&mut MacroExprFactory>,
            key: UniquePtr<Expr>,
            value: UniquePtr<Expr>,
            optional: bool,
        ) -> UniquePtr<MapExprEntry>;
        fn MacroExprFactory_new_map(
            factory: Pin<&mut MacroExprFactory>,
            entries: UniquePtr<CxxVector<MapExprEntry>>,
        ) -> UniquePtr<Expr>;
        fn MacroExprFactory_new_comprehension<'a>(
            factory: Pin<&mut MacroExprFactory>,
            iter_var: string_view<'a>,
            iter_range: UniquePtr<Expr>,
            accu_var: string_view<'a>,
            accu_init: UniquePtr<Expr>,
            loop_condition: UniquePtr<Expr>,
            loop_step: UniquePtr<Expr>,
            result: UniquePtr<Expr>,
        ) -> UniquePtr<Expr>;
        fn MacroExprFactory_new_comprehension2<'a>(
            factory: Pin<&mut MacroExprFactory>,
            iter_var: string_view<'a>,
            iter_var2: string_view<'a>,
            iter_range: UniquePtr<Expr>,
            accu_var: string_view<'a>,
            accu_init: UniquePtr<Expr>,
            loop_condition: UniquePtr<Expr>,
            loop_step: UniquePtr<Expr>,
            result: UniquePtr<Expr>,
        ) -> UniquePtr<Expr>;
        fn MacroExprFactory_report_error<'a>(
            factory: Pin<&mut MacroExprFactory>,
            message: string_view<'a>,
        ) -> UniquePtr<Expr>;
        fn MacroExprFactory_report_error_at<'a>(
            factory: Pin<&mut MacroExprFactory>,
            expr: &Expr,
            message: string_view<'a>,
        ) -> UniquePtr<Expr>;

        // ParserOptions
        fn ParserOptions_new() -> UniquePtr<ParserOptions>;

        // ParserOptions getters and setters
        fn ParserOptions_error_recovery_limit(parser_options: &ParserOptions) -> i32;
        fn ParserOptions_error_recovery_limit_mut(
            parser_options: Pin<&mut ParserOptions>,
        ) -> &mut i32;
        fn ParserOptions_max_recursion_depth(parser_options: &ParserOptions) -> i32;
        fn ParserOptions_max_recursion_depth_mut(
            parser_options: Pin<&mut ParserOptions>,
        ) -> &mut i32;
        fn ParserOptions_expression_size_codepoint_limit(parser_options: &ParserOptions) -> i32;
        fn ParserOptions_expression_size_codepoint_limit_mut(
            parser_options: Pin<&mut ParserOptions>,
        ) -> &mut i32;
        fn ParserOptions_error_recovery_token_lookahead_limit(
            parser_options: &ParserOptions,
        ) -> i32;
        fn ParserOptions_error_recovery_token_lookahead_limit_mut(
            parser_options: Pin<&mut ParserOptions>,
        ) -> &mut i32;
        fn ParserOptions_add_macro_calls(parser_options: &ParserOptions) -> bool;
        fn ParserOptions_add_macro_calls_mut(parser_options: Pin<&mut ParserOptions>) -> &mut bool;
        fn ParserOptions_enable_optional_syntax(parser_options: &ParserOptions) -> bool;
        fn ParserOptions_enable_optional_syntax_mut(
            parser_options: Pin<&mut ParserOptions>,
        ) -> &mut bool;
        fn ParserOptions_disable_standard_macros(parser_options: &ParserOptions) -> bool;
        fn ParserOptions_disable_standard_macros_mut(
            parser_options: Pin<&mut ParserOptions>,
        ) -> &mut bool;
        fn ParserOptions_enable_hidden_accumulator_var(parser_options: &ParserOptions) -> bool;
        fn ParserOptions_enable_hidden_accumulator_var_mut(
            parser_options: Pin<&mut ParserOptions>,
        ) -> &mut bool;
        fn ParserOptions_enable_quoted_identifiers(parser_options: &ParserOptions) -> bool;
        fn ParserOptions_enable_quoted_identifiers_mut(
            parser_options: Pin<&mut ParserOptions>,
        ) -> &mut bool;

        // ParserBuilderConfigurer
        fn ParserBuilderConfigurer_new(ffi_configurer: Box<AnyFfiParserBuilderConfigurer>) -> UniquePtr<ParserBuilderConfigurer>;

        // ParserLibrary
        fn ParserLibrary_new(id: &CxxString, configurer: UniquePtr<ParserBuilderConfigurer>) -> UniquePtr<ParserLibrary>;
        fn ParserLibrary_id<'a>(parser_library: &'a ParserLibrary) -> &'a CxxString;

        // MacroPredicate
        fn MacroPredicate_new(ffi_predicate: Box<AnyFfiMacroPredicate>) -> UniquePtr<MacroPredicate>;

        // ParserLibrarySubset
        fn ParserLibrarySubset_new(library_id: &CxxString, should_include_macro: UniquePtr<MacroPredicate>) -> UniquePtr<ParserLibrarySubset>;
        fn ParserLibrarySubset_library_id<'a>(parser_library_subset: &'a ParserLibrarySubset) -> &'a CxxString;

        // ParserBuilder
        fn ParserBuilder_add_library(
            parser_builder: Pin<&mut ParserBuilder>,
            library: UniquePtr<ParserLibrary>,
        ) -> Status;
        fn ParserBuilder_add_library_subset(
            parser_builder: Pin<&mut ParserBuilder>,
            library_subset: UniquePtr<ParserLibrarySubset>,
        ) -> Status;
    }

    #[namespace = "rust::cel_cxx"]
    extern "Rust" {
        #[derive(ExternType)]
        type AnyFfiParserBuilderConfigurer<'f>;
        #[cxx_name = "Call"]
        unsafe fn call<'f>(
            self: &AnyFfiParserBuilderConfigurer<'f>,
            parser_builder: Pin<&mut ParserBuilder>,
        ) -> Status;

        #[derive(ExternType)]
        type AnyFfiMacroPredicate<'f>;
        #[cxx_name = "Call"]
        unsafe fn call<'f>(
            self: &AnyFfiMacroPredicate<'f>,
            m: &Macro,
        ) -> bool;

        type AnyFfiGlobalMacroExpander<'f>;
        #[cxx_name = "Call"]
        unsafe fn call<'f>(
            self: &AnyFfiGlobalMacroExpander<'f>,
            factory: Pin<&mut MacroExprFactory>,
            args: &mut [UniquePtr<Expr>],
        ) -> UniquePtr<Expr>;

        type AnyFfiReceiverMacroExpander<'f>;
        #[cxx_name = "Call"]
        unsafe fn call<'f>(
            self: &AnyFfiReceiverMacroExpander<'f>,
            factory: Pin<&mut MacroExprFactory>,
            target: UniquePtr<Expr>,
            args: &mut [UniquePtr<Expr>],
        ) -> UniquePtr<Expr>;
    }

}

// GlobalMacroExpander
pub use ffi::GlobalMacroExpander;
unsafe impl Send for GlobalMacroExpander {}
unsafe impl Sync for GlobalMacroExpander {}

impl GlobalMacroExpander {
    pub fn new<F: FfiGlobalMacroExpander + 'static>(expander: F) -> cxx::UniquePtr<Self> {
        ffi::GlobalMacroExpander_new(Box::new(AnyFfiGlobalMacroExpander::new(expander)))
    }
}

pub trait FfiGlobalMacroExpander
    : Fn(Pin<&mut MacroExprFactory>, &mut [cxx::UniquePtr<Expr>]) -> cxx::UniquePtr<Expr>
{}

impl<'f, F> FfiGlobalMacroExpander for F where F
    : Fn(Pin<&mut MacroExprFactory>, &mut [cxx::UniquePtr<Expr>]) -> cxx::UniquePtr<Expr>
    + 'f
{}

struct AnyFfiGlobalMacroExpander<'f>(Box<dyn FfiGlobalMacroExpander + 'f>);
impl<'f> AnyFfiGlobalMacroExpander<'f> {
    fn new<T: FfiGlobalMacroExpander + 'f>(expander: T) -> Self {
        Self(Box::new(expander))
    }

    fn call(&self, factory: Pin<&mut MacroExprFactory>, args: &mut [cxx::UniquePtr<Expr>]) -> cxx::UniquePtr<Expr> {
        (self.0)(factory, args)
    }
}

// ReceiverMacroExpander
pub use ffi::ReceiverMacroExpander;
unsafe impl Send for ReceiverMacroExpander {}
unsafe impl Sync for ReceiverMacroExpander {}

impl ReceiverMacroExpander {
    pub fn new<F: FfiReceiverMacroExpander + 'static>(expander: F) -> cxx::UniquePtr<Self> {
        ffi::ReceiverMacroExpander_new(Box::new(AnyFfiReceiverMacroExpander::new(expander)))
    }
}

pub trait FfiReceiverMacroExpander
    : Fn(Pin<&mut MacroExprFactory>, cxx::UniquePtr<Expr>, &mut [cxx::UniquePtr<Expr>]) -> cxx::UniquePtr<Expr>
{}

impl<'f, F> FfiReceiverMacroExpander for F where F
    : Fn(Pin<&mut MacroExprFactory>, cxx::UniquePtr<Expr>, &mut [cxx::UniquePtr<Expr>]) -> cxx::UniquePtr<Expr>
    + 'f
{}

struct AnyFfiReceiverMacroExpander<'f>(Box<dyn FfiReceiverMacroExpander + 'f>);
impl<'f> AnyFfiReceiverMacroExpander<'f> {
    fn new<T: FfiReceiverMacroExpander + 'f>(expander: T) -> Self {
        Self(Box::new(expander))
    }

    fn call(&self, factory: Pin<&mut MacroExprFactory>, target: cxx::UniquePtr<Expr>, args: &mut [cxx::UniquePtr<Expr>]) -> cxx::UniquePtr<Expr> {
        (self.0)(factory, target, args)
    }
}

// Macro
pub use ffi::Macro;
unsafe impl Send for Macro {}
unsafe impl Sync for Macro {}

impl Macro {
    pub fn new_global(
        name: StringView<'_>,
        argument_count: usize,
        expander: cxx::UniquePtr<GlobalMacroExpander>,
    ) -> Result<cxx::UniquePtr<Self>, Status> {
        let mut result = cxx::UniquePtr::null();
        let status = ffi::Macro_new_global(name, argument_count, expander, &mut result);
        if status.is_ok() {
            Ok(result)
        } else {
            Err(status)
        }
    }

    pub fn new_global_var_arg(
        name: StringView<'_>,
        expander: cxx::UniquePtr<GlobalMacroExpander>,
    ) -> Result<cxx::UniquePtr<Self>, Status> {
        let mut result = cxx::UniquePtr::null();
        let status = ffi::Macro_new_global_var_arg(name, expander, &mut result);
        if status.is_ok() {
            Ok(result)
        } else {
            Err(status)
        }
    }

    pub fn new_receiver(
        name: StringView<'_>,
        argument_count: usize,
        expander: cxx::UniquePtr<ReceiverMacroExpander>,
    ) -> Result<cxx::UniquePtr<Self>, Status> {
        let mut result = cxx::UniquePtr::null();
        let status = ffi::Macro_new_receiver(name, argument_count, expander, &mut result);
        if status.is_ok() {
            Ok(result)
        } else {
            Err(status)
        }
    }

    pub fn new_receiver_var_arg(
        name: StringView<'_>,
        expander: cxx::UniquePtr<ReceiverMacroExpander>,
    ) -> Result<cxx::UniquePtr<Self>, Status> {
        let mut result = cxx::UniquePtr::null();
        let status = ffi::Macro_new_receiver_var_arg(name, expander, &mut result);
        if status.is_ok() {
            Ok(result)
        } else {
            Err(status)
        }
    }
}

// MacroExprFactory
pub use ffi::MacroExprFactory;
unsafe impl Send for MacroExprFactory {}
unsafe impl Sync for MacroExprFactory {}

impl MacroExprFactory {
    pub fn copy(self: Pin<&mut Self>, expr: &Expr) -> cxx::UniquePtr<Expr> {
        ffi::MacroExprFactory_copy(self, expr)
    }

    pub fn copy_list_element(self: Pin<&mut Self>, list_element: &ListExprElement) -> cxx::UniquePtr<ListExprElement> {
        ffi::MacroExprFactory_copy_list_element(self, list_element)
    }

    pub fn copy_struct_field(self: Pin<&mut Self>, struct_field: &StructExprField) -> cxx::UniquePtr<StructExprField> {
        ffi::MacroExprFactory_copy_struct_field(self, struct_field)
    }

    pub fn copy_map_entry(self: Pin<&mut Self>, map_entry: &MapExprEntry) -> cxx::UniquePtr<MapExprEntry> {
        ffi::MacroExprFactory_copy_map_entry(self, map_entry)
    }

    pub fn new_unspecified(self: Pin<&mut Self>) -> cxx::UniquePtr<Expr> {
        ffi::MacroExprFactory_new_unspecified(self)
    }

    pub fn new_null_const(self: Pin<&mut Self>) -> cxx::UniquePtr<Expr> {
        ffi::MacroExprFactory_new_null_const(self)
    }
    
    pub fn new_bool_const(self: Pin<&mut Self>, value: bool) -> cxx::UniquePtr<Expr> {
        ffi::MacroExprFactory_new_bool_const(self, value)
    }

    pub fn new_int_const(self: Pin<&mut Self>, value: i64) -> cxx::UniquePtr<Expr> {
        ffi::MacroExprFactory_new_int_const(self, value)
    }

    pub fn new_double_const(self: Pin<&mut Self>, value: f64) -> cxx::UniquePtr<Expr> {
        ffi::MacroExprFactory_new_double_const(self, value)
    }

    pub fn new_bytes_const(self: Pin<&mut Self>, value: StringView<'_>) -> cxx::UniquePtr<Expr> {
        ffi::MacroExprFactory_new_bytes_const(self, value)
    }

    pub fn new_string_const(self: Pin<&mut Self>, value: StringView<'_>) -> cxx::UniquePtr<Expr> {
        ffi::MacroExprFactory_new_string_const(self, value)
    }

    pub fn new_ident(self: Pin<&mut Self>, name: StringView<'_>) -> cxx::UniquePtr<Expr> {
        ffi::MacroExprFactory_new_ident(self, name)
    }

    pub fn new_accu_ident(self: Pin<&mut Self>) -> cxx::UniquePtr<Expr> {
        ffi::MacroExprFactory_new_accu_ident(self)
    }

    pub fn new_select(self: Pin<&mut Self>, operand: cxx::UniquePtr<Expr>, field: StringView<'_>) -> cxx::UniquePtr<Expr> {
        ffi::MacroExprFactory_new_select(self, operand, field)
    }

    pub fn new_presence_test(self: Pin<&mut Self>, operand: cxx::UniquePtr<Expr>, field: StringView<'_>) -> cxx::UniquePtr<Expr> {
        ffi::MacroExprFactory_new_presence_test(self, operand, field)
    }

    pub fn new_call(self: Pin<&mut Self>, function: StringView<'_>, args: cxx::UniquePtr<cxx::CxxVector<Expr>>) -> cxx::UniquePtr<Expr> {
        ffi::MacroExprFactory_new_call(self, function, args)
    }

    pub fn new_member_call(self: Pin<&mut Self>, function: StringView<'_>, target: cxx::UniquePtr<Expr>, args: cxx::UniquePtr<cxx::CxxVector<Expr>>) -> cxx::UniquePtr<Expr> {
        ffi::MacroExprFactory_new_member_call(self, function, target, args)
    }

    pub fn new_list_element(self: Pin<&mut Self>, expr: cxx::UniquePtr<Expr>, optional: bool) -> cxx::UniquePtr<ListExprElement> {
        ffi::MacroExprFactory_new_list_element(self, expr, optional)
    }

    pub fn new_list(self: Pin<&mut Self>, elements: cxx::UniquePtr<cxx::CxxVector<ListExprElement>>) -> cxx::UniquePtr<Expr> {
        ffi::MacroExprFactory_new_list(self, elements)
    }

    pub fn new_struct_field(self: Pin<&mut Self>, name: StringView<'_>, value: cxx::UniquePtr<Expr>, optional: bool) -> cxx::UniquePtr<StructExprField> {
        ffi::MacroExprFactory_new_struct_field(self, name, value, optional)
    }

    pub fn new_struct(self: Pin<&mut Self>, name: StringView<'_>, fields: cxx::UniquePtr<cxx::CxxVector<StructExprField>>) -> cxx::UniquePtr<Expr> {
        ffi::MacroExprFactory_new_struct(self, name, fields)
    }

    pub fn new_map_entry(self: Pin<&mut Self>, key: cxx::UniquePtr<Expr>, value: cxx::UniquePtr<Expr>, optional: bool) -> cxx::UniquePtr<MapExprEntry> {
        ffi::MacroExprFactory_new_map_entry(self, key, value, optional)
    }
    
    pub fn new_map(self: Pin<&mut Self>, entries: cxx::UniquePtr<cxx::CxxVector<MapExprEntry>>) -> cxx::UniquePtr<Expr> {
        ffi::MacroExprFactory_new_map(self, entries)
    }

    pub fn new_comprehension(
        self: Pin<&mut Self>,
        iter_var: StringView<'_>,
        iter_range: cxx::UniquePtr<Expr>,
        accu_var: StringView<'_>,
        accu_init: cxx::UniquePtr<Expr>,
        loop_condition: cxx::UniquePtr<Expr>,
        loop_step: cxx::UniquePtr<Expr>,
        result: cxx::UniquePtr<Expr>,
    ) -> cxx::UniquePtr<Expr> {
        ffi::MacroExprFactory_new_comprehension(
            self,
            iter_var,
            iter_range,
            accu_var,
            accu_init,
            loop_condition,
            loop_step,
            result,
        )
    }
    
    pub fn new_comprehension2(
        self: Pin<&mut Self>,
        iter_var: StringView<'_>,
        iter_var2: StringView<'_>,
        iter_range: cxx::UniquePtr<Expr>,
        accu_var: StringView<'_>,
        accu_init: cxx::UniquePtr<Expr>,
        loop_condition: cxx::UniquePtr<Expr>,
        loop_step: cxx::UniquePtr<Expr>,
        result: cxx::UniquePtr<Expr>,
    ) -> cxx::UniquePtr<Expr> {
        ffi::MacroExprFactory_new_comprehension2(
            self,
            iter_var,
            iter_var2,
            iter_range,
            accu_var,
            accu_init,
            loop_condition,
            loop_step,
            result,
        )
    }

    pub fn report_error(self: Pin<&mut Self>, message: StringView<'_>) -> cxx::UniquePtr<Expr> {
        ffi::MacroExprFactory_report_error(self, message)
    }
    
    pub fn report_error_at(self: Pin<&mut Self>, expr: &Expr, message: StringView<'_>) -> cxx::UniquePtr<Expr> {
        ffi::MacroExprFactory_report_error_at(self, expr, message)
    }
}

pub use ffi::ParserOptions;
unsafe impl Send for ParserOptions {}
unsafe impl Sync for ParserOptions {}

impl ParserOptions {
    pub fn new() -> cxx::UniquePtr<Self> {
        ffi::ParserOptions_new()
    }

    pub fn error_recovery_limit(&self) -> i32 {
        ffi::ParserOptions_error_recovery_limit(self)
    }

    pub fn error_recovery_limit_mut<'a>(self: Pin<&'a mut Self>) -> &'a mut i32 {
        ffi::ParserOptions_error_recovery_limit_mut(self)
    }

    pub fn max_recursion_depth(&self) -> i32 {
        ffi::ParserOptions_max_recursion_depth(self)
    }

    pub fn max_recursion_depth_mut<'a>(self: Pin<&'a mut Self>) -> &'a mut i32 {
        ffi::ParserOptions_max_recursion_depth_mut(self)
    }

    pub fn expression_size_codepoint_limit(&self) -> i32 {
        ffi::ParserOptions_expression_size_codepoint_limit(self)
    }

    pub fn expression_size_codepoint_limit_mut<'a>(self: Pin<&'a mut Self>) -> &'a mut i32 {
        ffi::ParserOptions_expression_size_codepoint_limit_mut(self)
    }

    pub fn error_recovery_token_lookahead_limit(&self) -> i32 {
        ffi::ParserOptions_error_recovery_token_lookahead_limit(self)
    }

    pub fn error_recovery_token_lookahead_limit_mut<'a>(self: Pin<&'a mut Self>) -> &'a mut i32 {
        ffi::ParserOptions_error_recovery_token_lookahead_limit_mut(self)
    }

    pub fn add_macro_calls(&self) -> bool {
        ffi::ParserOptions_add_macro_calls(self)
    }

    pub fn add_macro_calls_mut<'a>(self: Pin<&'a mut Self>) -> &'a mut bool {
        ffi::ParserOptions_add_macro_calls_mut(self)
    }

    pub fn enable_optional_syntax(&self) -> bool {
        ffi::ParserOptions_enable_optional_syntax(self)
    }

    pub fn enable_optional_syntax_mut<'a>(self: Pin<&'a mut Self>) -> &'a mut bool {
        ffi::ParserOptions_enable_optional_syntax_mut(self)
    }

    pub fn disable_standard_macros(&self) -> bool {
        ffi::ParserOptions_disable_standard_macros(self)
    }

    pub fn disable_standard_macros_mut<'a>(self: Pin<&'a mut Self>) -> &'a mut bool {
        ffi::ParserOptions_disable_standard_macros_mut(self)
    }

    pub fn enable_hidden_accumulator_var(&self) -> bool {
        ffi::ParserOptions_enable_hidden_accumulator_var(self)
    }

    pub fn enable_hidden_accumulator_var_mut<'a>(self: Pin<&'a mut Self>) -> &'a mut bool {
        ffi::ParserOptions_enable_hidden_accumulator_var_mut(self)
    }

    pub fn enable_quoted_identifiers(&self) -> bool {
        ffi::ParserOptions_enable_quoted_identifiers(self)
    }

    pub fn enable_quoted_identifiers_mut<'a>(self: Pin<&'a mut Self>) -> &'a mut bool {
        ffi::ParserOptions_enable_quoted_identifiers_mut(self)
    }
}

// ParserBuilderConfigurer
pub use ffi::ParserBuilderConfigurer;
unsafe impl Send for ParserBuilderConfigurer {}
unsafe impl Sync for ParserBuilderConfigurer {}

impl ParserBuilderConfigurer {
    pub fn new<F: FfiParserBuilderConfigurer + 'static>(configurer: F) -> cxx::UniquePtr<Self> {
        ffi::ParserBuilderConfigurer_new(Box::new(AnyFfiParserBuilderConfigurer::new(configurer)))
    }
}

pub trait FfiParserBuilderConfigurer: Fn(Pin<&mut ParserBuilder>) -> Status {}
impl<'f, F> FfiParserBuilderConfigurer for F where
    F: 'f + Fn(Pin<&mut ParserBuilder>) -> Status {}

struct AnyFfiParserBuilderConfigurer<'f>(Box<dyn FfiParserBuilderConfigurer + 'f>);
impl<'f> AnyFfiParserBuilderConfigurer<'f> {
    fn new<T: FfiParserBuilderConfigurer + 'f>(configurer: T) -> Self {
        Self(Box::new(configurer))
    }

    fn call(&self, parser_builder: Pin<&mut ParserBuilder>) -> Status {
        (self.0)(parser_builder)
    }
}

// ParserLibrary
pub use ffi::ParserLibrary;
unsafe impl Send for ParserLibrary {}
unsafe impl Sync for ParserLibrary {}

impl ParserLibrary {
    pub fn new(id: &cxx::CxxString, configurer: cxx::UniquePtr<ParserBuilderConfigurer>) -> cxx::UniquePtr<Self> {
        ffi::ParserLibrary_new(id, configurer)
    }

    pub fn id(&self) -> &cxx::CxxString {
        ffi::ParserLibrary_id(&self)
    }
}

// MacroPredicate
pub use ffi::MacroPredicate;
unsafe impl Send for MacroPredicate {}
unsafe impl Sync for MacroPredicate {}

impl MacroPredicate {
    pub fn new<F: FfiMacroPredicate + 'static>(predicate: F) -> cxx::UniquePtr<Self> {
        ffi::MacroPredicate_new(Box::new(AnyFfiMacroPredicate::new(predicate)))
    }
}

pub trait FfiMacroPredicate: Fn(&Macro) -> bool {}
impl<'f, F> FfiMacroPredicate for F where
    F: 'f + Fn(&Macro) -> bool {}

struct AnyFfiMacroPredicate<'f>(Box<dyn FfiMacroPredicate + 'f>);
impl<'f> AnyFfiMacroPredicate<'f> {
    fn new<T: FfiMacroPredicate + 'f>(predicate: T) -> Self {
        Self(Box::new(predicate))
    }

    fn call(&self, m: &Macro) -> bool {
        (self.0)(m)
    }
}

// ParserLibrarySubset
pub use ffi::ParserLibrarySubset;
unsafe impl Send for ParserLibrarySubset {}
unsafe impl Sync for ParserLibrarySubset {}

impl ParserLibrarySubset {
    pub fn new(library_id: &cxx::CxxString, should_include_macro: cxx::UniquePtr<MacroPredicate>) -> cxx::UniquePtr<Self> {
        ffi::ParserLibrarySubset_new(library_id, should_include_macro)
    }

    pub fn library_id(&self) -> &cxx::CxxString {
        ffi::ParserLibrarySubset_library_id(&self)
    }
}

// ParserBuilder
pub use ffi::ParserBuilder;
unsafe impl Send for ParserBuilder {}
unsafe impl Sync for ParserBuilder {}

impl ParserBuilder {
    pub fn add_library(self: Pin<&mut Self>, library: cxx::UniquePtr<ParserLibrary>) -> Status {
        ffi::ParserBuilder_add_library(self, library)
    }

    pub fn add_library_subset(self: Pin<&mut Self>, library_subset: cxx::UniquePtr<ParserLibrarySubset>) -> Status {
        ffi::ParserBuilder_add_library_subset(self, library_subset)
    }
}

// Parser
pub use ffi::Parser;
unsafe impl Send for Parser {}
unsafe impl Sync for Parser {}

impl std::fmt::Debug for Parser {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let ptr = self as *const Parser;
        write!(f, "Parser {{ ptr: {ptr:p} }}")
    }
}