Exemple #1
0
        /// <summary>
        /// Combine two empty results.
        /// </summary>
        /// <typeparam name="T">The source type.</typeparam>
        /// <typeparam name="TKind">The kind of token.</typeparam>
        /// <param name="first">The first value to combine.</param>
        /// <param name="second">The second value to combine.</param>
        /// <returns>A result of type <typeparamref name="T"/> carrying information from both results.</returns>
        public static TokenListParserResult <TKind, T> CombineEmpty <TKind, T>(TokenListParserResult <TKind, T> first, TokenListParserResult <TKind, T> second)
        {
            if (first.Remainder != second.Remainder)
            {
                return(second);
            }

            var expectations = first.Expectations;

            if (expectations == null)
            {
                expectations = second.Expectations;
            }
            else if (second.Expectations != null)
            {
                expectations = new string[first.Expectations.Length + second.Expectations.Length];
                var i = 0;
                for (; i < first.Expectations.Length; ++i)
                {
                    expectations[i] = first.Expectations[i];
                }
                for (var j = 0; j < second.Expectations.Length; ++i, ++j)
                {
                    expectations[i] = second.Expectations[j];
                }
            }

            return(new TokenListParserResult <TKind, T>(second.Remainder, second.SubTokenErrorPosition, first.ErrorMessage, expectations, second.Backtrack));
        }
Exemple #2
0
        /// <summary>
        /// Consume a token from the start of the list, returning a result with the token and remainder.
        /// </summary>
        /// <returns></returns>
        public TokenListParserResult <TKind, Token <TKind> > ConsumeToken()
        {
            EnsureHasValue();

            if (IsAtEnd)
            {
                return(TokenListParserResult.Empty <TKind, Token <TKind> >(this));
            }

            var token = _tokens ![Position];
Exemple #3
0
        /// <summary>
        /// Consume a token from the start of the list, returning a result with the token and remainder.
        /// </summary>
        /// <returns></returns>
        public TokenListParserResult <TKind, Token <TKind> > ConsumeToken()
        {
            EnsureHasValue();

            if (IsAtEnd)
            {
                return(TokenListParserResult.Empty <TKind, Token <TKind> >(this));
            }

            var token = _tokens[Position];

            return(TokenListParserResult.Value(token, this, new TokenList <TKind>(_tokens, Position + 1)));
        }
Exemple #4
0
        /// <summary>
        /// Combine two empty results.
        /// </summary>
        /// <typeparam name="T">The source type.</typeparam>
        /// <typeparam name="TKind">The kind of token.</typeparam>
        /// <param name="first">The first value to combine.</param>
        /// <param name="second">The second value to combine.</param>
        /// <returns>A result of type <typeparamref name="T"/> carrying information from both results.</returns>
        public static TokenListParserResult <TKind, T> CombineEmpty <TKind, T>(TokenListParserResult <TKind, T> first, TokenListParserResult <TKind, T> second)
        {
            if (first.Remainder != second.Remainder)
            {
                return(second);
            }

            var expectations = first.Expectations;

            if (expectations == null)
            {
                expectations = second.Expectations;
            }
            else if (second.Expectations != null)
            {
                expectations = new string[first.Expectations !.Length + second.Expectations.Length];
Exemple #5
0
 /// <summary>
 /// Convert an empty result of one type into another.
 /// </summary>
 /// <typeparam name="TKind">The kind of token.</typeparam>
 /// <typeparam name="T">The source type.</typeparam>
 /// <typeparam name="U">The destination type.</typeparam>
 /// <param name="result">The result to convert.</param>
 /// <returns>The converted result.</returns>
 public static TokenListParserResult <TKind, U> CastEmpty <TKind, T, U>(TokenListParserResult <TKind, T> result)
 {
     return(new TokenListParserResult <TKind, U>(result.Remainder, result.SubTokenErrorPosition, result.ErrorMessage, result.Expectations, result.Backtrack));
 }