diff --git a/FieldArgument.cs b/FieldArgument.cs index 562f5f5..c5a3243 100644 --- a/FieldArgument.cs +++ b/FieldArgument.cs @@ -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()) - {} - public FieldArgument(object instance,FieldInfo fieldInfo) - :this(instance, fieldInfo, fieldInfo.GetCustomAttribute()) - {} - - 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()) + {} + public FieldArgument(object instance,FieldInfo fieldInfo) + :this(instance, fieldInfo, fieldInfo.GetCustomAttribute()) + {} + + 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); } } - } - } + } + } } \ No newline at end of file diff --git a/configuration/ConfigurationContainer.cs b/configuration/ConfigurationContainer.cs new file mode 100644 index 0000000..35eedaa --- /dev/null +++ b/configuration/ConfigurationContainer.cs @@ -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 children = new List(); + Dictionary statements = new Dictionary(); + + 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; + } + } + + } +} diff --git a/configuration/ConfigurationParser.cs b/configuration/ConfigurationParser.cs new file mode 100644 index 0000000..50a2ffb --- /dev/null +++ b/configuration/ConfigurationParser.cs @@ -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 tokenStream = new ArrayStream(tokens.Where((e) => !(e is Token.WhiteSpaceToken))); + ParseContainer(tokenStream,RootContainer); + } + + private void ParseContainer(ArrayStream 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); + + } + } +} diff --git a/ln.application.csproj b/ln.application.csproj index b53d418..fba25d4 100644 --- a/ln.application.csproj +++ b/ln.application.csproj @@ -10,6 +10,7 @@ + diff --git a/ln.application.tests/ConfigurationTest.conf b/ln.application.tests/ConfigurationTest.conf new file mode 100644 index 0000000..23cdf15 --- /dev/null +++ b/ln.application.tests/ConfigurationTest.conf @@ -0,0 +1,8 @@ + +aNumber: 123.987; +anInteger: 45467; +aString: "This is a test string"; + +objectA { + something: "stupid"; +} diff --git a/ln.application.tests/UnitTest1.cs b/ln.application.tests/UnitTest1.cs new file mode 100644 index 0000000..d23c960 --- /dev/null +++ b/ln.application.tests/UnitTest1.cs @@ -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(); + } + + + + + + + } +} \ No newline at end of file diff --git a/ln.application.tests/ln.application.tests.csproj b/ln.application.tests/ln.application.tests.csproj new file mode 100644 index 0000000..e532582 --- /dev/null +++ b/ln.application.tests/ln.application.tests.csproj @@ -0,0 +1,15 @@ + + + + netcoreapp3.1 + + false + + + + + + + + +