public Transform ( |
||
pattern | ||
Результат |
public virtual BasePattern Transform(BasePattern pattern)
{
// The Identity transform
switch (pattern.Type)
{
case PatternType.Group:
GroupPattern group = (GroupPattern)pattern;
BasePattern[] newChildren = group.Patterns
.Select(p => Transform(p))
.Where(IsNotEmpty)
.ToArray();
return CreateGroupOrSingleton(group.IsCapturing, newChildren);
case PatternType.Quantifier:
QuantifierPattern quant = (QuantifierPattern)pattern;
BasePattern newChild = Transform(quant.ChildPattern);
if (IsNotEmpty(newChild))
return new QuantifierPattern(newChild, quant.MinOccurrences, quant.MaxOccurrences, quant.IsGreedy);
else
return GroupPattern.Empty;
case PatternType.Alternation:
return new AlternationPattern(((AlternationPattern)pattern).Alternatives
.Select(a => Transform(a)));
default:
return pattern;
}
}
private static BasePattern doTransform(BasePattern pattern, BaseASTTransform transform) { return transform.Transform(pattern); }