Source transfer commit
parent
b68568be3a
commit
efa1a64685
|
@ -1,36 +1,36 @@
|
|||
using System.Reflection;
|
||||
using ln.type;
|
||||
|
||||
namespace ln.application
|
||||
{
|
||||
public class FieldArgument : IArgument
|
||||
{
|
||||
public FieldInfo FieldInfo { get; }
|
||||
public object Instance { get;}
|
||||
|
||||
public FieldArgument(FieldInfo fieldInfo)
|
||||
:this(null, fieldInfo, fieldInfo.GetCustomAttribute<StaticArgumentAttribute>())
|
||||
{}
|
||||
public FieldArgument(object instance,FieldInfo fieldInfo)
|
||||
:this(instance, fieldInfo, fieldInfo.GetCustomAttribute<StaticArgumentAttribute>())
|
||||
{}
|
||||
|
||||
public FieldArgument(FieldInfo fieldInfo, StaticArgumentAttribute staticArgumentAttribute)
|
||||
:this(null,fieldInfo,staticArgumentAttribute){}
|
||||
public FieldArgument(object instance,FieldInfo fieldInfo, StaticArgumentAttribute staticArgumentAttribute)
|
||||
{
|
||||
FieldInfo = fieldInfo;
|
||||
OptionName = staticArgumentAttribute?.Option ?? (char)0;
|
||||
LongOptionName = staticArgumentAttribute?.LongOption ?? fieldInfo.Name;
|
||||
HelpString = staticArgumentAttribute?.HelpString ?? "";
|
||||
HasArgument = fieldInfo.FieldType != typeof(bool);
|
||||
Instance = instance;
|
||||
}
|
||||
|
||||
public char OptionName { get; }
|
||||
public string LongOptionName { get; }
|
||||
public bool HasArgument { get; }
|
||||
public string HelpString { get; }
|
||||
using System.Reflection;
|
||||
using ln.type;
|
||||
|
||||
namespace ln.application
|
||||
{
|
||||
public class FieldArgument : IArgument
|
||||
{
|
||||
public FieldInfo FieldInfo { get; }
|
||||
public object Instance { get;}
|
||||
|
||||
public FieldArgument(FieldInfo fieldInfo)
|
||||
:this(null, fieldInfo, fieldInfo.GetCustomAttribute<StaticArgumentAttribute>())
|
||||
{}
|
||||
public FieldArgument(object instance,FieldInfo fieldInfo)
|
||||
:this(instance, fieldInfo, fieldInfo.GetCustomAttribute<StaticArgumentAttribute>())
|
||||
{}
|
||||
|
||||
public FieldArgument(FieldInfo fieldInfo, StaticArgumentAttribute staticArgumentAttribute)
|
||||
:this(null,fieldInfo,staticArgumentAttribute){}
|
||||
public FieldArgument(object instance,FieldInfo fieldInfo, StaticArgumentAttribute staticArgumentAttribute)
|
||||
{
|
||||
FieldInfo = fieldInfo;
|
||||
OptionName = staticArgumentAttribute?.Option ?? (char)0;
|
||||
LongOptionName = staticArgumentAttribute?.LongOption ?? fieldInfo.Name;
|
||||
HelpString = staticArgumentAttribute?.HelpString ?? "";
|
||||
HasArgument = fieldInfo.FieldType != typeof(bool);
|
||||
Instance = instance;
|
||||
}
|
||||
|
||||
public char OptionName { get; }
|
||||
public string LongOptionName { get; }
|
||||
public bool HasArgument { get; }
|
||||
public string HelpString { get; }
|
||||
public string Value
|
||||
{
|
||||
get => FieldInfo.GetValue(Instance)?.ToString();
|
||||
|
@ -45,6 +45,6 @@ namespace ln.application
|
|||
FieldInfo.SetValue(Instance, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace ln.application.configuration
|
||||
{
|
||||
public class ConfigurationContainer
|
||||
{
|
||||
public ConfigurationContainer Parent { get; private set; }
|
||||
|
||||
public String Key { get; set; }
|
||||
|
||||
List<ConfigurationContainer> children = new List<ConfigurationContainer>();
|
||||
Dictionary<string, string[]> statements = new Dictionary<string, string[]>();
|
||||
|
||||
public ConfigurationContainer()
|
||||
{
|
||||
}
|
||||
public ConfigurationContainer(ConfigurationContainer parent)
|
||||
{
|
||||
parent.Add(this);
|
||||
}
|
||||
|
||||
public void Add(ConfigurationContainer child)
|
||||
{
|
||||
if (child.Parent != null)
|
||||
child.Parent.Remove(child);
|
||||
|
||||
children.Add(child);
|
||||
child.Parent = this;
|
||||
}
|
||||
public void Remove(ConfigurationContainer child)
|
||||
{
|
||||
if (child.Parent == this)
|
||||
{
|
||||
children.Remove(child);
|
||||
child.Parent = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
using ln.collections;
|
||||
using ln.parse.tokenizer;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace ln.application.configuration
|
||||
{
|
||||
public class ConfigurationParser
|
||||
{
|
||||
ConfigurationContainer RootContainer { get; }
|
||||
|
||||
public ConfigurationParser()
|
||||
{
|
||||
RootContainer = new ConfigurationContainer();
|
||||
}
|
||||
public ConfigurationParser(ConfigurationContainer rootContainer)
|
||||
{
|
||||
RootContainer = rootContainer;
|
||||
}
|
||||
|
||||
public void Parse(String source)
|
||||
{
|
||||
Parse(configurationTokenizer.Parse(source));
|
||||
}
|
||||
public void Parse(Token[] tokens)
|
||||
{
|
||||
ArrayStream<Token> tokenStream = new ArrayStream<Token>(tokens.Where((e) => !(e is Token.WhiteSpaceToken)));
|
||||
ParseContainer(tokenStream,RootContainer);
|
||||
}
|
||||
|
||||
private void ParseContainer(ArrayStream<Token> tokenStream,ConfigurationContainer container)
|
||||
{
|
||||
while (tokenStream.Current is Token.BracketToken bracket && bracket.Value.Equals("}"))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static Tokenizer configurationTokenizer;
|
||||
|
||||
static ConfigurationParser() {
|
||||
configurationTokenizer = new Tokenizer()
|
||||
.Add(TokenMatcher.WHITESPACE)
|
||||
.Add(TokenMatcher.FLOAT)
|
||||
.Add(TokenMatcher.INTEGER)
|
||||
.Add(TokenMatcher.STRING)
|
||||
.Add(TokenMatcher.OPERATOR)
|
||||
.Add(TokenMatcher.BRACKET);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,6 +10,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ln.parse\ln.parse.csproj" />
|
||||
<ProjectReference Include="..\ln.type\ln.type.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
aNumber: 123.987;
|
||||
anInteger: 45467;
|
||||
aString: "This is a test string";
|
||||
|
||||
objectA {
|
||||
something: "stupid";
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
using NUnit.Framework;
|
||||
using System.IO;
|
||||
|
||||
namespace ln.application.tests
|
||||
{
|
||||
public class Tests
|
||||
{
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
using (StreamReader sr = new StreamReader("ConfigurationTest.conf"))
|
||||
{
|
||||
testConfiguration = sr.ReadToEnd();
|
||||
}
|
||||
}
|
||||
|
||||
string testConfiguration;
|
||||
|
||||
[Test]
|
||||
public void TestTokenizer()
|
||||
{
|
||||
|
||||
|
||||
|
||||
Assert.Pass();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="nunit" Version="3.12.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Loading…
Reference in New Issue