Reworked bound variables into specific LuaType class instead of anonymous objects

This commit is contained in:
2018-11-14 13:09:01 +01:00
parent dff1ddc0ba
commit deefe43d9f
17 changed files with 125 additions and 56 deletions

89
Ycicle/Program.cs Normal file
View File

@@ -0,0 +1,89 @@
using System;
using System.Collections.Generic;
using Upsilon;
using Upsilon.BaseTypes;
using Upsilon.Binder;
using Upsilon.Evaluator;
using UpsilonCompiler;
namespace Ycicle
{
internal static class Program
{
private static void Main()
{
Console.WriteLine("Upsilon REPL");
var variables = new Dictionary<VariableSymbol, LuaType>();
var showTranspiledOutput = false;
while (true)
{
Console.Write("» ");
var input = Console.ReadLine();
switch (input)
{
case "exit":
return;
case "compiled":
showTranspiledOutput = !showTranspiledOutput;
break;
}
var parsed = new Script(input, variables);
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;
}
if (showTranspiledOutput)
{
var transpiler = new Transpiler();
var transpiled = transpiler.TranspilerToCSharp(parsed.Bind());
Console.WriteLine(transpiled);
}
else
{
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.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(evaluate);
Console.ResetColor();
}
}
}
}
private 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();
}
}
}

13
Ycicle/Ycicle.csproj Normal file
View File

@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\UpsilonCompiler\UpsilonCompiler.csproj" />
<ProjectReference Include="..\Upsilon\Upsilon.csproj" />
</ItemGroup>
</Project>