From 9e26507631b7503a4aff0f8e7288e72a557947fc Mon Sep 17 00:00:00 2001 From: Serhei Makarov Date: Mon, 22 Nov 2021 15:15:57 -0500 Subject: [PATCH] PR28618 stapregex: allow non-capturing group --- stapregex-parse.cxx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/stapregex-parse.cxx b/stapregex-parse.cxx index b7893fca7..d227faeb2 100644 --- a/stapregex-parse.cxx +++ b/stapregex-parse.cxx @@ -295,15 +295,27 @@ regex_parser::parse_factor () } else if (c == '(') { + // Allow non-capturing group (?:...) + bool do_tag_now = do_tag; + rchar c2 = cur.peek(); + if (c2 == '?') + { + cur.next(); + rchar c3 = cur.peek(); + if (c3 != ':') + parse_error(_F("unexpected '(?%c'", c3)); + do_tag_now = false; + } + // To number tags correctly, reserve a subexpression number here: unsigned curr_subexpression = 0; - if (do_tag) + if (do_tag_now) curr_subexpression = num_subexpressions++; result = parse_expr (); // PR15065 glom appropriate tag_ops onto the expr - if (do_tag) { + if (do_tag_now) { result = new cat_op(new tag_op(TAG_START(curr_subexpression)), result); result = new cat_op(result, new tag_op(TAG_END(curr_subexpression))); } else { -- 2.43.5