From aeb0d4f887a0c18c36b59acc7b5df08e62020c50 Mon Sep 17 00:00:00 2001 From: Dimitar Trendafilov Date: Sun, 11 Oct 2020 21:32:48 +0300 Subject: Removed old homeworks --- homework/81459/js2html/README.md | 9 ---- homework/81459/js2html/highlight.js | 103 ------------------------------------ homework/81459/js2html/output.html | 74 -------------------------- homework/81459/js2html/testfile.js | 35 ------------ 4 files changed, 221 deletions(-) delete mode 100644 homework/81459/js2html/README.md delete mode 100644 homework/81459/js2html/highlight.js delete mode 100644 homework/81459/js2html/output.html delete mode 100644 homework/81459/js2html/testfile.js (limited to 'homework/81459/js2html') diff --git a/homework/81459/js2html/README.md b/homework/81459/js2html/README.md deleted file mode 100644 index bb0d3a7..0000000 --- a/homework/81459/js2html/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# Requirements -- [Node.js](https://nodejs.org/en/) - -# Usage -```bash -node highlight.js -``` -`` - the file with code to highlight (**testfile.js**)
-`` - the file where to save the computed html (**output.html**) *If missing the result will be printed on the console* diff --git a/homework/81459/js2html/highlight.js b/homework/81459/js2html/highlight.js deleted file mode 100644 index 947ae5f..0000000 --- a/homework/81459/js2html/highlight.js +++ /dev/null @@ -1,103 +0,0 @@ -(() => { - const inputFile = process.argv[2]; - const outputFile = process.argv[3]; - - const fs = require('fs'); - - fs.readFile(inputFile, 'utf8', (err, contents) => { - if (err) { - throw err; - } - - const html = generateHtml(contents); - - if (outputFile) { - fs.writeFile(outputFile, html, 'utf8', (err) => { - if (err) { - throw err; - } - }); - } else { - console.log(html); - } - }); -})(); - -const tokens = [ - {type: 'KEYWORD', className: 'orange', regex: /^(break|case|catch|class|const|continue|debugger|default|delete|do|else|export|extends|finally|for|function|if|import|in|instanceof|new|of|return|super|switch|this|throw|try|typeof|var|void|while|with|yield)\b/}, - {type: 'WHITESPACE', className: '', regex: /^\s+/}, - {type: 'BRACKET', className: 'white', regex: /^[\[\]{}()]/}, - {type: 'PUNCTUATION', className: 'white', regex: /^[:;,.]/}, - {type: 'COMMENT', className: 'grey', regex: /^\/\/.*/}, - {type: 'OPERATOR', className: 'red', regex: /^(\+|-|\/|={1,3}|!={0,2}|&{1,2}|\|{1,2}|\*|~|\^)/}, - {type: 'BOOLEAN_LITERAL', className: 'purple', regex: /^(true|false)\b/}, - {type: 'NUMBER_LITERAL', className: 'blue', regex: /^-?\d+(?:\.\d+)?(?:e[+\-]?\d+)?/i}, - {type: 'STRING_LITERAL', className: 'green', regex: /^("(?:\\.|[^"])*"|'(?:\\.|[^'])*')/}, - {type: 'NULL', className: 'orange', regex: /^(null|undefined)\b/}, - {type: 'IDENTIFIER', className: 'white', regex: /^\w+/}, - {type: "UNKNOWN", className: 'white', regex: /^./} -]; - -function generateHtml(code) { - let highlitedTokens = []; - - while (code && code.length) { - for (const token of tokens) { - if (token.regex.test(code)) { - const match = token.regex.exec(code); - highlitedTokens.push(highlightToken(match[0], token)); - code = code.substring(match[0].length); - break; - } - } - } - - return `${getHtmlHeader()}${highlitedTokens.join('')}${getHtmlFooter()}` -} - -function highlightToken(token, tokenType) { - return `${token}` -} - -const getHtmlHeader = () => ` - - - - - -
-`;
-
-const getHtmlFooter = () => `
-        
- - -`; diff --git a/homework/81459/js2html/output.html b/homework/81459/js2html/output.html deleted file mode 100644 index 52eeeb6..0000000 --- a/homework/81459/js2html/output.html +++ /dev/null @@ -1,74 +0,0 @@ - - - - - - -
-class Nonsense {
-   constructor() {
-      this.arbitraryArray = ['string with no meaning', 42];
-   }
-
-   doesThisMakeSense() {
-      return false;
-   }
-
-   answer(answer) {
-      console.log(answer);
-   }
-
-   whatIsTheMeaning() {
-      return this.arbitraryArray[this.getRandomIndex()]
-   }
-
-   getRandomIndex() {
-      return Math.floor(Math.random() * 2);
-   }
-}
-
-(function () {
-   console.log((-~function(){}-~function(){})); // 2, now that's weird
-   console.log(Array(16).join("lol" - 2) + " Batman!"); // ;)
-
-
-   const nonsense = new Nonsense();
-
-   while(nonsense.doesThisMakeSense()) { // No, it doesn't
-      nonsense.answer(nonsense.whatIsTheMeaning());
-   }
-})();
-
-
-
-        
- - diff --git a/homework/81459/js2html/testfile.js b/homework/81459/js2html/testfile.js deleted file mode 100644 index 0097012..0000000 --- a/homework/81459/js2html/testfile.js +++ /dev/null @@ -1,35 +0,0 @@ -class Nonsense { - constructor() { - this.arbitraryArray = ['string with no meaning', 42]; - } - - doesThisMakeSense() { - return false; - } - - answer(answer) { - console.log(answer); - } - - whatIsTheMeaning() { - return this.arbitraryArray[this.getRandomIndex()] - } - - getRandomIndex() { - return Math.floor(Math.random() * 2); - } -} - -(function () { - console.log((-~function(){}-~function(){})); // 2, now that's weird - console.log(Array(16).join("lol" - 2) + " Batman!"); // ;) - - - const nonsense = new Nonsense(); - - while(nonsense.doesThisMakeSense()) { // No, it doesn't - nonsense.answer(nonsense.whatIsTheMeaning()); - } -})(); - - -- cgit v1.3.1-26-gb76a