cel_cxx_ffi/
parser.rs

1use crate::absl::StringView;
2use std::pin::Pin;
3
4#[cxx::bridge]
5mod ffi {
6    #[namespace = "absl"]
7    unsafe extern "C++" {
8        type string_view<'a> = super::StringView<'a>;
9    }
10
11    #[namespace = "cel"]
12    unsafe extern "C++" {
13        include!(<parser/parser.h>);
14        type Macro;
15        fn function<'a>(self: &Macro) -> string_view<'a>;
16        fn argument_count(self: &Macro) -> usize;
17        fn is_receiver_style(self: &Macro) -> bool;
18        fn is_variadic(self: &Macro) -> bool;
19        fn key<'a>(self: &Macro) -> string_view<'a>;
20
21        type ParserOptions;
22        type ParserBuilder;
23        type Parser;
24    }
25
26    #[namespace = "rust::cel_cxx"]
27    unsafe extern "C++" {
28        include!(<cel-cxx-ffi/include/absl.h>);
29        include!(<cel-cxx-ffi/include/parser.h>);
30
31        // ParserOptions
32        fn ParserOptions_new() -> UniquePtr<ParserOptions>;
33
34        // ParserOptions getters and setters
35        fn ParserOptions_error_recovery_limit(parser_options: &ParserOptions) -> i32;
36        fn ParserOptions_error_recovery_limit_mut(
37            parser_options: Pin<&mut ParserOptions>,
38        ) -> &mut i32;
39        fn ParserOptions_max_recursion_depth(parser_options: &ParserOptions) -> i32;
40        fn ParserOptions_max_recursion_depth_mut(
41            parser_options: Pin<&mut ParserOptions>,
42        ) -> &mut i32;
43        fn ParserOptions_expression_size_codepoint_limit(parser_options: &ParserOptions) -> i32;
44        fn ParserOptions_expression_size_codepoint_limit_mut(
45            parser_options: Pin<&mut ParserOptions>,
46        ) -> &mut i32;
47        fn ParserOptions_error_recovery_token_lookahead_limit(
48            parser_options: &ParserOptions,
49        ) -> i32;
50        fn ParserOptions_error_recovery_token_lookahead_limit_mut(
51            parser_options: Pin<&mut ParserOptions>,
52        ) -> &mut i32;
53        fn ParserOptions_add_macro_calls(parser_options: &ParserOptions) -> bool;
54        fn ParserOptions_add_macro_calls_mut(parser_options: Pin<&mut ParserOptions>) -> &mut bool;
55        fn ParserOptions_enable_optional_syntax(parser_options: &ParserOptions) -> bool;
56        fn ParserOptions_enable_optional_syntax_mut(
57            parser_options: Pin<&mut ParserOptions>,
58        ) -> &mut bool;
59        fn ParserOptions_disable_standard_macros(parser_options: &ParserOptions) -> bool;
60        fn ParserOptions_disable_standard_macros_mut(
61            parser_options: Pin<&mut ParserOptions>,
62        ) -> &mut bool;
63        fn ParserOptions_enable_hidden_accumulator_var(parser_options: &ParserOptions) -> bool;
64        fn ParserOptions_enable_hidden_accumulator_var_mut(
65            parser_options: Pin<&mut ParserOptions>,
66        ) -> &mut bool;
67        fn ParserOptions_enable_quoted_identifiers(parser_options: &ParserOptions) -> bool;
68        fn ParserOptions_enable_quoted_identifiers_mut(
69            parser_options: Pin<&mut ParserOptions>,
70        ) -> &mut bool;
71    }
72}
73
74// Macro
75pub use ffi::Macro;
76unsafe impl Send for Macro {}
77unsafe impl Sync for Macro {}
78
79pub use ffi::ParserOptions;
80unsafe impl Send for ParserOptions {}
81unsafe impl Sync for ParserOptions {}
82
83impl ParserOptions {
84    pub fn new() -> cxx::UniquePtr<Self> {
85        ffi::ParserOptions_new()
86    }
87
88    pub fn error_recovery_limit(&self) -> i32 {
89        ffi::ParserOptions_error_recovery_limit(self)
90    }
91
92    pub fn error_recovery_limit_mut<'a>(self: Pin<&'a mut Self>) -> &'a mut i32 {
93        ffi::ParserOptions_error_recovery_limit_mut(self)
94    }
95
96    pub fn max_recursion_depth(&self) -> i32 {
97        ffi::ParserOptions_max_recursion_depth(self)
98    }
99
100    pub fn max_recursion_depth_mut<'a>(self: Pin<&'a mut Self>) -> &'a mut i32 {
101        ffi::ParserOptions_max_recursion_depth_mut(self)
102    }
103
104    pub fn expression_size_codepoint_limit(&self) -> i32 {
105        ffi::ParserOptions_expression_size_codepoint_limit(self)
106    }
107
108    pub fn expression_size_codepoint_limit_mut<'a>(self: Pin<&'a mut Self>) -> &'a mut i32 {
109        ffi::ParserOptions_expression_size_codepoint_limit_mut(self)
110    }
111
112    pub fn error_recovery_token_lookahead_limit(&self) -> i32 {
113        ffi::ParserOptions_error_recovery_token_lookahead_limit(self)
114    }
115
116    pub fn error_recovery_token_lookahead_limit_mut<'a>(self: Pin<&'a mut Self>) -> &'a mut i32 {
117        ffi::ParserOptions_error_recovery_token_lookahead_limit_mut(self)
118    }
119
120    pub fn add_macro_calls(&self) -> bool {
121        ffi::ParserOptions_add_macro_calls(self)
122    }
123
124    pub fn add_macro_calls_mut<'a>(self: Pin<&'a mut Self>) -> &'a mut bool {
125        ffi::ParserOptions_add_macro_calls_mut(self)
126    }
127
128    pub fn enable_optional_syntax(&self) -> bool {
129        ffi::ParserOptions_enable_optional_syntax(self)
130    }
131
132    pub fn enable_optional_syntax_mut<'a>(self: Pin<&'a mut Self>) -> &'a mut bool {
133        ffi::ParserOptions_enable_optional_syntax_mut(self)
134    }
135
136    pub fn disable_standard_macros(&self) -> bool {
137        ffi::ParserOptions_disable_standard_macros(self)
138    }
139
140    pub fn disable_standard_macros_mut<'a>(self: Pin<&'a mut Self>) -> &'a mut bool {
141        ffi::ParserOptions_disable_standard_macros_mut(self)
142    }
143
144    pub fn enable_hidden_accumulator_var(&self) -> bool {
145        ffi::ParserOptions_enable_hidden_accumulator_var(self)
146    }
147
148    pub fn enable_hidden_accumulator_var_mut<'a>(self: Pin<&'a mut Self>) -> &'a mut bool {
149        ffi::ParserOptions_enable_hidden_accumulator_var_mut(self)
150    }
151
152    pub fn enable_quoted_identifiers(&self) -> bool {
153        ffi::ParserOptions_enable_quoted_identifiers(self)
154    }
155
156    pub fn enable_quoted_identifiers_mut<'a>(self: Pin<&'a mut Self>) -> &'a mut bool {
157        ffi::ParserOptions_enable_quoted_identifiers_mut(self)
158    }
159}
160
161pub use ffi::ParserBuilder;
162unsafe impl Send for ParserBuilder {}
163unsafe impl Sync for ParserBuilder {}
164
165// Parser
166pub use ffi::Parser;
167unsafe impl Send for Parser {}
168unsafe impl Sync for Parser {}
169
170impl std::fmt::Debug for Parser {
171    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
172        let ptr = self as *const Parser;
173        write!(f, "Parser {{ ptr: {ptr:p} }}")
174    }
175}