private Lexeme Take(LexemeKind lexemeKind, string expected = null, bool ignoreWhitespace = true) { if (ignoreWhitespace) { SkipWhitespaces(); } if (Current.Kind != lexemeKind) { var lexemeChar = lexemeKind.GetCharacter(); Error($"expected {expected ?? lexemeKind.ToString()}{(lexemeChar != null ? $" '{lexemeChar}'" : "")}, found '{Current.Content}' ({Current.Kind})"); } return(TakeAny()); }
public static string GetCharacter(this LexemeKind kind) { return(CharCache.TryGetValue(kind, out var c) ? c : CharCache[kind] = typeof(LexemeKind).GetField(kind.ToString()).GetCustomAttribute <DescriptionAttribute>()?.Description); }