...
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Nub.Lang.Backend;
|
||||
using Nub.Lang.Frontend.Diagnostics;
|
||||
using Nub.Lang.Frontend.Lexing;
|
||||
using Nub.Lang.Frontend.Parsing;
|
||||
using Nub.Lang.Frontend.Typing;
|
||||
@@ -41,7 +42,20 @@ internal static class Program
|
||||
return 1;
|
||||
}
|
||||
|
||||
var modules = RunFrontend(input);
|
||||
List<Diagnostic> diagnostics = [];
|
||||
|
||||
var modules = RunFrontend(input, diagnostics);
|
||||
|
||||
foreach (var diagnostic in diagnostics)
|
||||
{
|
||||
Console.WriteLine(diagnostic.Format());
|
||||
}
|
||||
|
||||
if (diagnostics.Any(d => d.Severity == DiagnosticSeverity.Error))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
var definitions = modules.SelectMany(f => f.Definitions).ToList();
|
||||
|
||||
var typeChecker = new TypeChecker(definitions);
|
||||
@@ -54,14 +68,14 @@ internal static class Program
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static List<ModuleNode> RunFrontend(string rootFilePath)
|
||||
private static List<ModuleNode> RunFrontend(string rootFilePath, List<Diagnostic> diagnostics)
|
||||
{
|
||||
List<ModuleNode> modules = [];
|
||||
RunFrontend(rootFilePath, modules);
|
||||
RunFrontend(rootFilePath, modules, diagnostics);
|
||||
return modules;
|
||||
}
|
||||
|
||||
private static void RunFrontend(string rootFilePath, List<ModuleNode> modules)
|
||||
private static void RunFrontend(string rootFilePath, List<ModuleNode> modules, List<Diagnostic> diagnostics)
|
||||
{
|
||||
var filePaths = Directory.EnumerateFiles(rootFilePath, "*.nub", SearchOption.TopDirectoryOnly);
|
||||
|
||||
@@ -73,6 +87,7 @@ internal static class Program
|
||||
}
|
||||
|
||||
var module = Parser.ParseModule(tokens, rootFilePath);
|
||||
diagnostics.AddRange(Parser.Diagnostics);
|
||||
modules.Add(module);
|
||||
|
||||
foreach (var import in module.Imports)
|
||||
@@ -80,7 +95,7 @@ internal static class Program
|
||||
var importPath = Path.GetFullPath(import, module.Path);
|
||||
if (modules.All(m => m.Path != importPath))
|
||||
{
|
||||
RunFrontend(importPath, modules);
|
||||
RunFrontend(importPath, modules, diagnostics);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user