/// <summary> /// Read and consume a token from the lexer, throw if the read token does not match the expected token /// </summary> /// <param name="type">The expected token type</param> /// <param name="text">The expected token text</param> private void ReadToken(WellKnownTextTokenType type, String text) { if (!(this.NextToken() && this.IsTokenMatch(type, text))) { throw new FormatException(Strings.WellKnownText_UnexpectedToken(type, text, this.lexer.CurrentToken)); } }
private bool ReadOptionalToken(WellKnownTextTokenType expectedTokenType, string expectedTokenText) { LexerToken token; while (this.lexer.Peek(out token)) { if (token.MatchToken(8, null, StringComparison.OrdinalIgnoreCase)) { this.lexer.Next(); } else { if (token.MatchToken((int)expectedTokenType, expectedTokenText, StringComparison.OrdinalIgnoreCase)) { this.lexer.Next(); return(true); } return(false); } } return(false); }
/// <summary> /// Test whether the current token matches the expected token /// </summary> /// <param name="type">The expected token type</param> /// <param name="text">The expected token text</param> /// <returns>True if the two tokens match</returns> private bool IsTokenMatch(WellKnownTextTokenType type, String text) { return(this.lexer.CurrentToken.MatchToken((int)type, text, StringComparison.OrdinalIgnoreCase)); }