Optimizer is almost ok. Will go on source generate
This commit is contained in:
@@ -56,11 +56,11 @@ namespace StgSharp.RegularAnalysis.TextRegex
|
||||
public static RegexAstNode Empty { get; }
|
||||
= new EmptyRegexAstNode();
|
||||
|
||||
public virtual RegexAstNode Previous { get; set; }
|
||||
public RegexAstNode Previous { get; set; }
|
||||
|
||||
public virtual RegexAstNode Next { get; set; }
|
||||
public RegexAstNode Next { get; set; }
|
||||
|
||||
public virtual RegexAstNode Parent { get; set; }
|
||||
public RegexAstNode Parent { get; set; }
|
||||
|
||||
public RegexAstNode Left
|
||||
{
|
||||
@@ -69,7 +69,9 @@ namespace StgSharp.RegularAnalysis.TextRegex
|
||||
{
|
||||
field?.Parent = Empty;
|
||||
field = value;
|
||||
value.Parent = this;
|
||||
if (!IsNullOrEmpty(value)) {
|
||||
value.Parent = this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +82,9 @@ namespace StgSharp.RegularAnalysis.TextRegex
|
||||
{
|
||||
field?.Parent = Empty;
|
||||
field = value;
|
||||
value.Parent = this;
|
||||
if (!IsNullOrEmpty(value)) {
|
||||
value.Parent = this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +97,7 @@ namespace StgSharp.RegularAnalysis.TextRegex
|
||||
|
||||
public string CodeConvertTemplate { get; }
|
||||
|
||||
public Token<RegexElementLabel> Source { get; private set; }
|
||||
public Token<RegexElementLabel> Source { get; private protected set; }
|
||||
|
||||
public void AppendNode(
|
||||
RegexAstNode nextToken
|
||||
@@ -123,7 +127,7 @@ namespace StgSharp.RegularAnalysis.TextRegex
|
||||
RegexAstNode node
|
||||
)
|
||||
{
|
||||
return node is null || node is EmptyRegexAstNode;
|
||||
return node is null || ReferenceEquals(node, Empty);
|
||||
}
|
||||
/**/
|
||||
|
||||
@@ -154,6 +158,23 @@ namespace StgSharp.RegularAnalysis.TextRegex
|
||||
{
|
||||
return new EmptyRegexAstNode();
|
||||
}
|
||||
|
||||
internal void RemoveAndAsChild(
|
||||
bool useLeft
|
||||
)
|
||||
{
|
||||
if (useLeft)
|
||||
{
|
||||
Source = Left.Source;
|
||||
Left.Parent = Empty;
|
||||
Left = Empty;
|
||||
} else
|
||||
{
|
||||
Source = Right.Source;
|
||||
Right.Parent = Empty;
|
||||
Right = Empty;
|
||||
}
|
||||
}
|
||||
/**/
|
||||
|
||||
internal void ReplaceBy(
|
||||
@@ -163,10 +184,10 @@ namespace StgSharp.RegularAnalysis.TextRegex
|
||||
Source = node.Source;
|
||||
Left = node.Left;
|
||||
Right = node.Right;
|
||||
if (IsNullOrEmpty(Left)) {
|
||||
if (!IsNullOrEmpty(Left)) {
|
||||
Left.Parent = this;
|
||||
}
|
||||
if (IsNullOrEmpty(Right)) {
|
||||
if (!IsNullOrEmpty(Right)) {
|
||||
Right.Parent = this;
|
||||
}
|
||||
Previous = node.Previous;
|
||||
@@ -188,18 +209,6 @@ namespace StgSharp.RegularAnalysis.TextRegex
|
||||
|
||||
public EmptyRegexAstNode() : base(Token<RegexElementLabel>.Empty) { }
|
||||
|
||||
public override RegexAstNode Next
|
||||
{
|
||||
get;
|
||||
set { field = Empty; }
|
||||
}
|
||||
|
||||
public override RegexAstNode Previous
|
||||
{
|
||||
get;
|
||||
set { field = Empty; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user