Пример #1
0
 /// <summary>
 /// Compare two token lists using identity semantics - same list, same position.
 /// </summary>
 /// <param name="other">The other token list.</param>
 /// <returns>True if the token lists are the same.</returns>
 public bool Equals(TokenList <TKind> other)
 {
     return(Equals(_tokens, other._tokens) && Position == other.Position);
 }
Пример #2
0
        /// <summary>
        /// Create a token result with no value, indicating a failure to parse any value.
        /// </summary>
        /// <typeparam name="TKind">The kind of token.</typeparam>
        /// <typeparam name="T">The result type.</typeparam>
        /// <param name="remainder">The start of un-parsed input.</param>
        /// <param name="expectations">Expectations that could not be fulfilled.</param>
        /// <returns>An empty result.</returns>
        public static TokenListParserResult <TKind, T> Empty <TKind, T>(TokenList <TKind> remainder, TKind[] expectations)
        {
            var stringExpectations = expectations.Select(Presentation.FormatExpectation).ToArray();

            return(new TokenListParserResult <TKind, T>(remainder, Position.Empty, null, stringExpectations, false));
        }
Пример #3
0
 /// <summary>
 /// Create a token result with no value, indicating a failure to parse any value.
 /// </summary>
 /// <typeparam name="TKind">The kind of token.</typeparam>
 /// <typeparam name="T">The result type.</typeparam>
 /// <param name="remainder">The start of un-parsed input.</param>
 /// <param name="errorPosition">A source position within an individual token where parsing failed. In this case the position will be within
 /// the first token in <paramref name="remainder"/>.</param>
 /// <param name="errorMessage">A message describing the problem.</param>
 /// <returns>An empty result.</returns>
 public static TokenListParserResult <TKind, T> Empty <TKind, T>(TokenList <TKind> remainder, Position errorPosition, string errorMessage)
 {
     return(new TokenListParserResult <TKind, T>(remainder, errorPosition, errorMessage, null, false));
 }
Пример #4
0
 /// <summary>
 /// Create a token result with no value, indicating a failure to parse any value.
 /// </summary>
 /// <typeparam name="TKind">The kind of token.</typeparam>
 /// <typeparam name="T">The result type.</typeparam>
 /// <param name="remainder">The start of un-parsed input.</param>
 /// <param name="expectations">Expectations that could not be fulfilled.</param>
 /// <returns>An empty result.</returns>
 public static TokenListParserResult <TKind, T> Empty <TKind, T>(TokenList <TKind> remainder, string[] expectations)
 {
     return(new TokenListParserResult <TKind, T>(remainder, Position.Empty, null, expectations, false));
 }
Пример #5
0
 /// <summary>
 /// Create a token result with no value, indicating a failure to parse any value.
 /// </summary>
 /// <typeparam name="TKind">The kind of token.</typeparam>
 /// <typeparam name="T">The result type.</typeparam>
 /// <param name="remainder">The start of un-parsed input.</param>
 /// <returns>An empty result.</returns>
 public static TokenListParserResult <TKind, T> Empty <TKind, T>(TokenList <TKind> remainder)
 {
     return(new TokenListParserResult <TKind, T>(remainder, Position.Empty, null, null, false));
 }
Пример #6
0
 /// <summary>
 /// Create a token result with the provided value.
 /// </summary>
 /// <typeparam name="TKind">The kind of token.</typeparam>
 /// <typeparam name="T">The result type.</typeparam>
 /// <param name="value">The value.</param>
 /// <param name="location">The location where parsing began.</param>
 /// <param name="remainder">The first un-parsed location.</param>
 /// <returns></returns>
 public static TokenListParserResult <TKind, T> Value <TKind, T>(T value, TokenList <TKind> location, TokenList <TKind> remainder)
 {
     return(new TokenListParserResult <TKind, T>(value, location, remainder, false));
 }
 internal bool IsPartial(TokenList <TKind> from) => SubTokenErrorPosition.HasValue || from != Remainder;
Пример #8
0
 internal TokenListParserResult(TokenList <TKind> location, TokenList <TKind> remainder, Position errorPosition, string?errorMessage, string[]?expectations, bool backtrack)
 {
     Location              = location;
     Remainder             = remainder;
     _value                = default !; // Default value is not observable.