void Preprocessor::parseMultiLineComment() { advance(2); setFirstOnLine(false); for (;;) { if (!hasMore()) { logError("%s:%u: Unexpected end of file in multi-line comment", files.back().name, files.back().line); throw Exception("Unexpected end of file in multi-line comment"); } if (c(0) == '*' && c(1) == '/') { advance(2); break; } else if (isNewLine()) parseNewLine(); else advance(1); } appendToOutput(); }
Token Lexer::nextToken() { if (atEof_) { return Token(TokenType::END_OF_INPUT, ""); } if (std::isdigit(next_)) { return parseNumber(); } else if (isIdentifierStart(next_)) { return parseIdentifier(); } else if (isEol(next_)) { return parseNewLine(); } else { return parseOperator(); } }
void Preprocessor::parse(const char* name, const char* text) { if (std::find(names.begin(), names.end(), name) != names.end()) return; files.push_back(File(name, text)); names.push_back(name); list += format("( file %u: %s )\n", (uint) names.size(), name); output.reserve(output.size() + std::strlen(text)); appendToOutput(format("#line 0 %u /* entering %s */\n", (uint) files.size(), files.back().name).c_str()); while (hasMore()) { if (isMultiLineComment()) parseMultiLineComment(); else if (isSingleLineComment()) parseSingleLineComment(); else if (isNewLine()) parseNewLine(); else if (isWhitespace()) parseWhitespace(); else if (isCommand()) parseCommand(); else { advance(1); appendToOutput(); setFirstOnLine(false); } } files.pop_back(); if (!files.empty()) { appendToOutput(format("\n#line %u %u /* returning to %s */", files.back().line, (uint) files.size(), files.back().name).c_str()); } }