Skip to content

Commit

Permalink
Eliminate need for VirtualUnaryTuple extraction node type
Browse files Browse the repository at this point in the history
  • Loading branch information
sblom committed Dec 20, 2023
1 parent ed80c9f commit fb646d9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 19 deletions.
7 changes: 4 additions & 3 deletions RegExtract/ExtractionPlan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace RegExtract
{
public class ExtractionPlan<T>: IFormattable
{
public ExtractionPlanNode Plan { get; protected set; }
ExtractionPlanNode Plan { get; set; }
RegexCaptureGroupTree? _tree;

protected ExtractionPlan()
Expand Down Expand Up @@ -226,7 +226,8 @@ private ExtractionPlanNode AssignTypesToTree(RegexCaptureGroupNode tree, Type ty

if (IsDirectlyConstructable(type))
{
// We're at a leaf--if there's an inner capture group, use it instead of everything.
// We're at a leaf in the type hierarchy, and all we need is a string.
// If there's an inner capture group, use it to narrow the match.
if (tree.children.Count() == 1)
{
tree = tree.children.Single();
Expand All @@ -244,7 +245,7 @@ private ExtractionPlanNode AssignTypesToTree(RegexCaptureGroupNode tree, Type ty

if (tree.name == "0")
{
return new VirtualUnaryTupleNode(tree.name, type, new[] { AssignTypesToTree(tree.children.Single(), type) }, new ExtractionPlanNode[0]);
return AssignTypesToTree(tree.children.Single(), type);
}

if (typeParams.Length < 2 && !IsInitializableCollection(typeParams.FirstOrDefault()))
Expand Down
4 changes: 2 additions & 2 deletions RegExtract/ExtractionPlanNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ internal virtual void Validate()
return result;
}

public object? Execute(Match match)
internal object? Execute(Match match)
{
if (!match.Success)
{
Expand All @@ -201,7 +201,7 @@ internal virtual void Validate()

Dictionary<string, (string Value, int Index, int Length)[]> cache = new();

return Execute(match, match.Groups[groupName].Index, match.Groups[groupName].Length, cache);
return Execute(match, match.Groups[0].Index, match.Groups[0].Length, cache);
}

protected const string VALUETUPLE_TYPENAME = "System.ValueTuple`";
Expand Down
14 changes: 0 additions & 14 deletions RegExtract/ExtractionPlanNodeTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,6 @@ internal record UninitializedNode() :
}
}

internal record VirtualUnaryTupleNode(string groupName, Type type, ExtractionPlanNode[] constructorParams, ExtractionPlanNode[] propertySetters) :
ExtractionPlanNode(groupName, type, constructorParams, propertySetters)
{
internal override object? Execute(Match match, int captureStart, int captureLength, Dictionary<string, (string Value, int Index, int Length)[]> cache)
{
return constructorParams.Single().Execute(match, captureStart, captureLength, cache);
}

internal override void Validate()
{
base.Validate();
}
}

internal record CollectionInitializerNode(string groupName, Type type, ExtractionPlanNode[] constructorParams, ExtractionPlanNode[] propertySetters) :
ExtractionPlanNode(groupName, type, constructorParams, propertySetters)
{
Expand Down

0 comments on commit fb646d9

Please sign in to comment.