From 1c374d10147a912112272a4b2e2a21faa1dcc895 Mon Sep 17 00:00:00 2001 From: Anton Lydike Date: Fri, 12 Jul 2024 19:00:19 +0100 Subject: [PATCH] regex: Fix bare OR not being properly grouped (fixes #3) --- filecheck/compiler.py | 7 ++++++- tests/filecheck/regex.test | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/filecheck/compiler.py b/filecheck/compiler.py index e0abd67..ada4ae0 100644 --- a/filecheck/compiler.py +++ b/filecheck/compiler.py @@ -49,7 +49,12 @@ def compile_uops( # count number of capture groups by counting unescaped brackets groups += len(UNESCAPED_BRACKETS.findall(uop.content)) - expr.append(uop.content) + # add brackets sorrounding patterns that contain ORs (fixes #3) + if "|" in uop.content: + expr.append(f"({uop.content})") + groups += 1 + else: + expr.append(uop.content) elif isinstance(uop, Capture): # record the group we capture in the dictionary captures[uop.name] = (groups + 1, uop.value_mapper) diff --git a/tests/filecheck/regex.test b/tests/filecheck/regex.test index 85176af..5c96031 100644 --- a/tests/filecheck/regex.test +++ b/tests/filecheck/regex.test @@ -11,3 +11,6 @@ test 123 // CHECK: test [[VAR:[^ ,]+]] test 123, 123 // CHECK: test [[VAR]], [[VAR]] + +test a b +// CHECK: test {{a|b}} {{b|c}}