Fix multiline RegEx iteration

In `.Multiline` mode:

- `^` is now defined to assert the start of the string or that a "\n" or
  "\r" rune was parsed on last VM dispatch.

- `$` is now defined to consume a newline sequence of "\n", "\r", or
  "\r\n" or to assert the end of the string.
This commit is contained in:
Feoramund
2025-05-26 14:48:45 -04:00
parent 4f7ed35435
commit 35b157ac83
6 changed files with 113 additions and 53 deletions
+7 -3
View File
@@ -195,8 +195,12 @@ generate_code :: proc(c: ^Compiler, node: Node) -> (code: Program) {
case ^Node_Anchor:
if .Multiline in c.flags {
append(&code, Opcode.Multiline_Open)
append(&code, Opcode.Multiline_Close)
if specific.start {
append(&code, Opcode.Assert_Start_Multiline)
} else {
append(&code, Opcode.Multiline_Open)
append(&code, Opcode.Multiline_Close)
}
} else {
if specific.start {
append(&code, Opcode.Assert_Start)
@@ -439,7 +443,7 @@ compile :: proc(tree: Node, flags: common.Flags) -> (code: Program, class_data:
case .Save:
continue
case .Assert_Start:
case .Assert_Start, .Assert_Start_Multiline:
break optimize_opening
case: