Move cli to own project
This commit is contained in:
16
src/compiler/Nub.Lang.CLI/Nub.Lang.CLI.csproj
Normal file
16
src/compiler/Nub.Lang.CLI/Nub.Lang.CLI.csproj
Normal file
@@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<AssemblyName>nub</AssemblyName>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<PublishAot>true</PublishAot>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Nub.Lang\Nub.Lang.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
57
src/compiler/Nub.Lang.CLI/Program.cs
Normal file
57
src/compiler/Nub.Lang.CLI/Program.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using Nub.Lang.Backend;
|
||||
using Nub.Lang.Frontend.Diagnostics;
|
||||
using Nub.Lang.Frontend.Lexing;
|
||||
using Nub.Lang.Frontend.Parsing;
|
||||
using Nub.Lang.Frontend.Typing;
|
||||
|
||||
if (args.Length != 1)
|
||||
{
|
||||
Console.Error.WriteLine("Usage: nub <input-dir>");
|
||||
Console.Error.WriteLine("Example: nub src");
|
||||
return 1;
|
||||
}
|
||||
|
||||
var srcDir = Path.GetFullPath(args[0]);
|
||||
|
||||
if (!Directory.Exists(srcDir))
|
||||
{
|
||||
Console.Error.WriteLine($"Error: Input directory '{srcDir}' does not exist.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
var error = false;
|
||||
var lexer = new Lexer();
|
||||
var parser = new Parser();
|
||||
var typeChecker = new TypeChecker();
|
||||
|
||||
List<SourceFile> files = [];
|
||||
foreach (var file in Directory.EnumerateFiles(srcDir, "*.nub", SearchOption.AllDirectories))
|
||||
{
|
||||
var content = File.ReadAllText(file);
|
||||
|
||||
var tokenizeResult = lexer.Tokenize(new SourceText(file, content));
|
||||
tokenizeResult.PrintAllDiagnostics();
|
||||
error = error || tokenizeResult.HasErrors;
|
||||
|
||||
var parseResult = parser.ParseModule(tokenizeResult.Value);
|
||||
parseResult.PrintAllDiagnostics();
|
||||
error = error || parseResult.HasErrors;
|
||||
|
||||
if (parseResult.Value != null)
|
||||
{
|
||||
files.Add(parseResult.Value);
|
||||
}
|
||||
}
|
||||
|
||||
var typeCheckResult = typeChecker.TypeCheck(files);
|
||||
typeCheckResult.PrintAllDiagnostics();
|
||||
error = error || typeCheckResult.HasErrors;
|
||||
|
||||
if (error) return 1;
|
||||
|
||||
var generator = new Generator();
|
||||
var result = generator.Generate(files);
|
||||
|
||||
Console.Out.Write(result);
|
||||
|
||||
return 0;
|
||||
@@ -2,6 +2,8 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nub.Lang", "Nub.Lang\Nub.Lang.csproj", "{5047E21F-590D-4CB3-AFF3-064316485009}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nub.Lang.CLI", "Nub.Lang.CLI\Nub.Lang.CLI.csproj", "{A22F17ED-FA17-45AB-92BA-CD02C28B3524}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -12,5 +14,9 @@ Global
|
||||
{5047E21F-590D-4CB3-AFF3-064316485009}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5047E21F-590D-4CB3-AFF3-064316485009}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5047E21F-590D-4CB3-AFF3-064316485009}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{A22F17ED-FA17-45AB-92BA-CD02C28B3524}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A22F17ED-FA17-45AB-92BA-CD02C28B3524}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A22F17ED-FA17-45AB-92BA-CD02C28B3524}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A22F17ED-FA17-45AB-92BA-CD02C28B3524}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<AssemblyName>nub</AssemblyName>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<PublishAot>true</PublishAot>
|
||||
<IsAotCompatible>true</IsAotCompatible>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
using Nub.Lang.Backend;
|
||||
using Nub.Lang.Frontend.Diagnostics;
|
||||
using Nub.Lang.Frontend.Lexing;
|
||||
using Nub.Lang.Frontend.Parsing;
|
||||
using Nub.Lang.Frontend.Typing;
|
||||
|
||||
namespace Nub.Lang;
|
||||
|
||||
internal static class Program
|
||||
{
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
if (args.Length != 1)
|
||||
{
|
||||
Console.Error.WriteLine("Usage: nub <input-dir>");
|
||||
Console.Error.WriteLine("Example: nub src");
|
||||
return 1;
|
||||
}
|
||||
|
||||
var srcDir = Path.GetFullPath(args[0]);
|
||||
|
||||
if (!Directory.Exists(srcDir))
|
||||
{
|
||||
Console.Error.WriteLine($"Error: Input directory '{srcDir}' does not exist.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return Compile(srcDir);
|
||||
}
|
||||
|
||||
private static int Compile(string srcDir)
|
||||
{
|
||||
var error = false;
|
||||
var lexer = new Lexer();
|
||||
var parser = new Parser();
|
||||
var typeChecker = new TypeChecker();
|
||||
|
||||
List<SourceFile> files = [];
|
||||
foreach (var file in Directory.EnumerateFiles(srcDir, "*.nub", SearchOption.AllDirectories))
|
||||
{
|
||||
var content = File.ReadAllText(file);
|
||||
|
||||
var tokenizeResult = lexer.Tokenize(new SourceText(file, content));
|
||||
tokenizeResult.PrintAllDiagnostics();
|
||||
error = error || tokenizeResult.HasErrors;
|
||||
|
||||
var parseResult = parser.ParseModule(tokenizeResult.Value);
|
||||
parseResult.PrintAllDiagnostics();
|
||||
error = error || parseResult.HasErrors;
|
||||
|
||||
if (parseResult.Value != null)
|
||||
{
|
||||
files.Add(parseResult.Value);
|
||||
}
|
||||
}
|
||||
|
||||
var typeCheckResult = typeChecker.TypeCheck(files);
|
||||
typeCheckResult.PrintAllDiagnostics();
|
||||
error = error || typeCheckResult.HasErrors;
|
||||
|
||||
if (error) return 1;
|
||||
|
||||
var generator = new Generator();
|
||||
var result = generator.Generate(files);
|
||||
|
||||
Console.Out.Write(result);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user