Optimizer is almost ok. Will go on source generate
This commit is contained in:
@@ -170,23 +170,40 @@ namespace StgSharp.RegularAnalysis.TextRegex
|
||||
RegexAstNode current;
|
||||
|
||||
// phase1: ALT flatten
|
||||
// phase2: then ALT union
|
||||
// phase3: CONCAT normalize
|
||||
int i = 0;
|
||||
List<RegexAstNode> altNodes = [];
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
current = enumerator.Current;
|
||||
RegexAstNode cur = current.Next;
|
||||
if (current.EqualityTypeConvert == RegexElementLabel.ALT)
|
||||
{
|
||||
List<RegexAstNode> list = FlattenAlt(current);
|
||||
RegexAstNode union = MergeAlt(list);
|
||||
current.ReplaceBy(union);
|
||||
RegexAstNode union = FlattenAlt(current);
|
||||
altNodes.Add(current);
|
||||
current.Right = union;
|
||||
current.Left = RegexAstNode.Empty;
|
||||
} else if (current.EqualityTypeConvert == RegexElementLabel.CONCAT) {
|
||||
RotateConcat(current);
|
||||
}
|
||||
}
|
||||
|
||||
List<RegexAstNode> cases = [];
|
||||
|
||||
// phase2: then ALT union
|
||||
foreach (RegexAstNode item in altNodes)
|
||||
{
|
||||
RegexAstNode _case = item.Right;
|
||||
do
|
||||
{
|
||||
cases.Add(_case);
|
||||
_case = _case.Next;
|
||||
} while (!RegexAstNode.IsNullOrEmpty(_case));
|
||||
RegexAstNode newAlt = MergeAlt(cases);
|
||||
item.ReplaceBy(newAlt);
|
||||
}
|
||||
|
||||
// return;
|
||||
|
||||
// phase4: CONCAT merge
|
||||
enumerator.Reset();
|
||||
while (enumerator.MoveNext())
|
||||
@@ -207,7 +224,6 @@ namespace StgSharp.RegularAnalysis.TextRegex
|
||||
RegexAstNode op
|
||||
)
|
||||
{
|
||||
Console.WriteLine($"Processing a {op.Source.Flag} operator");
|
||||
if (op.EqualityTypeConvert == RegexElementLabel.CONCAT)
|
||||
{
|
||||
if (_stack.TryPopOperand(out RegexAstNode? _1) &&
|
||||
|
||||
Reference in New Issue
Block a user