Пример #1
0
            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));
                }
            }
Пример #2
0
        /// <summary>
        /// Creates an expression consisting of multiple sub-expressions.
        /// </summary>
        /// <param name="members">The expressions comprising the expression.</param>
        /// <returns>The expression.</returns>
        public static ICompoundExpression From(IEnumerable <IExpression> members)
        {
            if (members == null)
            {
                throw new ArgumentNullException(nameof(members));
            }
            var expression = new CompoundExpression();

            foreach (var member in members)
            {
                expression.Add(member);
            }
            return(expression);
        }
Пример #3
0
 public IExpression AsExpression() => CompoundExpression.From(Members);