common.odin 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // This package helps break dependency cycles for the regular expression engine.
  2. package regex_common
  3. /*
  4. (c) Copyright 2024 Feoramund <[email protected]>.
  5. Made available under Odin's BSD-3 license.
  6. List of contributors:
  7. Feoramund: Initial implementation.
  8. */
  9. // VM limitations
  10. MAX_CAPTURE_GROUPS :: max(#config(ODIN_REGEX_MAX_CAPTURE_GROUPS, 10), 10)
  11. MAX_PROGRAM_SIZE :: int(max(i16))
  12. MAX_CLASSES :: int(max(u8))
  13. Flag :: enum u8 {
  14. // Multiline: treat `^` and `$` as if they also match newlines.
  15. Multiline,
  16. // Case Insensitive: treat `a-z` as if it was also `A-Z`.
  17. Case_Insensitive,
  18. // Ignore Whitespace: bypass unescaped whitespace outside of classes.
  19. Ignore_Whitespace,
  20. // Unicode: let the compiler and virtual machine know to expect Unicode strings.
  21. Unicode,
  22. // No Capture: avoid saving capture group data entirely.
  23. No_Capture,
  24. // No Optimization: do not pass the pattern through the optimizer; for debugging.
  25. No_Optimization,
  26. }
  27. Flags :: bit_set[Flag; u8]
  28. @(rodata)
  29. Flag_To_Letter := #sparse[Flag]u8 {
  30. .Multiline = 'm',
  31. .Case_Insensitive = 'i',
  32. .Ignore_Whitespace = 'x',
  33. .Unicode = 'u',
  34. .No_Capture = 'n',
  35. .No_Optimization = '-',
  36. }