void IdLookupReader::Read(const char* p_filePath, CrossMap<unsigned, string>& p_table) { fstream file; file.open(p_filePath, ios::in); if (!file.is_open()) return; string line; string key; string value; Token* token = NULL; unsigned lastId = 0; while(getline(file, line)) { if(line.empty()) continue; line = FilterLine(line); Toolbox::GetCharacterBuffer(line, m_buffer); m_scanner->SetCodeBuffer(m_buffer); m_scanner->Reset(); key.clear(); value.clear(); while((token = m_scanner->GetNextToken()) && !token->IsEOF()) { if (g_TokenTypesMap[token->TypeId]->Name == "identifier") { value = token->Value->Lexeme; } else if(g_TokenTypesMap[token->TypeId]->Name == "number") { key = token->Value->Lexeme; lastId = atoi(key.c_str()); } } if(key.empty()) ++lastId; std::string enumStr = EnumToSentence(value); p_table.SetByFirst(lastId, enumStr); } file.close(); }
Token Tokenizer::GetToken(int i) { int p = buffer_pos + i; if (p < 0) return Token(); while (int(token_buffer.size()) < p + 1) { Token t; ReadToken(t); if (t.IsEOF()) return t; token_buffer.push_back(t); } return token_buffer[p]; }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------ int main(int argc, char* argv[]) { GLCCPreprocessor* preproc = NULL; GLCCint errCode = GLCCError_Ok; GLCCint tmpErrCode = GLCCError_Ok; GLPPOptions opts; extern const LexicalEntry* GetGlslTokens(); extern const char** GetGlslReservedTypes(); StateObject parserState(GetGlslReservedTypes()); Lexer myLex(GetGlslTokens(), "struct Foo {\n\tdmat2x2 bar[3];\n\tfloat baz;\n};", &parserState); for (Token tok = myLex.Pop(); !tok.IsEOF(); tok = myLex.Pop()) { std::cout << tok << std::endl; } if (argc < 2) { errCode = GLCCError_MissingRequiredParameter; goto exit; } if ((errCode = genPreprocessor(&preproc, &opts)) != GLCCError_Ok) goto exit; if ((errCode = preprocessFromFile(preproc, argv[1])) != GLCCError_Ok) { const char* errText = getLastError(preproc); if (errText) { printf("Error reported during preprocessing: \"%s\"\n", errText); } goto cleanup; } cleanup: tmpErrCode = deletePreprocessor(&preproc); if (tmpErrCode != GLCCError_Ok) { printf("Error while cleaning up: '%d', main still returning preprocess status.", tmpErrCode); } exit: return errCode; }