aboutsummaryrefslogtreecommitdiff
path: root/core/text/regex/common/common.odin
blob: cfbbe53ba85295188c146f8fa96d7ddfffd1714f (plain)
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
// This package helps break dependency cycles for the regular expression engine.
package regex_common

/*
	(c) Copyright 2024 Feoramund <rune@swevencraft.org>.
	Made available under Odin's license.

	List of contributors:
		Feoramund: Initial implementation.
*/

// VM limitations
MAX_CAPTURE_GROUPS :: max(#config(ODIN_REGEX_MAX_CAPTURE_GROUPS, 10), 10)
MAX_PROGRAM_SIZE   :: int(max(i16))
MAX_CLASSES        :: int(max(u8))

ODIN_DEBUG_REGEX :: #config(ODIN_DEBUG_REGEX, false)

Flag :: enum u8 {
	// Multiline: treat `^` and `$` as if they also match newlines.
	Multiline,
	// Case Insensitive: treat `a-z` as if it was also `A-Z`.
	Case_Insensitive,
	// Ignore Whitespace: bypass unescaped whitespace outside of classes.
	Ignore_Whitespace,
	// Unicode: let the compiler and virtual machine know to expect Unicode strings.
	Unicode,

	// No Capture: avoid saving capture group data entirely.
	No_Capture,
	// No Optimization: do not pass the pattern through the optimizer; for debugging.
	No_Optimization,
}

Flags :: bit_set[Flag; u8]

@(rodata)
Flag_To_Letter := #sparse[Flag]u8 {
	.Multiline         = 'm',
	.Case_Insensitive  = 'i',
	.Ignore_Whitespace = 'x',
	.Unicode           = 'u',
	.No_Capture        = 'n',
	.No_Optimization   = '-',
}