2018-11-10 12:11:36 +00:00
|
|
|
|
using System;
|
2018-11-10 16:00:39 +00:00
|
|
|
|
using System.Collections.Generic;
|
2018-11-11 09:26:52 +00:00
|
|
|
|
using Upsilon;
|
2018-11-11 20:03:50 +00:00
|
|
|
|
using Upsilon.Binder;
|
2018-11-10 12:11:36 +00:00
|
|
|
|
using Upsilon.Evaluator;
|
|
|
|
|
|
|
|
|
|
namespace Yc
|
|
|
|
|
{
|
|
|
|
|
static class Program
|
|
|
|
|
{
|
|
|
|
|
static void Main(string[] args)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Upsilon REPL");
|
2018-11-11 20:03:50 +00:00
|
|
|
|
Dictionary<VariableSymbol, object> variables = new Dictionary<VariableSymbol, object>();
|
2018-11-10 12:11:36 +00:00
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
Console.Write("» ");
|
|
|
|
|
var input = Console.ReadLine();
|
|
|
|
|
if (input == "exit")
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-11 20:03:50 +00:00
|
|
|
|
var parsed = new Script(input, variables);
|
2018-11-11 09:26:52 +00:00
|
|
|
|
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
|
|
|
|
|
{
|
2018-11-13 11:48:50 +00:00
|
|
|
|
Console.ForegroundColor = ConsoleColor.Cyan;
|
2018-11-11 09:26:52 +00:00
|
|
|
|
Console.WriteLine(evaluate);
|
2018-11-13 11:48:50 +00:00
|
|
|
|
Console.ResetColor();
|
2018-11-11 09:26:52 +00:00
|
|
|
|
}
|
2018-11-10 12:11:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-11-11 09:26:52 +00:00
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
2018-11-10 12:11:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|