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:
3
VarsetLib/VarsetItem.cs
Normal file
3
VarsetLib/VarsetItem.cs
Normal file
@ -0,0 +1,3 @@
|
||||
namespace VarsetLib;
|
||||
|
||||
public record VarsetItem(string Type, string Name, string Value);
|
9
VarsetLib/VarsetLib.csproj
Normal file
9
VarsetLib/VarsetLib.csproj
Normal 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
68
VarsetLib/VarsetParser.cs
Normal 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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user