From 0fee8ccac98c536826c1a66d8d871594fd263de2 Mon Sep 17 00:00:00 2001 From: Tony Bark Date: Tue, 6 Feb 2024 01:15:33 -0500 Subject: [PATCH] Moved the hard-coded example to a .basic file that is read from a Toml-based project file. - To future-proof myself, the project file also support targeting other versions. - WIP "GOTO" function --- BarkBasic/BarkBasic.csproj | 15 +++++++++++++++ BarkBasic/ChangeLog.md | 9 +++++++++ BarkBasic/Program.cs | 31 +++++++++++++++++++++++-------- BarkBasic/Project.toml | 3 +++ BarkBasic/ProjectFile.cs | 8 ++++++++ BarkBasic/program.basic | 4 ++++ 6 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 BarkBasic/ChangeLog.md create mode 100644 BarkBasic/Project.toml create mode 100644 BarkBasic/ProjectFile.cs create mode 100644 BarkBasic/program.basic diff --git a/BarkBasic/BarkBasic.csproj b/BarkBasic/BarkBasic.csproj index 2f4fc77..9fa8142 100644 --- a/BarkBasic/BarkBasic.csproj +++ b/BarkBasic/BarkBasic.csproj @@ -2,9 +2,24 @@ Exe + 0.1.120 + alpha net8.0 enable enable + + + + + + + PreserveNewest + + + PreserveNewest + + + diff --git a/BarkBasic/ChangeLog.md b/BarkBasic/ChangeLog.md new file mode 100644 index 0000000..b8cc90d --- /dev/null +++ b/BarkBasic/ChangeLog.md @@ -0,0 +1,9 @@ +# Change Log + +## 0.1.120 + +Moved the hard-coded example to a ``.basic`` file that is read from a Toml-based project file. + +## 0.1.100 + +- Initial release. 🎉 \ No newline at end of file diff --git a/BarkBasic/Program.cs b/BarkBasic/Program.cs index 9ae2952..b723cac 100644 --- a/BarkBasic/Program.cs +++ b/BarkBasic/Program.cs @@ -1,10 +1,20 @@ -const string code = """ +using BarkBasic; +using Tomlyn; - 10 PRINT 'Hello, World!' - 20 REM This is a comment - 30 GOTO 10 +var projModel = File.ReadAllText(Path.Combine(Environment.CurrentDirectory, "Project.toml")); +var projFile = Toml.ToModel(projModel); +var code = ""; - """; +try +{ + var path = Path.Combine(Environment.CurrentDirectory, projFile.Code); + if (File.Exists(path)) + code = File.ReadAllText(path); +} +catch (Exception err) +{ + throw new FileNotFoundException(err.StackTrace); +} var lines = code.Split(Environment.NewLine); var lineNumberRegex = new Regex(@"^\d+"); @@ -28,12 +38,17 @@ foreach (var line in lines) Console.WriteLine(printMatch.Groups[1].Value); continue; } - + + // TODO: Finish goto function. var gotoMatch = gotoRegex.Match(line); if (gotoMatch.Success) { - // Handle GOTO statement - continue; + /*using var reader = new StreamReader(projFile.Code); + + for (var i = 1; i < int.Parse(gotoMatch.Groups[1].Value); i++) + reader.ReadLine(); + + Console.WriteLine(reader.ReadLine());*/ } throw new Exception($"Unknown statement in line: {line}"); diff --git a/BarkBasic/Project.toml b/BarkBasic/Project.toml new file mode 100644 index 0000000..b22f426 --- /dev/null +++ b/BarkBasic/Project.toml @@ -0,0 +1,3 @@ +code = "program.basic" +version = "0.1" +channel = "alpha" \ No newline at end of file diff --git a/BarkBasic/ProjectFile.cs b/BarkBasic/ProjectFile.cs new file mode 100644 index 0000000..35d100e --- /dev/null +++ b/BarkBasic/ProjectFile.cs @@ -0,0 +1,8 @@ +namespace BarkBasic; + +public class ProjectFile +{ + public string Code { get; set; } = string.Empty; + public string Version { get; set; } = string.Empty; + public string Channel { get; set; } = string.Empty; +} diff --git a/BarkBasic/program.basic b/BarkBasic/program.basic new file mode 100644 index 0000000..ed233b6 --- /dev/null +++ b/BarkBasic/program.basic @@ -0,0 +1,4 @@ +10 PRINT 'Hello, World!' +20 REM This is a comment +30 GOTO 10 +40 EXIT \ No newline at end of file