protected internal bool Required(TSymbolType expected, bool errorIfNotFound, Func <string, string> errorBase) { var found = At(expected); if (!found && errorIfNotFound) { string error; if (Language.IsNewLine(CurrentSymbol)) { error = LegacyResources.ErrorComponent_Newline; } else if (Language.IsWhiteSpace(CurrentSymbol)) { error = LegacyResources.ErrorComponent_Whitespace; } else if (EndOfFile) { error = LegacyResources.ErrorComponent_EndOfFile; } else { error = LegacyResources.FormatErrorComponent_Character(CurrentSymbol.Content); } int errorLength; if (CurrentSymbol == null || CurrentSymbol.Content == null) { errorLength = 1; } else { errorLength = Math.Max(CurrentSymbol.Content.Length, 1); } Context.ErrorSink.OnError(CurrentStart, errorBase(error), errorLength); } return(found); }