Renamed to QR Script

- Split into three projects: Library, Console, and Tests
- Library compiles as QRScript.Interpreter to avoid conflicts
This commit is contained in:
Tony Bark 2025-05-07 15:22:16 -04:00
parent e681e6144c
commit 6501b72973
16 changed files with 82 additions and 20 deletions

View file

@ -0,0 +1,59 @@
namespace QRScript.Console;
[Command("run", Description = "Run a Glyph program.")]
public class RunCommand : ICommand
{
[CommandParameter(0, Name = "file", Description = "Path to the Glyph source file.")]
public string FilePath { get; set; }
[CommandOption("input", 'i', Description = "Path to optional input file.")]
public string InputPath { get; set; }
[CommandOption("binary", 'b', Description = "Run binary file")]
public bool Binary { get; set; }
[CommandOption("verbose", 'v', Description = "Enable verbose output.")]
public bool Verbose { get; set; }
public async ValueTask ExecuteAsync(IConsole console)
{
var lines = new string[] { };
var fileInfo = new FileInfo(FilePath);
var file = fileInfo.FullName;
var dir = Path.GetDirectoryName(FilePath);
var path = Path.Combine(dir, file);
if (!System.IO.File.Exists(path))
{
await console.Error.WriteLineAsync($"Error: File not found: {file}");
return;
}
if (Binary)
{
// TODO: Implement binary file execution
await console.Error.WriteLineAsync($"Error: Binary file execution not implemented");
return;
}
lines = await System.IO.File.ReadAllLinesAsync(path);
var source = lines.JoinLines();
if (!string.IsNullOrEmpty(InputPath))
{
// You could inject input to the interpreter here
string input = await File.ReadAllTextAsync(InputPath);
// TODO: Attach to interpreter input stream
}
if (Verbose)
{
await console.Output.WriteLineAsync($"Executing: {path}");
if (source.ExceedsLengthLimit(1259))
await console.Output.WriteAsync($"Warning: source code exceeds {1259:n} characters.");
}
Runner.Interpret(lines);
}
}