aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorFeoramund <161657516+Feoramund@users.noreply.github.com>2025-05-24 06:02:50 -0400
committerFeoramund <161657516+Feoramund@users.noreply.github.com>2025-05-24 07:42:04 -0400
commit37d6491300269502341d7f5ea455ae089a36ce06 (patch)
treea4333515cb43f2a34e802e36a953de4324272c95 /core
parentfedb9efb413dda3f2d9d4bbb39050219f8c0f394 (diff)
Remove `Global` RegEx flag, default to unanchored patterns
Diffstat (limited to 'core')
-rw-r--r--core/text/regex/common/common.odin3
-rw-r--r--core/text/regex/compiler/compiler.odin14
-rw-r--r--core/text/regex/regex.odin4
3 files changed, 9 insertions, 12 deletions
diff --git a/core/text/regex/common/common.odin b/core/text/regex/common/common.odin
index 4a303e0a3..e60bef58f 100644
--- a/core/text/regex/common/common.odin
+++ b/core/text/regex/common/common.odin
@@ -15,8 +15,6 @@ MAX_PROGRAM_SIZE :: int(max(i16))
MAX_CLASSES :: int(max(u8))
Flag :: enum u8 {
- // Global: try to match the pattern anywhere in the string.
- Global,
// Multiline: treat `^` and `$` as if they also match newlines.
Multiline,
// Case Insensitive: treat `a-z` as if it was also `A-Z`.
@@ -36,7 +34,6 @@ Flags :: bit_set[Flag; u8]
@(rodata)
Flag_To_Letter := #sparse[Flag]u8 {
- .Global = 'g',
.Multiline = 'm',
.Case_Insensitive = 'i',
.Ignore_Whitespace = 'x',
diff --git a/core/text/regex/compiler/compiler.odin b/core/text/regex/compiler/compiler.odin
index b3ded0104..07ace7b5d 100644
--- a/core/text/regex/compiler/compiler.odin
+++ b/core/text/regex/compiler/compiler.odin
@@ -401,7 +401,7 @@ compile :: proc(tree: Node, flags: common.Flags) -> (code: Program, class_data:
pc_open := 0
- add_global: if .Global in flags {
+ optimize_opening: {
// Check if the opening to the pattern is predictable.
// If so, use one of the optimized Wait opcodes.
iter := virtual_machine.Opcode_Iterator{ code[:], 0 }
@@ -412,7 +412,7 @@ compile :: proc(tree: Node, flags: common.Flags) -> (code: Program, class_data:
pc_open += size_of(Opcode)
inject_at(&code, pc_open, Opcode(code[pc + size_of(Opcode) + pc_open]))
pc_open += size_of(u8)
- break add_global
+ break optimize_opening
case .Rune:
operand := intrinsics.unaligned_load(cast(^rune)&code[pc+1])
@@ -420,24 +420,28 @@ compile :: proc(tree: Node, flags: common.Flags) -> (code: Program, class_data:
pc_open += size_of(Opcode)
inject_raw(&code, pc_open, operand)
pc_open += size_of(rune)
- break add_global
+ break optimize_opening
case .Rune_Class:
inject_at(&code, pc_open, Opcode.Wait_For_Rune_Class)
pc_open += size_of(Opcode)
inject_at(&code, pc_open, Opcode(code[pc + size_of(Opcode) + pc_open]))
pc_open += size_of(u8)
- break add_global
+ break optimize_opening
case .Rune_Class_Negated:
inject_at(&code, pc_open, Opcode.Wait_For_Rune_Class_Negated)
pc_open += size_of(Opcode)
inject_at(&code, pc_open, Opcode(code[pc + size_of(Opcode) + pc_open]))
pc_open += size_of(u8)
- break add_global
+ break optimize_opening
case .Save:
continue
+
+ case .Assert_Start:
+ break optimize_opening
+
case:
break seek_loop
}
diff --git a/core/text/regex/regex.odin b/core/text/regex/regex.odin
index 90aa34946..94a4b163a 100644
--- a/core/text/regex/regex.odin
+++ b/core/text/regex/regex.odin
@@ -167,7 +167,6 @@ to escape the delimiter if found in the middle of the string.
All runes after the closing delimiter will be parsed as flags:
-- 'g': Global
- 'm': Multiline
- 'i': Case_Insensitive
- 'x': Ignore_Whitespace
@@ -244,7 +243,6 @@ create_by_user :: proc(
// to `end` here.
for r in pattern[start + end:] {
switch r {
- case 'g': flags += { .Global }
case 'm': flags += { .Multiline }
case 'i': flags += { .Case_Insensitive }
case 'x': flags += { .Ignore_Whitespace }
@@ -283,8 +281,6 @@ create_iterator :: proc(
permanent_allocator := context.allocator,
temporary_allocator := context.temp_allocator,
) -> (result: Match_Iterator, err: Error) {
- flags := flags
- flags += {.Global} // We're iterating over a string, so the next match could start anywhere
if .Multiline in flags {
return {}, .Unsupported_Flag