private IExpression Parse() { var alternatives = new List <IExpression>(); var expression = new CompoundExpression(); while (index != regex.Length) { if (regex[index] == '|') { ++index; alternatives.Add(expression.Normalize()); expression = new CompoundExpression(); } else { var item = ParseInternal(); if (item == null) { break; } expression.Add(item); } } if (alternatives.Count == 0) { return(expression.Normalize()); } else { alternatives.Add(expression.Normalize()); return(Alternation.From(alternatives)); } }
/// <summary> /// Creates an alternation consisting of the given alternatives. /// </summary> /// <param name="alternatives">The alternatives comprising the alternation.</param> /// <returns>The alternation.</returns> public static IAlternation From(IEnumerable <IExpression> alternatives) { if (alternatives == null) { throw new ArgumentNullException(nameof(alternatives)); } var alternation = new Alternation(); foreach (var alternative in alternatives) { alternation.Add(alternative); } return(alternation); }