Website Summary Files Commits Branches @commit @diff @stats
path: root / homework / 81270 / js2html / Highlighter.cpp
diff options
context:
space:
mode:
Commitaeb0d4f887a0c18c36b59acc7b5df08e62020c50 (patch)
Author
 Dimitar Trendafilov <dimitar@coherent-labs.com>
2020-10-11 21:32:48 +0300
Committer
 Dimitar Trendafilov <dimitar@coherent-labs.com>
2020-10-11 21:33:38 +0300
Filesb6abdc6e1810326b587f2a160f39570f1f568f27 /homework/81270/js2html/Highlighter.cpp
IPL-aeb0d4f887a0c18c36b59acc7b5df08e62020c50.tar
IPL-aeb0d4f887a0c18c36b59acc7b5df08e62020c50.tar.gz
IPL-aeb0d4f887a0c18c36b59acc7b5df08e62020c50.zip
Parent154b7cd30f21af1554ca26986ff1643e28857727 (diff)
Removed old homeworks
1 files changed, 0 insertions, 71 deletions
-rw-r--r--homework/81270/js2html/Highlighter.cpp71
diff --git a/homework/81270/js2html/Highlighter.cpp b/homework/81270/js2html/Highlighter.cpp
deleted file mode 100644
index cd56496..0000000
--- a/homework/81270/js2html/Highlighter.cpp
+++ /dev/null
@@ -1,71 +0,0 @@
-//
-// Created by bmestanov on 25.10.18.
-//
-
-#include "Highlighter.h"
-#include <fstream>
-#include <sstream>
-#include <iostream>
-
-Highlighter::Highlighter(const char *outputPath, const char *stylePath) :
- outputPath(outputPath), stylePath(stylePath) {}
-
-void Highlighter::highlight(const IPLVector<Token> &tokens) {
- std::stringstream ss;
-
- ss << "<!doctype html>\n";
- ss << "<html>\n";
- ss << " <head>\n";
- ss << " <title>hello.js</title>\n";
- ss << " <link rel=\"stylesheet\" href=\"" << stylePath << "\">\n";
- ss << " </head>\n";
- ss << " <body>\n";
- ss << " <pre class=\"code\">\n";
-
- for (auto &token : tokens) {
- IPLString cssClass = getClass(token);
- if (cssClass.empty()) {
- // Print with no formatting
- ss << token.lexeme;
- } else {
- ss << "<span class=\"" << cssClass << "\">" << token.lexeme << "</span>";
- }
- }
-
- ss << " </body>\n";
- ss << "</html>\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";
- }
-}