Upsilon/Yc/Program.cs

71 lines
2.3 KiB
C#

using System;
using System.Collections.Generic;
using Upsilon;
using Upsilon.Evaluator;
namespace Yc
{
static class Program
{
static void Main(string[] args)
{
Console.WriteLine("Upsilon REPL");
Dictionary<string, object> variables = new Dictionary<string, object>();
while (true)
{
Console.Write("» ");
var input = Console.ReadLine();
if (input == "exit")
{
return;
}
var parsed = new Script(input);
if (parsed.Diagnostics.Messages.Count > 0)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Errors were found during parsing");
foreach (var diagnosticsMessage in parsed.Diagnostics.Messages)
{
LogError(diagnosticsMessage);
}
Console.ResetColor();
continue;
}
var evaluate = parsed.Evaluate();
if (parsed.Diagnostics.Messages.Count > 0)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Errors were found during evaluating");
foreach (var diagnosticsMessage in parsed.Diagnostics.Messages)
{
LogError(diagnosticsMessage);
}
Console.ResetColor();
}
else
{
Console.WriteLine(evaluate);
//variables = parsed.Variables;
}
}
}
public static void LogError(DiagnosticsMessage message)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(message.Message);
Console.ForegroundColor = ConsoleColor.Gray;
Console.Write(message.BeforeError());
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(message.AtError());
Console.ForegroundColor = ConsoleColor.Gray;
Console.Write(message.AfterError());
Console.WriteLine();
}
}
}