// // Created by bmestanov on 25.10.18. // #include "Highlighter.h" #include #include #include Highlighter::Highlighter(const char *outputPath, const char *stylePath) : outputPath(outputPath), stylePath(stylePath) {} void Highlighter::highlight(const IPLVector &tokens) { std::stringstream ss; ss << "\n"; ss << "\n"; ss << " \n"; ss << " hello.js\n"; ss << " \n"; ss << " \n"; ss << " \n"; ss << "
\n";

    for (auto &token : tokens) {
        IPLString cssClass = getClass(token);
        if (cssClass.empty()) {
            // Print with no formatting
            ss << token.lexeme;
        } else {
            ss << "" << token.lexeme << "";
        }
    }

    ss << " \n";
    ss << "\n";

    std::ofstream fs(outputPath);
    if (fs) {
        fs << ss.rdbuf();
    } else {
        std::cout << ss.rdbuf();
    }
}

IPLString Highlighter::getClass(const Token &token) {
    switch (token.type) {
        case Whitespace:
        case NewLine:
        case Raw:
            return "";
        case Comment:
            return "comment";
        case Keyword:
            return "keyword";
        case NumericLiteral:
            return "numeric";
        case StringLiteral:
            return "string";
        case TemplateLiteral:
            return "template";
        case Regex:
            return "regex";
        case Identifier:
            return "identifier";
        case BooleanLiteral:
            return "boolean";
        case Global:
            return "global";
    }
}