this repo has no description
at master 2.5 kB view raw
1namespace Astrid; 2 3public static class Error 4{ 5 public static void Throw(string message, Token token) 6 { 7 string[] filearr = File.ReadAllLines(Program.sourceFile); 8 9 if(token != null) 10 { 11 Console.ForegroundColor = ConsoleColor.Red; 12 Console.Write("token"); 13 Console.ForegroundColor = ConsoleColor.White; 14 Console.Write($": {Tokenizer.GetTokenAsHuman(token)}"); 15 Console.WriteLine(); 16 } 17 18 Console.ForegroundColor = ConsoleColor.Red; 19 Console.Write("error"); 20 Console.ForegroundColor = ConsoleColor.White; 21 Console.Write($": {message}"); 22 Console.WriteLine(); 23 24 25 26 if((token!).lineStart > 0) { 27 Console.ForegroundColor = ConsoleColor.Blue; 28 Console.Write(token.lineStart); 29 Console.Write(" | "); 30 31 foreach(var j in filearr[token.lineStart - 1]) { 32 Console.ForegroundColor = ConsoleColor.Gray; 33 Console.Write(j); 34 } 35 Console.WriteLine(); 36 } 37 38 Console.ForegroundColor = ConsoleColor.Blue; 39 Console.Write(token.lineStart + 1); 40 Console.Write(" | "); 41 42 int jIndex = -1; 43 foreach(var j in filearr[token.lineStart]) { 44 jIndex ++; 45 if(jIndex >= token.charStart && jIndex < token.charEnd) { 46 Console.ForegroundColor = ConsoleColor.Red; 47 } else { 48 Console.ForegroundColor = ConsoleColor.Gray; 49 } 50 Console.Write(j); 51 } 52 Console.WriteLine(); 53 54 Console.ForegroundColor = ConsoleColor.Blue; 55 for(var j = 0; j < token.lineStart.ToString().Length; j++) { 56 Console.Write(" "); 57 } 58 Console.Write(" | "); 59 60 for(int j = 0; j < token.charStart; j++) { 61 Console.Write(" "); 62 } 63 Console.ForegroundColor = ConsoleColor.Blue; 64 for(var j = 0; j < token.charEnd - token.charStart; j++) { 65 Console.Write("^"); 66 } 67 Console.WriteLine(); 68 69 70 if(filearr.Length < token.lineStart + 1) 71 { 72 Console.ForegroundColor = ConsoleColor.Blue; 73 Console.Write(token.lineStart + 2); 74 Console.Write(" | "); 75 76 foreach(var j in filearr[token.lineStart + 1]) { 77 Console.ForegroundColor = ConsoleColor.Gray; 78 Console.Write(j); 79 } 80 Console.WriteLine(); 81 } 82 83 Environment.Exit(1); 84 } 85}