/// <summary> /// If the result is empty, format the fragment of text describing the error. /// </summary> /// <returns>The error fragment.</returns> public string FormatErrorMessageFragment() { if (ErrorMessage != null) { return(ErrorMessage); } string message; if (Location.IsAtEnd) { message = "unexpected end of input"; } else { var next = Location.ConsumeChar().Value; message = $"unexpected {Display.Presentation.FormatLiteral(next)}"; } if (Expectations != null) { var expected = Friendly.List(Expectations); message += $", expected {expected}"; } return(message); }
/// <summary> /// If the result is empty, format the fragment of text describing the error. /// </summary> /// <returns>The error fragment.</returns> public string FormatErrorMessageFragment() { if (ErrorMessage != null) { return(ErrorMessage); } string message; if (Remainder.IsAtEnd) { message = "unexpected end of input"; } else { var next = Remainder.ConsumeChar().Value; message = $"unexpected `{next}`"; } if (Expectations != null) { var expected = Friendly.List(Expectations); message += $", expected {expected}"; } return(message); }
public void FriendlyListsPreserveOrderButRemoveDuplicates() { var actual = Friendly.List(new[] { "one", "two", "two", "one", "three" }); const string expected = "one, two or three"; Assert.Equal(expected, actual); }
/// <summary> /// If the result is empty, format the fragment of text describing the error. /// </summary> /// <returns>The error fragment.</returns> public string FormatErrorMessageFragment() { if (ErrorMessage != null) { return(ErrorMessage); } string message; if (Remainder.IsAtEnd) { message = "unexpected end of input"; } else { var next = Remainder.ConsumeToken().Value; var appearance = Presentation.FormatAppearance(next.Kind, next.ToStringValue()); message = $"unexpected {appearance}"; } if (Expectations != null) { var expected = Friendly.List(Expectations); message += $", expected {expected}"; } return(message); }
/// <summary> /// Parse any single character except those in <paramref name="chars"/>. /// </summary> public static TextParser <char> ExceptIn(params char[] chars) { return(Matching(c => !chars.Contains(c), "any character except " + Friendly.List(chars.Select(Presentation.FormatLiteral)))); }