-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplification, style consistency, dead code deletion, some bounds-check removal, etc.
- Loading branch information
1 parent
0abaabe
commit 6bb517a
Showing
10 changed files
with
370 additions
and
437 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 33 additions & 9 deletions
42
...stem.Text.RegularExpressions/src/System/Text/RegularExpressions/Symbolic/MatchReversal.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,39 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace System.Text.RegularExpressions.Symbolic; | ||
using System.Diagnostics; | ||
|
||
internal readonly struct MatchReversal<TSet>( | ||
MatchReversalKind kind, | ||
int fixedLength, | ||
MatchingState<TSet>? adjustedStartState = null) | ||
where TSet : IComparable<TSet>, IEquatable<TSet> | ||
namespace System.Text.RegularExpressions.Symbolic | ||
{ | ||
internal MatchReversalKind Kind { get; } = kind; | ||
internal int FixedLength { get; } = fixedLength; | ||
internal MatchingState<TSet>? AdjustedStartState { get; } = adjustedStartState; | ||
/// <summary>Provides details on how a match may be processed in reverse to find the beginning of a match once a match's existence has been confirmed.</summary> | ||
internal readonly struct MatchReversalInfo<TSet> where TSet : IComparable<TSet>, IEquatable<TSet> | ||
{ | ||
/// <summary>Initializes the match reversal details.</summary> | ||
internal MatchReversalInfo(MatchReversalKind kind, int fixedLength, MatchingState<TSet>? adjustedStartState = null) | ||
{ | ||
Debug.Assert(kind is MatchReversalKind.MatchStart or MatchReversalKind.FixedLength or MatchReversalKind.PartialFixedLength); | ||
Debug.Assert(fixedLength >= 0); | ||
Debug.Assert((adjustedStartState is not null) == (kind is MatchReversalKind.PartialFixedLength)); | ||
|
||
Kind = kind; | ||
FixedLength = fixedLength; | ||
AdjustedStartState = adjustedStartState; | ||
} | ||
|
||
/// <summary>Gets the kind of the match reversal processing required.</summary> | ||
internal MatchReversalKind Kind { get; } | ||
|
||
/// <summary>Gets the fixed length of the match, if one is known.</summary> | ||
/// <remarks> | ||
/// For <see cref="MatchReversalKind.MatchStart"/>, this is ignored. | ||
/// For <see cref="MatchReversalKind.FixedLength"/>, this is the full length of the match. The beginning may be found simply | ||
/// by subtracting this length from the end. | ||
/// For <see cref="MatchReversalKind.PartialFixedLength"/>, this is the length of fixed portion of the match. | ||
/// </remarks> | ||
internal int FixedLength { get; } | ||
|
||
/// <summary>Gets the adjusted start state to use for partial fixed-length matches.</summary> | ||
/// <remarks>This will be non-null iff <see cref="Kind"/> is <see cref="MatchReversalKind.PartialFixedLength"/>.</remarks> | ||
internal MatchingState<TSet>? AdjustedStartState { get; } | ||
} | ||
} |
30 changes: 21 additions & 9 deletions
30
....Text.RegularExpressions/src/System/Text/RegularExpressions/Symbolic/MatchReversalKind.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,26 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace System.Text.RegularExpressions.Symbolic; | ||
|
||
internal enum MatchReversalKind | ||
namespace System.Text.RegularExpressions.Symbolic | ||
{ | ||
/// <summary>The most generic option, run the regex backwards to find beginning of match</summary> | ||
MatchStart, | ||
/// <summary>Part of the reversal is fixed length and can be skipped</summary> | ||
PartialFixedLength, | ||
/// <summary>The entire pattern is fixed length, reversal not necessary</summary> | ||
FixedLength | ||
/// <summary>Specifies the kind of a <see cref="MatchReversalInfo{TSet}"/>.</summary> | ||
internal enum MatchReversalKind | ||
{ | ||
/// <summary>The regex should be run in reverse to find beginning of the match.</summary> | ||
MatchStart, | ||
|
||
/// <summary>The end of the pattern is of a fixed length and can be skipped as part of running a regex in reverse to find the beginning of the match.</summary> | ||
/// <remarks> | ||
/// Reverse execution is not necessary for a subset of the match. | ||
/// <see cref="MatchReversalInfo{TSet}.FixedLength"/> will contain the length of the fixed portion. | ||
/// </remarks> | ||
PartialFixedLength, | ||
|
||
/// <summary>The entire pattern is of a fixed length.</summary> | ||
/// <remarks> | ||
/// Reverse execution is not necessary to find the beginning of the match. | ||
/// <see cref="MatchReversalInfo{TSet}.FixedLength"/> will contain the length of the match. | ||
/// </remarks> | ||
FixedLength | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.