scanning min scan length

This commit is contained in:
Youmu Liu
2026-07-08 18:25:05 +08:00
parent 439128798e
commit 29b24191e1
8 changed files with 125 additions and 93 deletions
+23 -6
View File
@@ -26,7 +26,9 @@ namespace StgSharp.RegularAnalysis.Text
AbstractSyntaxTree<RegexAstNode, RegexElementLabel> ast,
List<RegexIR> base_ir,
List<RegexIR> ir,
RegexInfo info,
Exception? analyseException = null
)
{
Pattern = pattern;
@@ -34,6 +36,7 @@ namespace StgSharp.RegularAnalysis.Text
IRs = ir;
BaseIR = base_ir;
AnalyseException = analyseException;
Info = info;
}
public Exception? AnalyseException { get; set; }
@@ -46,6 +49,8 @@ namespace StgSharp.RegularAnalysis.Text
internal List<RegexIR> IRs { get; }
internal RegexInfo Info { get; }
}
public static partial class RegexAnalyzer
@@ -55,10 +60,11 @@ namespace StgSharp.RegularAnalysis.Text
string regex
)
{
#pragma warning disable CA1031
#pragma warning disable CA1031
// RegexAnalyzer interpreter = new();
// interpreter._source = regex;
AbstractSyntaxTree<RegexAstNode, RegexElementLabel> tree;
RegexInfo info = new();
try
{
tree = GenerateAST(regex);
@@ -66,29 +72,40 @@ namespace StgSharp.RegularAnalysis.Text
}
catch (Exception ex)
{
return new TextRegexSource(regex, null, null, null, ex);
return new TextRegexSource(regex, null, null, null, info, ex);
}
List<RegexIR> base_ir;
try
{
base_ir = GenerateIR(tree);
base_ir = GenerateIR(tree, ref info);
}
catch (Exception ex)
{
return new TextRegexSource(regex, tree, null, null, ex);
return new TextRegexSource(regex, tree, null, null, info, ex);
}
try
{
ScanAndOptimizeIR(base_ir, out List<RegexIR> opt_ir);
List<RegexIR> prefix_ir = EmitPrefix(opt_ir);
return new TextRegexSource(regex, tree, base_ir, prefix_ir);
return new TextRegexSource(regex, tree, base_ir, prefix_ir, info);
}
catch (Exception ex)
{
return new TextRegexSource(regex, tree, base_ir, null, ex);
return new TextRegexSource(regex, tree, base_ir, null, info, ex);
}
#pragma warning restore CA1031
}
}
internal struct RegexInfo
{
public int RegionCount { get; set; }
public int MinPredictLength { get; set; }
public int SingleLineResultCount { get; set; }
}
}