Skip to content

Commit

Permalink
regex: Fix bare OR not being properly grouped (fixes #3)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonLydike committed Jul 12, 2024
1 parent 716e954 commit 1c374d1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 6 additions & 1 deletion filecheck/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions tests/filecheck/regex.test
Original file line number Diff line number Diff line change
Expand Up @@ -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}}

0 comments on commit 1c374d1

Please sign in to comment.