swiftlang / swift-experimental-string-processing

An early experimental general-purpose pattern matching engine for Swift.
Apache License 2.0
278 stars 47 forks source link

Allow captures during lookahead #723

Closed natecook1000 closed 7 months ago

natecook1000 commented 8 months ago

This fixes an issue where capture groups inside a positive lookahead were being reset even upon successful matching of the lookahead. For example, with the pattern /(?=(\d))/, matching against a string like "abc1" should result in the output ("", "1"). However, accessing the output traps instead, since the range data for capture 1 is missing even on success.

This change resolves the issue by adding a boolean payload to the fail instruction that indicates whether to preserve captures when resetting the matching state, which allows any captures inside a lookahead to persist after success.

Fixes #713.

natecook1000 commented 7 months ago

@swift-ci Please test