Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2549,7 +2549,7 @@ void EmitCapture(RegexNode node, RegexNode? subsequent = null)
}
else
{
writer.WriteLine($"base.TransferCapture({capnum}, {uncapnum}, {startingPos}, pos);");
writer.WriteLine($"base.TransferCapture({capnum.ToString(CultureInfo.InvariantCulture)}, {uncapnum}, {startingPos}, pos);");
}

if (isAtomic || !childBacktracks)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ internal static async Task<Regex> SourceGenRegexAsync(
return results[0];
}

private static readonly CultureInfo s_cultureWithMinusNegativeSign = new CultureInfo("")
{
// To validate that generation still succeeds even when something other than '-' is used.
NumberFormat = new NumberFormatInfo() { NegativeSign = $"{(char)0x2212}" }
};

internal static async Task<Regex[]> SourceGenRegexAsync(
(string pattern, CultureInfo? culture, RegexOptions? options, TimeSpan? matchTimeout)[] regexes, CancellationToken cancellationToken = default)
{
Expand Down Expand Up @@ -214,13 +220,24 @@ internal static async Task<Regex[]> SourceGenRegexAsync(
comp = comp.ReplaceSyntaxTree(comp.SyntaxTrees.First(), CSharpSyntaxTree.ParseText(SourceText.From(code.ToString(), Encoding.UTF8), s_previewParseOptions));

// Run the generator
GeneratorDriverRunResult generatorResults = s_generatorDriver.RunGenerators(comp!, cancellationToken).GetRunResult();
ImmutableArray<Diagnostic> generatorDiagnostics = generatorResults.Diagnostics.RemoveAll(d => d.Severity <= DiagnosticSeverity.Hidden);
if (generatorDiagnostics.Length != 0)
CultureInfo origCulture = CultureInfo.CurrentCulture;
CultureInfo.CurrentCulture = s_cultureWithMinusNegativeSign;
GeneratorDriverRunResult generatorResults;
ImmutableArray<Diagnostic> generatorDiagnostics;
try
{
throw new ArgumentException(
string.Join(Environment.NewLine, generatorResults.GeneratedTrees.Select(t => NumberLines(t.ToString()))) + Environment.NewLine +
string.Join(Environment.NewLine, generatorDiagnostics));
generatorResults = s_generatorDriver.RunGenerators(comp!, cancellationToken).GetRunResult();
generatorDiagnostics = generatorResults.Diagnostics.RemoveAll(d => d.Severity <= DiagnosticSeverity.Hidden);
if (generatorDiagnostics.Length != 0)
{
throw new ArgumentException(
string.Join(Environment.NewLine, generatorResults.GeneratedTrees.Select(t => NumberLines(t.ToString()))) + Environment.NewLine +
string.Join(Environment.NewLine, generatorDiagnostics));
}
}
finally
{
CultureInfo.CurrentCulture = origCulture;
}

// Compile the assembly to a stream
Expand Down
Loading