From 6809bb77f35151ff1a6081a354344c285c293903 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Mon, 22 Nov 2021 20:50:39 -0500 Subject: [PATCH] Address PR feedback --- .../gen/RegexGenerator.Emitter.cs | 6 ++-- .../tests/Regex.KnownPattern.Tests.cs | 34 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Emitter.cs b/src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Emitter.cs index 689d6985667b9..44493b4b59108 100644 --- a/src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Emitter.cs +++ b/src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Emitter.cs @@ -783,7 +783,7 @@ string ReserveName(string prefix) // Emit failure writer.WriteLine("// No match"); - MarkLabel(originalDoneLabel); + MarkLabel(originalDoneLabel, emitSemicolon: !expressionHasCaptures); if (expressionHasCaptures) { EmitUncaptureUntil("0"); @@ -1156,7 +1156,7 @@ void EmitExpressionConditional(RegexNode node) // Emit the no branch, first uncapturing any captures from the expression condition that failed // to match and emit the branch. - MarkLabel(no); + MarkLabel(no, emitSemicolon: startingCrawlPos is null); if (startingCrawlPos is not null) { EmitUncaptureUntil(startingCrawlPos); @@ -1252,7 +1252,7 @@ void EmitNegativeLookaheadAssertion(RegexNode node) writer.WriteLine($"goto {originalDoneLabel};"); // Failures (success for a negative lookahead) jump here. - MarkLabel(negativeLookaheadDoneLabel); + MarkLabel(negativeLookaheadDoneLabel, emitSemicolon: false); Debug.Assert(doneLabel == negativeLookaheadDoneLabel); doneLabel = originalDoneLabel; diff --git a/src/libraries/System.Text.RegularExpressions/tests/Regex.KnownPattern.Tests.cs b/src/libraries/System.Text.RegularExpressions/tests/Regex.KnownPattern.Tests.cs index 32784a07064ca..b53526645705f 100644 --- a/src/libraries/System.Text.RegularExpressions/tests/Regex.KnownPattern.Tests.cs +++ b/src/libraries/System.Text.RegularExpressions/tests/Regex.KnownPattern.Tests.cs @@ -1159,14 +1159,14 @@ public async Task Blog_Levithan_BalancingGroups_MatchingParentheses(RegexEngine } Regex r = await RegexHelpers.GetRegexAsync(engine, @"^\( - (?> - [^()]+ - | - \( (?) - | - \) (?<-Depth>) - )* - (?(Depth)(?!)) + (?> + [^()]+ + | + \( (?) + | + \) (?<-Depth>) + )* + (?(Depth)(?!)) \)$", RegexOptions.IgnorePatternWhitespace); Assert.True(r.IsMatch("()")); @@ -1190,15 +1190,15 @@ public async Task Blog_Levithan_BalancingGroups_WordLengthIncreases(RegexEngine } Regex r = await RegexHelpers.GetRegexAsync(engine, @"^(?: - (?(A)\s|) - (?) - (?\w)+ (?(B)(?!)) - (?: - \s - (?) - (?\w)+ (?(C)(?!)) - (?) - )? + (?(A)\s|) + (?) + (?\w)+ (?(B)(?!)) + (?: + \s + (?) + (?\w)+ (?(C)(?!)) + (?) + )? )+ \b$", RegexOptions.IgnorePatternWhitespace); Assert.True(r.IsMatch("a bc def ghij klmni"));