2018-11-10 12:11:36 +00:00
|
|
|
|
using System;
|
2018-11-11 09:26:52 +00:00
|
|
|
|
using Upsilon;
|
2018-11-10 12:11:36 +00:00
|
|
|
|
using Upsilon.Evaluator;
|
|
|
|
|
|
2018-11-14 12:09:01 +00:00
|
|
|
|
namespace Ycicle
|
2018-11-10 12:11:36 +00:00
|
|
|
|
{
|
2018-11-14 12:09:01 +00:00
|
|
|
|
internal static class Program
|
2018-11-10 12:11:36 +00:00
|
|
|
|
{
|
2018-11-14 12:09:01 +00:00
|
|
|
|
private static void Main()
|
2018-11-10 12:11:36 +00:00
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Upsilon REPL");
|
2018-11-17 11:40:28 +00:00
|
|
|
|
Script script = null;
|
2018-11-10 12:11:36 +00:00
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
Console.Write("» ");
|
|
|
|
|
var input = Console.ReadLine();
|
2018-11-14 12:09:01 +00:00
|
|
|
|
switch (input)
|
2018-11-10 12:11:36 +00:00
|
|
|
|
{
|
2018-11-14 12:09:01 +00:00
|
|
|
|
case "exit":
|
|
|
|
|
return;
|
2018-11-10 12:11:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-17 11:40:28 +00:00
|
|
|
|
if (script == null)
|
|
|
|
|
script = new Script(input);
|
|
|
|
|
else
|
|
|
|
|
script = Script.ContinueWith(script, input);
|
2018-11-15 14:51:05 +00:00
|
|
|
|
|
2018-11-17 11:40:28 +00:00
|
|
|
|
if (script.Diagnostics.Messages.Count > 0)
|
2018-11-11 09:26:52 +00:00
|
|
|
|
{
|
|
|
|
|
Console.ForegroundColor = ConsoleColor.Red;
|
|
|
|
|
Console.WriteLine("Errors were found during parsing");
|
2018-11-17 11:40:28 +00:00
|
|
|
|
foreach (var diagnosticsMessage in script.Diagnostics.Messages)
|
2018-11-11 09:26:52 +00:00
|
|
|
|
{
|
|
|
|
|
LogError(diagnosticsMessage);
|
|
|
|
|
}
|
|
|
|
|
Console.ResetColor();
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-17 12:05:08 +00:00
|
|
|
|
var evaluate = script.Evaluate();
|
|
|
|
|
if (script.Diagnostics.Messages.Count > 0)
|
2018-11-11 09:26:52 +00:00
|
|
|
|
{
|
2018-11-17 12:05:08 +00:00
|
|
|
|
Console.ForegroundColor = ConsoleColor.Red;
|
|
|
|
|
Console.WriteLine("Errors were found during evaluating");
|
|
|
|
|
foreach (var diagnosticsMessage in script.Diagnostics.Messages)
|
|
|
|
|
{
|
|
|
|
|
LogError(diagnosticsMessage);
|
|
|
|
|
}
|
|
|
|
|
Console.ResetColor();
|
2018-11-11 09:26:52 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-11-16 13:11:27 +00:00
|
|
|
|
if (evaluate == null)
|
|
|
|
|
continue;
|
2018-11-17 12:05:08 +00:00
|
|
|
|
Console.ForegroundColor = ConsoleColor.Cyan;
|
|
|
|
|
Console.WriteLine(evaluate);
|
|
|
|
|
Console.ResetColor();
|
2018-11-14 12:09:01 +00:00
|
|
|
|
}
|
2018-11-10 12:11:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-11-11 09:26:52 +00:00
|
|
|
|
|
2018-11-14 12:09:01 +00:00
|
|
|
|
private static void LogError(DiagnosticsMessage message)
|
2018-11-11 09:26:52 +00:00
|
|
|
|
{
|
|
|
|
|
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();
|
|
|
|
|
}
|
2018-11-10 12:11:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|