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>
|
||||
<OutputType>Exe</OutputType>
|
||||
<Version>0.1.120</Version>
|
||||
<VersionSuffix>alpha</VersionSuffix>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</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>
|
||||
|
|
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!'
|
||||
20 REM This is a comment
|
||||
30 GOTO 10
|
||||
var projModel = File.ReadAllText(Path.Combine(Environment.CurrentDirectory, "Project.toml"));
|
||||
var projFile = Toml.ToModel<ProjectFile>(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+");
|
||||
|
@ -29,11 +39,16 @@ foreach (var line in lines)
|
|||
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}");
|
||||
|
|
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