common.odin 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // This package helps break dependency cycles.
  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. // Global: try to match the pattern anywhere in the string.
  15. Global,
  16. // Multiline: treat `^` and `$` as if they also match newlines.
  17. Multiline,
  18. // Case Insensitive: treat `a-z` as if it was also `A-Z`.
  19. Case_Insensitive,
  20. // Ignore Whitespace: bypass unescaped whitespace outside of classes.
  21. Ignore_Whitespace,
  22. // Unicode: let the compiler and virtual machine know to expect Unicode strings.
  23. Unicode,
  24. // No Capture: avoid saving capture group data entirely.
  25. No_Capture,
  26. // No Optimization: do not pass the pattern through the optimizer; for debugging.
  27. No_Optimization,
  28. }
  29. Flags :: bit_set[Flag; u8]
  30. @(rodata)
  31. Flag_To_Letter := #sparse[Flag]u8 {
  32. .Global = 'g',
  33. .Multiline = 'm',
  34. .Case_Insensitive = 'i',
  35. .Ignore_Whitespace = 'x',
  36. .Unicode = 'u',
  37. .No_Capture = 'n',
  38. .No_Optimization = '-',
  39. }