Website Summary Files Commits Branches @commit @diff @stats
path: root / homework / 81709 / JSCompiler.SyntaxHighlighter / SyntaxHighlighter.cs
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/81709/JSCompiler.SyntaxHighlighter/SyntaxHighlighter.cs
IPL-aeb0d4f887a0c18c36b59acc7b5df08e62020c50.tar
IPL-aeb0d4f887a0c18c36b59acc7b5df08e62020c50.tar.gz
IPL-aeb0d4f887a0c18c36b59acc7b5df08e62020c50.zip
Parent154b7cd30f21af1554ca26986ff1643e28857727 (diff)
Removed old homeworks
1 files changed, 0 insertions, 187 deletions
-rw-r--r--homework/81709/JSCompiler.SyntaxHighlighter/SyntaxHighlighter.cs187
diff --git a/homework/81709/JSCompiler.SyntaxHighlighter/SyntaxHighlighter.cs b/homework/81709/JSCompiler.SyntaxHighlighter/SyntaxHighlighter.cs
deleted file mode 100644
index fd8572f..0000000
--- a/homework/81709/JSCompiler.SyntaxHighlighter/SyntaxHighlighter.cs
+++ /dev/null
@@ -1,187 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.IO;
-using JSCompiler.Core;
-
-namespace JSCompiler.SyntaxHighlighter
-{
- public static class SyntaxHighlighter
- {
- private static readonly string HTML =
- @"<!DOCTYPE html>
-<html>
-<head>
-{0}
-<title> {1} </title>
-</head>
-<body> {2} </body></html>";
-
- private static readonly string DEFAULT_CSS =
- @"<style>
-body {
- font-size: 20px;
- font-family: ""Verdana"";
-}
-.number {
- color: Orange;
-}
-.string {
- color: Gray;
- white-space: pre-wrap;
-}
-.keyword {
- color: Blue;
-}
-.identifier {
- color: Black;
-}
-.operator {
- color: DarkBlue;
-}
-.comment {
- color: Green;
- font-style: italic;
- white-space: pre-wrap;
-}
-
-.reserved {
- color: MediumVioletRed;
-}
-
-.undefined{
- color: Black;
-}
-
-.default {
- color: DarkBlue;
-}
-</style>";
-
- private static IEnumerable<TokenType> KEYWORDS = ReservedStrings.KeywordsAsMap().Values;
-
- private static IEnumerable<TokenType> OTHER_RESERVED = ReservedStrings.OthersAsMap().Values;
-
- private static IEnumerable<TokenType> ONE_SYMBOL_OPERATORS = new List<TokenType>
- {
- TokenType.Minus, // -
- TokenType.Plus, // +
- TokenType.Star, // *
- TokenType.Division, // /
- TokenType.Modulo, // %
- TokenType.BitwiseNot, // ~
- TokenType.BitwiseAnd, // &
- TokenType.BitwiseXor, // ^
- TokenType.BitwiseOr, // |
- TokenType.QuestionMark, // ?
- TokenType.Bang, // !
- TokenType.Equal, // =
- TokenType.Greater, // >
- TokenType.Less, // <
- TokenType.Backslash, // \
- };
-
- private static IEnumerable<TokenType> MULT_SYMBOL_OPERATORS = new List<TokenType>
- {
- TokenType.NotEqual, // !=
- TokenType.EqualEqual, // ==
- TokenType.StrictEqual, // ===
- TokenType.StrictNotEqual, // !==
- TokenType.GreaterEqual, // >=
- TokenType.LessEqual, // <=
- TokenType.MinusMinus, // --
- TokenType.PlusPlus, // ++
- TokenType.LeftShift, // <<
- TokenType.RightShift, // >>
- TokenType.LogicalAnd, // &&
- TokenType.LogicalOr, // ||
- TokenType.StarEqual, // *=
- TokenType.DivideEqual, // /=
- TokenType.ModuloEqual, // %=
- TokenType.PlusEqual, // +=
- TokenType.MinusEqual, // -=
- TokenType.LeftShiftEqual, // <<=
- TokenType.RightShiftEqual, // >>=
- TokenType.BitwiseAndEqual, // &=
- TokenType.BitwiseXorEqual, // ^=
- TokenType.BitwiseOrEqual, // |=
- };
-
- public static void GenerateHtml(IEnumerable<Token> tokens, string fileName, string css = null)
- {
- if (css == null) css = DEFAULT_CSS;
-
- string code = "";
- IEnumerator<Token> tokenEnum = tokens.GetEnumerator();
- if (!tokenEnum.MoveNext()) return;
- Token cur;
- do
- {
- cur = tokenEnum.Current;
- TokenType type = cur.Type;
-
- switch (type)
- {
- case TokenType.Whitespace:
- code += "&nbsp";
- break;
- case TokenType.Tab:
- code += "&nbsp" + "&nbsp" + "&nbsp" + "&nbsp";
- break;
- case TokenType.NewLine:
- code += "<br>";
- break;
- case TokenType.Number:
- code += "<span class=\"number\">" + ((NumToken)cur).Num + "</span>";
- break;
- case TokenType.String:
- code += "<span class=\"string\">" + ((WordToken)cur).Lexeme + "</span>";
- break;
- case TokenType.Identifier:
- code += "<span class=\"identifier\">" + ((WordToken)cur).Lexeme + "</span>";
- break;
- case TokenType.Comment:
- code += "<span class=\"comment\">" + ((WordToken)cur).Lexeme + "</span>";
- break;
- case TokenType.Error:
- code += "<span class=\"undefined\">" + ((WordToken)cur).Lexeme + "</span>";
- break;
-
- default:
- if (KEYWORDS.Contains(type))
- {
- code += "<span class=\"keyword\">" + ((WordToken)cur).Lexeme + "</span>";
- }
- else if(OTHER_RESERVED.Contains(type))
- {
- code += "<span class=\"reserved\">" + ((WordToken)cur).Lexeme + "</span>";
- }
- else if (ONE_SYMBOL_OPERATORS.Contains(type))
- {
- code += "<span class=\"operator\">" + cur.ToString() + "</span>";
- }
- else if (MULT_SYMBOL_OPERATORS.Contains(type))
- {
- code += "<span class=\"operator\">" + ((WordToken)cur).Lexeme + "</span>";
- }
- else
- {
- code += "<span class=\"default\">" + cur.ToString() + "</span>";
- break;
- }
- break;
- }
- }
- while (tokenEnum.MoveNext() && tokenEnum.Current.Type != TokenType.EOF);
-
- string shouldWrite = string.Format(HTML, css, fileName, code);
-
- using (StreamWriter writer = new StreamWriter(fileName))
- {
- writer.Write(shouldWrite);
- }
- }
- }
-}