-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
108 additions
and
583 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.CommandLine; | ||
|
||
namespace HydraScript; | ||
|
||
internal class ExecuteCommand : RootCommand | ||
{ | ||
public ExecuteCommand() : base("HydraScript interpreter") | ||
{ | ||
PathArgument = new Argument<FileInfo>( | ||
name: "path", | ||
description: "Path to input file"); | ||
AddArgument(PathArgument); | ||
|
||
DumpOption = new Option<bool>( | ||
["-d", "--dump"], | ||
getDefaultValue: () => false, | ||
description: "Show dump data of interpreter"); | ||
AddOption(DumpOption); | ||
} | ||
|
||
public Argument<FileInfo> PathArgument { get; } | ||
public Option<bool> DumpOption { get; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System.CommandLine.Invocation; | ||
using HydraScript.Application.CodeGeneration; | ||
using HydraScript.Application.StaticAnalysis.Exceptions; | ||
using HydraScript.Domain.BackEnd; | ||
using HydraScript.Domain.FrontEnd.Lexer; | ||
using HydraScript.Domain.FrontEnd.Parser; | ||
using HydraScript.Infrastructure; | ||
|
||
namespace HydraScript; | ||
|
||
internal class ExecuteCommandHandler( | ||
ISourceCodeProvider sourceCodeProvider, | ||
IParser parser, | ||
ICodeGenerator codeGenerator, | ||
IVirtualMachine virtualMachine, | ||
TextWriter writer) : ICommandHandler | ||
{ | ||
|
||
public int Invoke(InvocationContext context) | ||
{ | ||
try | ||
{ | ||
var sourceCode = sourceCodeProvider.GetText(); | ||
var ast = parser.Parse(sourceCode); | ||
var instructions = codeGenerator.GetInstructions(ast); | ||
virtualMachine.Run(instructions); | ||
return 0; | ||
} | ||
catch (Exception ex) | ||
when (ex is LexerException or ParserException or SemanticException) | ||
{ | ||
writer.WriteLine(ex.Message); | ||
return 1; | ||
} | ||
catch (Exception ex) | ||
{ | ||
writer.WriteLine("Internal HydraScript Error"); | ||
writer.WriteLine(ex); | ||
return 2; | ||
} | ||
} | ||
|
||
public Task<int> InvokeAsync(InvocationContext context) => | ||
Task.FromResult(Invoke(context)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,28 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.IO.Abstractions; | ||
using CommandLine; | ||
using HydraScript.Domain.FrontEnd.Lexer; | ||
using HydraScript.Domain.FrontEnd.Lexer.Impl; | ||
using HydraScript.Lib.FrontEnd.GetTokens; | ||
using HydraScript.Services.CodeGen; | ||
using HydraScript.Services.CodeGen.Impl; | ||
using HydraScript.Services.Executor; | ||
using HydraScript.Services.Executor.Impl; | ||
using HydraScript.Services.Parsing; | ||
using HydraScript.Services.Parsing.Impl; | ||
using HydraScript.Services.Providers.LexerProvider; | ||
using HydraScript.Services.Providers.LexerProvider.Impl; | ||
using HydraScript.Services.Providers.ParserProvider; | ||
using HydraScript.Services.Providers.ParserProvider.Impl; | ||
using HydraScript.Services.Providers.StructureProvider; | ||
using HydraScript.Services.Providers.StructureProvider.Impl; | ||
using HydraScript.Services.SourceCode; | ||
using HydraScript.Services.SourceCode.Impl; | ||
using System.CommandLine.Builder; | ||
using System.CommandLine.Hosting; | ||
using System.CommandLine.Parsing; | ||
using HydraScript; | ||
using HydraScript.Infrastructure; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Options; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace HydraScript; | ||
|
||
[ExcludeFromCodeCoverage] | ||
public static class Program | ||
{ | ||
private static IServiceCollection ServiceCollection { get; } = new ServiceCollection(); | ||
private static IServiceProvider? ServiceProvider { get; set; } | ||
|
||
private static void Main(string[] args) => | ||
Parser.Default.ParseArguments<CommandLineSettings>(args) | ||
.WithParsed(options => | ||
var command = new ExecuteCommand(); | ||
var runner = new CommandLineBuilder(command) | ||
.UseHost( | ||
Host.CreateDefaultBuilder, | ||
configureHost: builder => builder | ||
.ConfigureServices((context, services) => | ||
{ | ||
ConfigureServices(options); | ||
ServiceProvider? | ||
.GetService<IExecutor>()! | ||
.Execute(); | ||
services.AddLogging(c => c.ClearProviders()); | ||
var parseResult = context.GetInvocationContext().ParseResult; | ||
var fileInfo = parseResult.GetValueForArgument(command.PathArgument); | ||
var dump = parseResult.GetValueForOption(command.DumpOption); | ||
services.AddDomain(); | ||
services.AddApplication(); | ||
services.AddInfrastructure(dump, fileInfo); | ||
}) | ||
.WithNotParsed(errors => errors.Output()); | ||
|
||
|
||
private static void ConfigureServices(CommandLineSettings settings) | ||
{ | ||
ServiceCollection.AddSingleton<IStructureProvider, StructureProvider>(); | ||
ServiceCollection.AddSingleton<ILexerProvider, LexerProvider>(); | ||
ServiceCollection.AddSingleton<IParserProvider, ParserProvider>(); | ||
ServiceCollection.AddSingleton<IParsingService, ParsingService>(); | ||
ServiceCollection.AddSingleton<ISourceCodeProvider, SourceCodeProvider>(); | ||
ServiceCollection.AddSingleton<IFileSystem, FileSystem>(); | ||
ServiceCollection.AddSingleton<ITextCoordinateSystemComputer, TextCoordinateSystemComputer>(); | ||
ServiceCollection.AddSingleton<ICodeGenService, CodeGenService>(); | ||
|
||
ServiceCollection.AddSingleton<IExecutor, Executor>(); | ||
.UseCommandHandler<ExecuteCommand, ExecuteCommandHandler>()) | ||
.UseDefaults().Build(); | ||
|
||
ServiceCollection.AddSingleton(_ => Options.Create(settings)); | ||
|
||
ServiceProvider = ServiceCollection.BuildServiceProvider(); | ||
} | ||
} | ||
await runner.InvokeAsync(args); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.