89 lines
1.7 KiB
C#
89 lines
1.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text.Json;
|
|
|
|
namespace luaaaaah;
|
|
|
|
public class Program
|
|
{
|
|
internal static JsonSerializerOptions options = new()
|
|
{
|
|
IncludeFields = true,
|
|
WriteIndented = true,
|
|
};
|
|
public static void Main(string[] args)
|
|
{
|
|
switch(args[0])
|
|
{
|
|
case "test":
|
|
{
|
|
Test(args[1]);
|
|
}
|
|
break;
|
|
case "run":
|
|
{
|
|
Run(args[1], true);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
public static void Run(string file, bool debug)
|
|
{
|
|
Token[] tokens = new Tokenizer().Tokenize(File.ReadAllText(file));
|
|
if(debug)
|
|
{
|
|
foreach(Token token in tokens)
|
|
{
|
|
Console.WriteLine($"{token.region}: {token.type} {{{token.data}}}");
|
|
}
|
|
}
|
|
if(Path.GetFileName(file).StartsWith("tokenizer"))
|
|
{
|
|
Console.WriteLine($"Skipping parsing of `{file}`");
|
|
}
|
|
else
|
|
{
|
|
Parser.ChunkNode root = new Parser().Parse(tokens);
|
|
if(debug)
|
|
{
|
|
Console.WriteLine("Parsed tree:");
|
|
Console.WriteLine(JsonSerializer.Serialize(root, options: options));
|
|
}
|
|
}
|
|
}
|
|
static readonly Dictionary<string, string> failedFiles = [];
|
|
public static void Test(string directory)
|
|
{
|
|
TestRecursive(directory);
|
|
Console.WriteLine("===FAILED===");
|
|
foreach(KeyValuePair<string, string> entry in failedFiles)
|
|
{
|
|
Console.WriteLine($"{entry.Key}: {entry.Value}");
|
|
}
|
|
}
|
|
|
|
public static void TestRecursive(string directory)
|
|
{
|
|
foreach(string file in Directory.EnumerateFiles(directory))
|
|
{
|
|
if(file.EndsWith(".lua"))
|
|
{
|
|
try
|
|
{
|
|
Run(file, false);
|
|
}
|
|
catch(Exception e)
|
|
{
|
|
Console.WriteLine($"{file}: {e}");
|
|
failedFiles.Add(file, e.ToString());
|
|
}
|
|
}
|
|
}
|
|
foreach(string dir in Directory.EnumerateDirectories(directory))
|
|
{
|
|
TestRecursive(dir);
|
|
}
|
|
}
|
|
}
|