未验证 提交 41a624dc 编写于 作者: S Stephen Toub 提交者: GitHub

Augment generated regex XML comment with original pattern and options (#88175)

* Augment generated regex XML comment with original pattern and options

* Delete special-handling of ECMADigitClass for consistency
上级 dd04e019
......@@ -55,12 +55,19 @@ private static void EmitRegexPartialMethod(RegexMethod regexMethod, IndentedText
}
// Emit the partial method definition.
writer.WriteLine("/// <remarks>");
writer.WriteLine("/// Pattern explanation:<br/>");
writer.WriteLine("/// <code>");
writer.WriteLine($"/// <remarks>");
writer.WriteLine($"/// Pattern:<br/>");
writer.WriteLine($"/// <code>{EscapeXmlComment(Literal(regexMethod.Pattern, quote: false))}</code><br/>");
if (regexMethod.Options != RegexOptions.None)
{
writer.WriteLine($"/// Options:<br/>");
writer.WriteLine($"/// <code>{Literal(regexMethod.Options)}</code><br/>");
}
writer.WriteLine($"/// Explanation:<br/>");
writer.WriteLine($"/// <code>");
DescribeExpressionAsXmlComment(writer, regexMethod.Tree.Root.Child(0), regexMethod); // skip implicit root capture
writer.WriteLine("/// </code>");
writer.WriteLine("/// </remarks>");
writer.WriteLine($"/// </code>");
writer.WriteLine($"/// </remarks>");
writer.WriteLine($"[global::System.CodeDom.Compiler.{s_generatedCodeAttribute}]");
writer.WriteLine($"{regexMethod.Modifiers} global::System.Text.RegularExpressions.Regex {regexMethod.MethodName}() => global::{GeneratedNamespace}.{regexMethod.GeneratedName}.Instance;");
......@@ -5084,7 +5091,7 @@ private static void InsertAdditionalDeclarations(IndentedTextWriter writer, Hash
private static string Literal(char c) => SymbolDisplay.FormatLiteral(c, quote: true);
/// <summary>Formats the string as valid C#.</summary>
private static string Literal(string s) => SymbolDisplay.FormatLiteral(s, quote: true);
private static string Literal(string s, bool quote = true) => SymbolDisplay.FormatLiteral(s, quote);
private static string Literal(RegexOptions options)
{
......@@ -5183,11 +5190,9 @@ charClass switch
{
RegexCharClass.AnyClass => "any character",
RegexCharClass.DigitClass => "a Unicode digit",
RegexCharClass.ECMADigitClass => "'0' through '9'",
RegexCharClass.ECMASpaceClass => "a whitespace character (ECMA)",
RegexCharClass.ECMAWordClass => "a word character (ECMA)",
RegexCharClass.NotDigitClass => "any character other than a Unicode digit",
RegexCharClass.NotECMADigitClass => "any character other than '0' through '9'",
RegexCharClass.NotECMASpaceClass => "any character other than a whitespace character (ECMA)",
RegexCharClass.NotECMAWordClass => "any character other than a word character (ECMA)",
RegexCharClass.NotSpaceClass => "any character other than a whitespace character",
......
......@@ -70,7 +70,9 @@ partial class C
partial class C
{
/// <remarks>
/// Pattern explanation:<br/>
/// Pattern:<br/>
/// <code>^(?&lt;proto&gt;\\w+)://[^/]+?(?&lt;port&gt;:\\d+)?/</code><br/>
/// Explanation:<br/>
/// <code>
/// ○ Match if at the beginning of the string.<br/>
/// ○ "proto" capture group.<br/>
......@@ -431,7 +433,9 @@ partial class C
partial class C
{
/// <remarks>
/// Pattern explanation:<br/>
/// Pattern:<br/>
/// <code>href\\s*=\\s*(?:["'](?&lt;1&gt;[^"']*)["']|(?&lt;1&gt;[^&gt;\\s]+))</code><br/>
/// Explanation:<br/>
/// <code>
/// ○ Match the string "href".<br/>
/// ○ Match a whitespace character atomically any number of times.<br/>
......@@ -727,7 +731,9 @@ partial class C
partial class C
{
/// <remarks>
/// Pattern explanation:<br/>
/// Pattern:<br/>
/// <code>[A-Za-z]+</code><br/>
/// Explanation:<br/>
/// <code>
/// ○ Match a character in the set [A-Za-z] atomically at least once.<br/>
/// </code>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册