mirror of
https://github.com/tonytins/BarkBasic.git
synced 2025-03-15 05:11:21 +00:00
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
This commit is contained in:
parent
0658337ecf
commit
0fee8ccac9
6 changed files with 62 additions and 8 deletions
|
@ -2,9 +2,24 @@
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
|
<Version>0.1.120</Version>
|
||||||
|
<VersionSuffix>alpha</VersionSuffix>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Tomlyn" Version="0.17.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="program.basic">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Update="Project.toml">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
9
BarkBasic/ChangeLog.md
Normal file
9
BarkBasic/ChangeLog.md
Normal file
|
@ -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. 🎉
|
|
@ -1,10 +1,20 @@
|
||||||
const string code = """
|
using BarkBasic;
|
||||||
|
using Tomlyn;
|
||||||
|
|
||||||
10 PRINT 'Hello, World!'
|
var projModel = File.ReadAllText(Path.Combine(Environment.CurrentDirectory, "Project.toml"));
|
||||||
20 REM This is a comment
|
var projFile = Toml.ToModel<ProjectFile>(projModel);
|
||||||
30 GOTO 10
|
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 lines = code.Split(Environment.NewLine);
|
||||||
var lineNumberRegex = new Regex(@"^\d+");
|
var lineNumberRegex = new Regex(@"^\d+");
|
||||||
|
@ -28,12 +38,17 @@ foreach (var line in lines)
|
||||||
Console.WriteLine(printMatch.Groups[1].Value);
|
Console.WriteLine(printMatch.Groups[1].Value);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Finish goto function.
|
||||||
var gotoMatch = gotoRegex.Match(line);
|
var gotoMatch = gotoRegex.Match(line);
|
||||||
if (gotoMatch.Success)
|
if (gotoMatch.Success)
|
||||||
{
|
{
|
||||||
// Handle GOTO statement
|
/*using var reader = new StreamReader(projFile.Code);
|
||||||
continue;
|
|
||||||
|
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}");
|
throw new Exception($"Unknown statement in line: {line}");
|
||||||
|
|
3
BarkBasic/Project.toml
Normal file
3
BarkBasic/Project.toml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
code = "program.basic"
|
||||||
|
version = "0.1"
|
||||||
|
channel = "alpha"
|
8
BarkBasic/ProjectFile.cs
Normal file
8
BarkBasic/ProjectFile.cs
Normal file
|
@ -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;
|
||||||
|
}
|
4
BarkBasic/program.basic
Normal file
4
BarkBasic/program.basic
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
10 PRINT 'Hello, World!'
|
||||||
|
20 REM This is a comment
|
||||||
|
30 GOTO 10
|
||||||
|
40 EXIT
|
Loading…
Add table
Reference in a new issue