/********************************************************************* * * Function: process_test_lexer_one_token * Purpose: * *********************************************************************/ static void process_test_lexer_one_token(const string &line, int token_start, int line_number, const Parameters ¶meters, ErrorCount *errors) { string token_string, expected_token_type; string extra; token_string = extract_token(&token_start, line); expected_token_type = extract_token(&token_start, line); extra = extract_token(&token_start, line); if (!token_string.compare("") || !expected_token_type.compare("")) { cout << "Error: Missing match information on line " << line_number << "." << endl; cout << " Format: test-lexer-one-token <token> <token-type> " << endl; errors->IncrementErrors(); } else if (extra.compare("")) { cout << "Ignored extra input (" << extra << ") on line " << line_number << "." << endl; } Lexer lexer; Lexer::TokenType token_type; const char *token_name; StringLexerSource *lexer_source; lexer_source = new StringLexerSource(&token_string); if (lexer_source == NULL) { cout << "Error: Couldn't allocate LexerSource! on line "; cout << line_number << "." << endl; } else { lexer.Initialize(lexer_source); token_type = lexer.PeekToken(NULL); token_name = lexer.strLexToken(token_type); lexer.FinishedParse(); if (!strcmp(expected_token_type.c_str(), token_name)) { cout << "OK: Token type for \"" << token_string << "\" is " << token_name << " on line " << line_number << "." << endl; } else { cout << "Error: Token type for \"" << token_string << "\" is not " << expected_token_type << " but is \"" << token_name << "\" on line " << line_number << "." << endl; errors->IncrementErrors(); } delete lexer_source; } return; }