onig/
flags.rs

1use bitflags::bitflags;
2use std::os::raw::c_uint;
3
4bitflags! {
5    /// Regex parsing and compilation options.
6    pub struct RegexOptions: onig_sys::OnigOptionType {
7        /// Default options.
8        const REGEX_OPTION_NONE
9            = onig_sys::ONIG_OPTION_NONE;
10        /// Ambiguity match on.
11        const REGEX_OPTION_IGNORECASE
12            = onig_sys::ONIG_OPTION_IGNORECASE;
13        /// Extended pattern form.
14        const REGEX_OPTION_EXTEND
15            = onig_sys::ONIG_OPTION_EXTEND;
16        /// `'.'` match with newline.
17        const REGEX_OPTION_MULTILINE
18            = onig_sys::ONIG_OPTION_MULTILINE;
19        /// `'^'` -> `'\A'`, `'$'` -> `'\Z'`.
20        const REGEX_OPTION_SINGLELINE
21            = onig_sys::ONIG_OPTION_SINGLELINE;
22        /// Find longest match.
23        const REGEX_OPTION_FIND_LONGEST
24            = onig_sys::ONIG_OPTION_FIND_LONGEST;
25        /// Ignore empty match.
26        const REGEX_OPTION_FIND_NOT_EMPTY
27            = onig_sys::ONIG_OPTION_FIND_NOT_EMPTY;
28        /// Clear `OPTION_SINGLELINE` which is enabled on
29        /// `SYNTAX_POSIX_BASIC`, `SYNTAX_POSIX_EXTENDED`,
30        /// `SYNTAX_PERL`, `SYNTAX_PERL_NG`, `SYNTAX_JAVA`.
31        const REGEX_OPTION_NEGATE_SINGLELINE
32            = onig_sys::ONIG_OPTION_NEGATE_SINGLELINE;
33        /// Only named group captured.
34        const REGEX_OPTION_DONT_CAPTURE_GROUP
35            = onig_sys::ONIG_OPTION_DONT_CAPTURE_GROUP;
36        /// Named and no-named group captured.
37        const REGEX_OPTION_CAPTURE_GROUP
38            = onig_sys::ONIG_OPTION_CAPTURE_GROUP;
39    }
40}
41
42bitflags! {
43    /// Regex evaluation options.
44    pub struct SearchOptions: onig_sys::OnigOptionType {
45        /// Default options.
46        const SEARCH_OPTION_NONE
47            = onig_sys::ONIG_OPTION_NONE;
48        /// String head isn't considered as begin of line.
49        const SEARCH_OPTION_NOTBOL
50            = onig_sys::ONIG_OPTION_NOTBOL;
51        /// String end isn't considered as end of line.
52        const SEARCH_OPTION_NOTEOL
53            = onig_sys::ONIG_OPTION_NOTEOL;
54    }
55}
56
57bitflags! {
58    /// Defines the different operators allowed within a regex syntax.
59    pub struct SyntaxOperator: u64 {
60        /// `.`
61        const SYNTAX_OPERATOR_DOT_ANYCHAR
62            = (onig_sys::ONIG_SYN_OP_DOT_ANYCHAR as u64);
63        /// `*`
64        const SYNTAX_OPERATOR_ASTERISK_ZERO_INF
65            = (onig_sys::ONIG_SYN_OP_ASTERISK_ZERO_INF as u64);
66        /// `+`
67        const SYNTAX_OPERATOR_PLUS_ONE_INF
68            = (onig_sys::ONIG_SYN_OP_PLUS_ONE_INF as u64);
69        /// `?`
70        const SYNTAX_OPERATOR_QMARK_ZERO_ONE
71            = (onig_sys::ONIG_SYN_OP_QMARK_ZERO_ONE as u64);
72    /// ?P
73    const SYNTAX_OPERATOR_QMARK_CAPITAL_P_NAME
74        = (onig_sys::ONIG_SYN_OP2_QMARK_CAPITAL_P_NAME as u64);
75        /// `{lower,upper}`
76        const SYNTAX_OPERATOR_BRACE_INTERVAL
77            = (onig_sys::ONIG_SYN_OP_BRACE_INTERVAL as u64);
78        /// `\{lower,upper\}`
79        const SYNTAX_OPERATOR_ESC_BRACE_INTERVAL
80            = (onig_sys::ONIG_SYN_OP_ESC_BRACE_INTERVAL as u64);
81        /// `|`
82        const SYNTAX_OPERATOR_VBAR_ALT
83            = (onig_sys::ONIG_SYN_OP_VBAR_ALT as u64);
84        /// `\|`
85        const SYNTAX_OPERATOR_ESC_VBAR_ALT
86            = (onig_sys::ONIG_SYN_OP_ESC_VBAR_ALT as u64);
87        /// `(...)`
88        const SYNTAX_OPERATOR_LPAREN_SUBEXP
89            = (onig_sys::ONIG_SYN_OP_LPAREN_SUBEXP as u64);
90        /// `\(...\)`
91        const SYNTAX_OPERATOR_ESC_LPAREN_SUBEXP
92            = (onig_sys::ONIG_SYN_OP_ESC_LPAREN_SUBEXP as u64);
93        /// `\A, \Z, \z`
94        const SYNTAX_OPERATOR_ESC_AZ_BUF_ANCHOR
95            = (onig_sys::ONIG_SYN_OP_ESC_AZ_BUF_ANCHOR as u64);
96        /// `\G`
97        const SYNTAX_OPERATOR_ESC_CAPITAL_G_BEGIN_ANCHOR
98            = (onig_sys::ONIG_SYN_OP_ESC_CAPITAL_G_BEGIN_ANCHOR as u64);
99        /// `\num`
100        const SYNTAX_OPERATOR_DECIMAL_BACKREF
101            = (onig_sys::ONIG_SYN_OP_DECIMAL_BACKREF as u64);
102        /// `[...]`
103        const SYNTAX_OPERATOR_BRACKET_CC
104            = (onig_sys::ONIG_SYN_OP_BRACKET_CC as u64);
105        /// `\w, \W`
106        const SYNTAX_OPERATOR_ESC_W_WORD
107            = (onig_sys::ONIG_SYN_OP_ESC_W_WORD as u64);
108        /// `\<. \>`
109        const SYNTAX_OPERATOR_ESC_LTGT_WORD_BEGIN_END
110            = (onig_sys::ONIG_SYN_OP_ESC_LTGT_WORD_BEGIN_END as u64);
111        /// `\b, \B`
112        const SYNTAX_OPERATOR_ESC_B_WORD_BOUND
113            = (onig_sys::ONIG_SYN_OP_ESC_B_WORD_BOUND as u64);
114        /// `\s, \S`
115        const SYNTAX_OPERATOR_ESC_S_WHITE_SPACE
116            = (onig_sys::ONIG_SYN_OP_ESC_S_WHITE_SPACE as u64);
117        /// `\d, \D`
118        const SYNTAX_OPERATOR_ESC_D_DIGIT
119            = (onig_sys::ONIG_SYN_OP_ESC_D_DIGIT as u64);
120        /// `^, $`
121        const SYNTAX_OPERATOR_LINE_ANCHOR
122            = (onig_sys::ONIG_SYN_OP_LINE_ANCHOR as u64);
123        /// `[:xxxx:]`
124        const SYNTAX_OPERATOR_POSIX_BRACKET
125            = (onig_sys::ONIG_SYN_OP_POSIX_BRACKET as u64);
126        /// `??,*?,+?,{n,m}?`
127        const SYNTAX_OPERATOR_QMARK_NON_GREEDY
128            = (onig_sys::ONIG_SYN_OP_QMARK_NON_GREEDY as u64);
129        /// `\n,\r,\t,\a ...`
130        const SYNTAX_OPERATOR_ESC_CONTROL_CHARS
131            = (onig_sys::ONIG_SYN_OP_ESC_CONTROL_CHARS as u64);
132        /// `\cx`
133        const SYNTAX_OPERATOR_ESC_C_CONTROL
134            = (onig_sys::ONIG_SYN_OP_ESC_C_CONTROL as u64);
135        /// `\OOO`
136        const SYNTAX_OPERATOR_ESC_OCTAL3
137            = (onig_sys::ONIG_SYN_OP_ESC_OCTAL3 as u64);
138        /// `\xHH`
139        const SYNTAX_OPERATOR_ESC_X_HEX2
140            = (onig_sys::ONIG_SYN_OP_ESC_X_HEX2 as u64);
141        /// `\x{7HHHHHHH}`
142        const SYNTAX_OPERATOR_ESC_X_BRACE_HEX8
143            = (onig_sys::ONIG_SYN_OP_ESC_X_BRACE_HEX8 as u64);
144        /// Variable meta characters
145        const SYNTAX_OPERATOR_VARIABLE_META_CHARACTERS
146            = (onig_sys::ONIG_SYN_OP_VARIABLE_META_CHARACTERS as u64);
147        /// `\Q...\E`
148        const SYNTAX_OPERATOR_ESC_CAPITAL_Q_QUOTE
149            = (onig_sys::ONIG_SYN_OP2_ESC_CAPITAL_Q_QUOTE as u64) << 32;
150        /// `(?...)`
151        const SYNTAX_OPERATOR_QMARK_GROUP_EFFECT
152            = (onig_sys::ONIG_SYN_OP2_QMARK_GROUP_EFFECT as u64) << 32;
153        /// `(?imsx),(?-imsx)`
154        const SYNTAX_OPERATOR_OPTION_PERL
155            = (onig_sys::ONIG_SYN_OP2_OPTION_PERL as u64) << 32;
156        /// `(?imx), (?-imx)`
157        const SYNTAX_OPERATOR_OPTION_RUBY
158            = (onig_sys::ONIG_SYN_OP2_OPTION_RUBY as u64) << 32;
159        /// `?+,*+,++`
160        const SYNTAX_OPERATOR_PLUS_POSSESSIVE_REPEAT
161            = (onig_sys::ONIG_SYN_OP2_PLUS_POSSESSIVE_REPEAT as u64) << 32;
162        /// `{n,m}+`
163        const SYNTAX_OPERATOR_PLUS_POSSESSIVE_INTERVAL
164            = (onig_sys::ONIG_SYN_OP2_PLUS_POSSESSIVE_INTERVAL as u64) << 32;
165        /// `[...&&..[..]..]`
166        const SYNTAX_OPERATOR_CCLASS_SET_OP
167            = (onig_sys::ONIG_SYN_OP2_CCLASS_SET_OP as u64) << 32;
168        /// `(?<name>...)`
169        const SYNTAX_OPERATOR_QMARK_LT_NAMED_GROUP
170            = (onig_sys::ONIG_SYN_OP2_QMARK_LT_NAMED_GROUP as u64) << 32;
171        /// `\k<name>`
172        const SYNTAX_OPERATOR_ESC_K_NAMED_BACKREF
173            = (onig_sys::ONIG_SYN_OP2_ESC_K_NAMED_BACKREF as u64) << 32;
174        /// `\g<name>, \g<n>`
175        const SYNTAX_OPERATOR_ESC_G_SUBEXP_CALL
176            = (onig_sys::ONIG_SYN_OP2_ESC_G_SUBEXP_CALL as u64) << 32;
177        /// `(?@..),(?@<x>..)`
178        const SYNTAX_OPERATOR_ATMARK_CAPTURE_HISTORY
179            = (onig_sys::ONIG_SYN_OP2_ATMARK_CAPTURE_HISTORY as u64) << 32;
180        /// `\C-x`
181        const SYNTAX_OPERATOR_ESC_CAPITAL_C_BAR_CONTROL
182            = (onig_sys::ONIG_SYN_OP2_ESC_CAPITAL_C_BAR_CONTROL as u64) << 32;
183        /// `\M-x`
184        const SYNTAX_OPERATOR_ESC_CAPITAL_M_BAR_META
185            = (onig_sys::ONIG_SYN_OP2_ESC_CAPITAL_M_BAR_META as u64) << 32;
186        /// `\v as VTAB`
187        const SYNTAX_OPERATOR_ESC_V_VTAB
188            = (onig_sys::ONIG_SYN_OP2_ESC_V_VTAB as u64) << 32;
189        /// `\uHHHH`
190        const SYNTAX_OPERATOR_ESC_U_HEX4
191            = (onig_sys::ONIG_SYN_OP2_ESC_U_HEX4 as u64) << 32;
192        /// `\`, \'`
193        const SYNTAX_OPERATOR_ESC_GNU_BUF_ANCHOR
194            = (onig_sys::ONIG_SYN_OP2_ESC_GNU_BUF_ANCHOR as u64) << 32;
195        /// `\p{...}, \P{...}`
196        const SYNTAX_OPERATOR_ESC_P_BRACE_CHAR_PROPERTY
197            = (onig_sys::ONIG_SYN_OP2_ESC_P_BRACE_CHAR_PROPERTY as u64) << 32;
198        /// `\p{^..}, \P{^..}`
199        const SYNTAX_OPERATOR_ESC_P_BRACE_CIRCUMFLEX_NOT
200            = (onig_sys::ONIG_SYN_OP2_ESC_P_BRACE_CIRCUMFLEX_NOT as u64) << 32;
201        /// `\h, \H`
202        const SYNTAX_OPERATOR_ESC_H_XDIGIT
203            = (onig_sys::ONIG_SYN_OP2_ESC_H_XDIGIT as u64) << 32;
204        /// `\`
205        const SYNTAX_OPERATOR_INEFFECTIVE_ESCAPE
206            = (onig_sys::ONIG_SYN_OP2_INEFFECTIVE_ESCAPE as u64) << 32;
207    }
208}
209
210bitflags! {
211    /// Defines the behaviour of regex operators.
212    pub struct SyntaxBehavior: onig_sys::OnigSyntaxBehavior {
213        /// `?, *, +, {n,m}`
214        const SYNTAX_BEHAVIOR_CONTEXT_INDEP_REPEAT_OPS
215            = onig_sys::ONIG_SYN_CONTEXT_INDEP_REPEAT_OPS;
216        /// `error or ignore`
217        const SYNTAX_BEHAVIOR_CONTEXT_INVALID_REPEAT_OPS
218            = onig_sys::ONIG_SYN_CONTEXT_INVALID_REPEAT_OPS;
219        /// `...)...`
220        const SYNTAX_BEHAVIOR_ALLOW_UNMATCHED_CLOSE_SUBEXP
221            = onig_sys::ONIG_SYN_ALLOW_UNMATCHED_CLOSE_SUBEXP;
222        /// `{???`
223        const SYNTAX_BEHAVIOR_ALLOW_INVALID_INTERVAL
224            = onig_sys::ONIG_SYN_ALLOW_INVALID_INTERVAL;
225        /// `{,n} => {0,n}`
226        const SYNTAX_BEHAVIOR_ALLOW_INTERVAL_LOW_ABBREV
227            = onig_sys::ONIG_SYN_ALLOW_INTERVAL_LOW_ABBREV;
228        /// `/(\1)/,/\1()/ ..`
229        const SYNTAX_BEHAVIOR_STRICT_CHECK_BACKREF
230            = onig_sys::ONIG_SYN_STRICT_CHECK_BACKREF;
231        /// `(?<=a|bc)`
232        const SYNTAX_BEHAVIOR_DIFFERENT_LEN_ALT_LOOK_BEHIND
233            = onig_sys::ONIG_SYN_DIFFERENT_LEN_ALT_LOOK_BEHIND;
234        /// See Oniguruma documenation
235        const SYNTAX_BEHAVIOR_CAPTURE_ONLY_NAMED_GROUP
236            = onig_sys::ONIG_SYN_CAPTURE_ONLY_NAMED_GROUP;
237        /// `(?<x>)(?<x>)`
238        const SYNTAX_BEHAVIOR_ALLOW_MULTIPLEX_DEFINITION_NAME
239            = onig_sys::ONIG_SYN_ALLOW_MULTIPLEX_DEFINITION_NAME;
240        /// `a{n}?=(?:a{n})?`
241        const SYNTAX_BEHAVIOR_FIXED_INTERVAL_IS_GREEDY_ONLY
242            = onig_sys::ONIG_SYN_FIXED_INTERVAL_IS_GREEDY_ONLY;
243        /// `[^...]`
244        const SYNTAX_BEHAVIOR_NOT_NEWLINE_IN_NEGATIVE_CC
245            = onig_sys::ONIG_SYN_NOT_NEWLINE_IN_NEGATIVE_CC;
246        /// `[..\w..] etc..`
247        const SYNTAX_BEHAVIOR_BACKSLASH_ESCAPE_IN_CC
248            = onig_sys::ONIG_SYN_BACKSLASH_ESCAPE_IN_CC;
249        /// `[0-9-a]=[0-9\-a]`
250        const SYNTAX_BEHAVIOR_ALLOW_DOUBLE_RANGE_OP_IN_CC
251            = onig_sys::ONIG_SYN_ALLOW_DOUBLE_RANGE_OP_IN_CC;
252        /// `[,-,]`
253        const SYNTAX_BEHAVIOR_WARN_CC_OP_NOT_ESCAPED
254            = onig_sys::ONIG_SYN_WARN_CC_OP_NOT_ESCAPED;
255        /// `(?:a*)+`
256        const SYNTAX_BEHAVIOR_WARN_REDUNDANT_NESTED_REPEAT
257            = onig_sys::ONIG_SYN_WARN_REDUNDANT_NESTED_REPEAT;
258    }
259}
260
261bitflags! {
262    /// The order in which traverse callbacks are invoked
263    pub struct TraverseCallbackAt: c_uint {
264        /// Callback before children are wallked
265        const CALLBACK_AT_FIRST =
266            onig_sys::ONIG_TRAVERSE_CALLBACK_AT_FIRST;
267        /// Callback after children are walked
268        const CALLBACK_AT_LAST =
269            onig_sys::ONIG_TRAVERSE_CALLBACK_AT_LAST;
270        /// Callback both before and after children are walked.
271        const CALLBACK_AT_BOTH =
272            onig_sys::ONIG_TRAVERSE_CALLBACK_AT_BOTH;
273    }
274}
275
276bitflags! {
277    /// Syntax meta character types
278    pub struct MetaCharType: c_uint {
279        /// The escape charater for this syntax
280        const META_CHAR_ESCAPE = onig_sys::ONIG_META_CHAR_ESCAPE;
281        /// The any (.) character for this syntax.
282        const META_CHAR_ANYCHAR =  onig_sys::ONIG_META_CHAR_ANYCHAR;
283        /// The any number of repeats (*) character for this syntax.
284        const META_CHAR_ANYTIME =  onig_sys::ONIG_META_CHAR_ANYTIME;
285        /// The optinoal (?) chracter for this syntax
286        const META_CHAR_ZERO_OR_ONE_TIME =  onig_sys::ONIG_META_CHAR_ZERO_OR_ONE_TIME;
287        /// The at least once (+) character for this syntax
288        const META_CHAR_ONE_OR_MORE_TIME =  onig_sys::ONIG_META_CHAR_ONE_OR_MORE_TIME;
289        /// The glob character for this syntax (.*)
290        const META_CHAR_ANYCHAR_ANYTIME =  onig_sys::ONIG_META_CHAR_ANYCHAR_ANYTIME;
291    }
292}