...
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using Nub.Lang.Backend;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Nub.Lang.Backend;
|
||||
using Nub.Lang.Frontend;
|
||||
using Nub.Lang.Frontend.Diagnostics;
|
||||
using Nub.Lang.Frontend.Lexing;
|
||||
using Nub.Lang.Frontend.Parsing;
|
||||
@@ -42,22 +44,7 @@ internal static class Program
|
||||
return 1;
|
||||
}
|
||||
|
||||
List<ModuleNode> modules;
|
||||
try
|
||||
{
|
||||
modules = RunFrontend(input);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
var definitions = modules.SelectMany(f => f.Definitions).ToList();
|
||||
|
||||
var typeChecker = new TypeChecker(definitions);
|
||||
var typeCheckResult = typeChecker.TypeCheck();
|
||||
typeCheckResult.PrintAllDiagnostics();
|
||||
if (typeCheckResult.HasErrors)
|
||||
if (TryRunFrontend(input, out var definitions))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
@@ -69,15 +56,22 @@ internal static class Program
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static List<ModuleNode> RunFrontend(string rootFilePath)
|
||||
private static bool TryRunFrontend(string rootFilePath, out List<DefinitionNode> definitions)
|
||||
{
|
||||
List<ModuleNode> modules = [];
|
||||
RunFrontend(rootFilePath, modules);
|
||||
return modules;
|
||||
var error = TryRunFrontend(rootFilePath, modules);
|
||||
definitions = modules.SelectMany(f => f.Definitions).ToList();
|
||||
|
||||
var typeChecker = new TypeChecker(definitions);
|
||||
var typeCheckResult = typeChecker.TypeCheck();
|
||||
typeCheckResult.PrintAllDiagnostics();
|
||||
error = error || typeCheckResult.HasErrors;
|
||||
return error;
|
||||
}
|
||||
|
||||
private static void RunFrontend(string rootFilePath, List<ModuleNode> modules)
|
||||
private static bool TryRunFrontend(string rootFilePath, List<ModuleNode> modules)
|
||||
{
|
||||
var error = false;
|
||||
var filePaths = Directory.EnumerateFiles(rootFilePath, "*.nub", SearchOption.TopDirectoryOnly);
|
||||
|
||||
List<Token> tokens = [];
|
||||
@@ -89,10 +83,6 @@ internal static class Program
|
||||
|
||||
var parseResult = Parser.ParseModule(tokens, rootFilePath);
|
||||
parseResult.PrintAllDiagnostics();
|
||||
if (parseResult.HasErrors)
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
modules.Add(parseResult.Value);
|
||||
|
||||
@@ -101,8 +91,13 @@ internal static class Program
|
||||
var importPath = Path.GetFullPath(import, parseResult.Value.Path);
|
||||
if (modules.All(m => m.Path != importPath))
|
||||
{
|
||||
RunFrontend(importPath, modules);
|
||||
if (!TryRunFrontend(importPath, modules))
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user