scanning min scan length
This commit is contained in:
@@ -137,7 +137,8 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
}
|
||||
|
||||
private static void OptimizeTree(
|
||||
AbstractSyntaxTree<RegexAstNode, RegexElementLabel> tree
|
||||
AbstractSyntaxTree<RegexAstNode, RegexElementLabel> tree,
|
||||
ref RegexInfo info
|
||||
)
|
||||
{
|
||||
// phase0: scan container and remove no parent nodes
|
||||
@@ -163,11 +164,10 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
}
|
||||
}
|
||||
|
||||
List<RegexAstNode> cases = [];
|
||||
|
||||
// phase3: then ALT union
|
||||
foreach (RegexAstNode item in altNodes)
|
||||
{
|
||||
List<RegexAstNode> cases = [];
|
||||
RegexAstNode _case = item.Right;
|
||||
do
|
||||
{
|
||||
@@ -194,6 +194,40 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
info.MinPredictLength = ComputeMinLength(tree.Root);
|
||||
|
||||
static int ComputeMinLength(
|
||||
RegexAstNode node
|
||||
)
|
||||
{
|
||||
if (node.EqualityTypeConvert is RegexElementLabel.UNIT_SPAN or
|
||||
RegexElementLabel.UNIT)
|
||||
{
|
||||
return node.Value.Length;
|
||||
} else if (node.EqualityTypeConvert == RegexElementLabel.CONCAT)
|
||||
{
|
||||
return ComputeMinLength(node.Left) + ComputeMinLength(node.Right);
|
||||
} else if (node.EqualityTypeConvert == RegexElementLabel.ALT)
|
||||
{
|
||||
RegexAstNode case_0 = node.Right;
|
||||
int length = int.MaxValue;
|
||||
do
|
||||
{
|
||||
length = int.Min(ComputeMinLength(case_0), length);
|
||||
case_0 = case_0.Next;
|
||||
} while (!RegexAstNode.IsNullOrEmpty(case_0));
|
||||
return length;
|
||||
} else if (node.EqualityTypeConvert == RegexElementLabel.COUNT)
|
||||
{
|
||||
string source = node.Source.Value;
|
||||
int single_count = ComputeMinLength(node.Right);
|
||||
return 0;
|
||||
} else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void RotateConcat(
|
||||
|
||||
Reference in New Issue
Block a user