Пример #1
0
        /// <summary>
        /// Валидация последовательности элементов
        /// </summary>
        /// <param name="tokens"></param>
        /// <returns></returns>
        private bool ValidateTokenSequence(TokenCollection tokens)
        {
            bool isValid           = true;
            var  sequenceValidator = new TokenSequenceValidator();

            for (int i = 0; i < tokens.Count; i++)
            {
                (string, string)tokenTypeTuple;
                if (i == 0)
                {
                    tokenTypeTuple = (TokenSequenceValidator.first, tokens[i].Name);
                }
                else
                {
                    tokenTypeTuple = (tokens[i - 1].Name, tokens[i].Name);
                }

                isValid = sequenceValidator.Validate(tokenTypeTuple);
                if (!isValid)
                {
                    return(isValid);
                }
            }
            return(sequenceValidator.Validate((TokenSequenceValidator.last, tokens.Last().Name)));
        }