internal ReKleeneStar(ReElement element) { if (element == null) { throw new ArgumentNullException(nameof(element)); } _element = element; }
public static ReElement NewRepetition(ReElement element, int min, int?max) { if (element == null) { throw new ArgumentNullException(nameof(element)); } if (max.HasValue && min > max.Value) { throw new ArgumentException("min cannot be greater than max", nameof(min)); } switch (element.Kind) { case ReElementKind.EmptyString: case ReElementKind.EmptyLanguage: case ReElementKind.KleenStar: return(element); } if (element.MatchesEmptyString) { min = 0; } var builder = ImmutableArray.CreateBuilder <ReElement>(); for (var i = 0; i < min; i++) { builder.Add(element); } if (max.HasValue) { var optionalElement = new ReUnion( ImmutableArray.Create( element, ReEmptyString.Instance)); for (var i = min; i < max; i++) { builder.Add(optionalElement); } } else { builder.Add(new ReKleeneStar(element)); } switch (builder.Count) { case 0: return(ReEmptyString.Instance); case 1: return(builder[0]); default: return(new ReConcatenation(builder.ToImmutable())); } }
static ReElement ParseRepitition(ReElement element, ReParseContext context) { var min = ParseInt(context) ?? 0; if (context.Current == ',') { if (!context.MoveNext()) { ThrowUnexpectedEnd(); } var max = ParseInt(context); return(ReFactory.NewRepetition(element, min, max)); } else { return(ReFactory.NewRepetition(element, min, min)); } }
public static ReElement NewKleeneStar(ReElement element) { if (element == null) { throw new ArgumentNullException(nameof(element)); } switch (element.Kind) { case ReElementKind.KleenStar: case ReElementKind.EmptyLanguage: case ReElementKind.EmptyString: return(element); default: return(new ReKleeneStar(element)); } }