0
mirror of https://github.com/sampletext32/ParkanPlayground.git synced 2025-06-18 23:59:46 +03:00

add varset view

This commit is contained in:
bird_egop
2025-03-01 23:03:13 +03:00
parent 76ef68635e
commit 135777a4c6
11 changed files with 195 additions and 58 deletions

3
VarsetLib/VarsetItem.cs Normal file
View File

@ -0,0 +1,3 @@
namespace VarsetLib;
public record VarsetItem(string Type, string Name, string Value);

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

68
VarsetLib/VarsetParser.cs Normal file
View File

@ -0,0 +1,68 @@
namespace VarsetLib;
public class VarsetParser
{
public static List<VarsetItem> Parse(string path)
{
FileStream fs = new FileStream(path, FileMode.Open);
var reader = new StreamReader(fs);
List<VarsetItem> varsetItems = [];
var lineIndex = 1;
while (!reader.EndOfStream)
{
var line = reader.ReadLine()!;
if (line.Length == 0)
{
lineIndex++;
continue;
}
if (line.StartsWith("//") || line.Trim().StartsWith("//"))
{
lineIndex++;
continue;
}
if (!line.StartsWith("VAR"))
{
Console.WriteLine($"Error on line: {lineIndex}! Not starting with VAR");
lineIndex++;
continue;
}
var openParenthesisIndex = line.IndexOf("(");
var closeParenthesisIndex = line.IndexOf(")");
if (openParenthesisIndex == -1 || closeParenthesisIndex == -1 || closeParenthesisIndex <= openParenthesisIndex)
{
Console.WriteLine($"Error on line: {lineIndex}! VAR() format invalid");
lineIndex++;
continue;
}
var arguments = line.Substring(openParenthesisIndex + 1, closeParenthesisIndex - openParenthesisIndex - 1);
var parts = arguments.Trim()
.Split(',');
var type = parts[0]
.Trim();
var name = parts[1]
.Trim();
var value = parts[2]
.Trim();
var item = new VarsetItem(type, name, value);
varsetItems.Add(item);
lineIndex++;
}
return varsetItems;
}
}