.sln reorganization
parent
efa1a64685
commit
02c08aacdf
|
@ -1,42 +0,0 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26124.0
|
||||
MinimumVisualStudioVersion = 15.0.26124.0
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ln.application", "ln.application\ln.application.csproj", "{AA996706-EAD5-47FD-B453-DF12D19F60FB}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ln.application.tests", "ln.application.tests\ln.application.tests.csproj", "{387CB82C-E717-4D11-AE99-1735023E2D51}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{AA996706-EAD5-47FD-B453-DF12D19F60FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{AA996706-EAD5-47FD-B453-DF12D19F60FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{AA996706-EAD5-47FD-B453-DF12D19F60FB}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{AA996706-EAD5-47FD-B453-DF12D19F60FB}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{AA996706-EAD5-47FD-B453-DF12D19F60FB}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{AA996706-EAD5-47FD-B453-DF12D19F60FB}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{AA996706-EAD5-47FD-B453-DF12D19F60FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{AA996706-EAD5-47FD-B453-DF12D19F60FB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{AA996706-EAD5-47FD-B453-DF12D19F60FB}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{AA996706-EAD5-47FD-B453-DF12D19F60FB}.Release|x64.Build.0 = Release|Any CPU
|
||||
{AA996706-EAD5-47FD-B453-DF12D19F60FB}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{AA996706-EAD5-47FD-B453-DF12D19F60FB}.Release|x86.Build.0 = Release|Any CPU
|
||||
{387CB82C-E717-4D11-AE99-1735023E2D51}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{387CB82C-E717-4D11-AE99-1735023E2D51}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{387CB82C-E717-4D11-AE99-1735023E2D51}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{387CB82C-E717-4D11-AE99-1735023E2D51}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{387CB82C-E717-4D11-AE99-1735023E2D51}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{387CB82C-E717-4D11-AE99-1735023E2D51}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{387CB82C-E717-4D11-AE99-1735023E2D51}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{387CB82C-E717-4D11-AE99-1735023E2D51}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{387CB82C-E717-4D11-AE99-1735023E2D51}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{387CB82C-E717-4D11-AE99-1735023E2D51}.Release|x64.Build.0 = Release|Any CPU
|
||||
{387CB82C-E717-4D11-AE99-1735023E2D51}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{387CB82C-E717-4D11-AE99-1735023E2D51}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -2,7 +2,8 @@
|
|||
aNumber: 123.987;
|
||||
anInteger: 45467;
|
||||
aString: "This is a test string";
|
||||
aString: "Another String";
|
||||
|
||||
objectA {
|
||||
objectA "Container 1" {
|
||||
something: "stupid";
|
||||
}
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
using ln.application.configuration;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace ln.application.tests
|
||||
{
|
||||
public class Tests
|
||||
{
|
||||
StreamWriter output = new StreamWriter(Console.OpenStandardOutput());
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
using (StreamReader sr = new StreamReader("ConfigurationTest.conf"))
|
||||
{
|
||||
testConfiguration = sr.ReadToEnd();
|
||||
}
|
||||
}
|
||||
|
||||
string testConfiguration;
|
||||
|
||||
[Test]
|
||||
public void Test_0_Configuration()
|
||||
{
|
||||
ConfigurationParser configurationParser = new ConfigurationParser();
|
||||
configurationParser.Parse(testConfiguration);
|
||||
|
||||
output.WriteLine("test_0_Configuration(): rootContainer: {0}", configurationParser.RootContainer);
|
||||
output.Flush();
|
||||
|
||||
Assert.AreEqual(1, configurationParser.RootContainer.Children("objectA").Count());
|
||||
|
||||
Assert.Pass();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ln.application.attributes;
|
||||
|
||||
namespace ln.application.tests
|
||||
{
|
||||
public class TestConcfiguration
|
||||
{
|
||||
|
||||
public TestConcfiguration()
|
||||
{
|
||||
}
|
||||
|
||||
List<Decimal> numbers = new List<decimal>();
|
||||
|
||||
|
||||
[ConfigurationStatement(Name = "aNumber")]
|
||||
public void AddNumber(int number)
|
||||
{
|
||||
numbers.Add(new decimal(number));
|
||||
}
|
||||
[ConfigurationStatement(Name = "aNumber")]
|
||||
public void AddNumber(float number)
|
||||
{
|
||||
numbers.Add(new decimal(number));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -6,6 +6,14 @@
|
|||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="ConfigurationTest.conf" CopyToOutputDirectory="PreserveNewest" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ln.application\ln.application.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="nunit" Version="3.12.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
|
||||
|
||||
using System;
|
||||
|
||||
namespace ln.application.attributes
|
||||
{
|
||||
|
||||
public class ConfigurationStatementAttribute: Attribute
|
||||
{
|
||||
|
||||
public String Name { get; set;}
|
||||
|
||||
public ConfigurationStatementAttribute()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,119 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace ln.application.configuration
|
||||
{
|
||||
public class ConfigurationContainer
|
||||
{
|
||||
public ConfigurationContainer Parent { get; private set; }
|
||||
|
||||
public object Key { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
List<ConfigurationStatement> statements = new List<ConfigurationStatement>();
|
||||
Dictionary<string,Dictionary<object,ConfigurationContainer>> children = new Dictionary<string, Dictionary<object, ConfigurationContainer>>();
|
||||
|
||||
public ConfigurationContainer()
|
||||
{
|
||||
}
|
||||
public ConfigurationContainer(ConfigurationContainer parent,string containerName,object containerKey)
|
||||
{
|
||||
Name = containerName;
|
||||
Key = containerKey;
|
||||
parent.Add(this);
|
||||
}
|
||||
|
||||
private void attach(ConfigurationContainer child)
|
||||
{
|
||||
Dictionary<object, ConfigurationContainer> containerList = GetContainerList(child.Name);
|
||||
containerList.Add(child.Key, child);
|
||||
}
|
||||
|
||||
private void detach(ConfigurationContainer child)
|
||||
{
|
||||
Dictionary<object, ConfigurationContainer> containerList = GetContainerList(child.Name);
|
||||
containerList.Remove(child.Key);
|
||||
}
|
||||
|
||||
|
||||
public IEnumerable<ConfigurationContainer> Children() => children.SelectMany((l)=>l.Value.Values);
|
||||
public IEnumerable<ConfigurationContainer> Children(string containerName){
|
||||
if (children.TryGetValue(containerName,out Dictionary<object, ConfigurationContainer> containerList))
|
||||
return containerList.Values;
|
||||
return new ConfigurationContainer[0];
|
||||
}
|
||||
|
||||
Dictionary<object, ConfigurationContainer> GetContainerList(string containerName)
|
||||
{
|
||||
if (!children.TryGetValue(containerName,out Dictionary<object, ConfigurationContainer> containerList))
|
||||
{
|
||||
containerList = new Dictionary<object, ConfigurationContainer>();
|
||||
children.Add(containerName, containerList);
|
||||
}
|
||||
return containerList;
|
||||
}
|
||||
|
||||
|
||||
public ConfigurationContainer GetOrCreate(string containerName) => GetOrCreate(containerName, null);
|
||||
public ConfigurationContainer GetOrCreate(string containerName,object containerKey)
|
||||
{
|
||||
Dictionary<object, ConfigurationContainer> containerList = GetContainerList(containerName);
|
||||
if (!containerList.TryGetValue(containerKey,out ConfigurationContainer childContainer))
|
||||
{
|
||||
childContainer = new ConfigurationContainer(this, containerName, containerKey);
|
||||
}
|
||||
return childContainer;
|
||||
}
|
||||
|
||||
public void Add(ConfigurationContainer child)
|
||||
{
|
||||
if (child.Parent != null)
|
||||
child.Parent.detach(child);
|
||||
|
||||
attach(child);
|
||||
|
||||
child.Parent = this;
|
||||
}
|
||||
public void Remove(ConfigurationContainer child)
|
||||
{
|
||||
if (child.Parent == this)
|
||||
{
|
||||
detach(child);
|
||||
child.Parent = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddStatement(string statementName,object[] arguments) => AddStatement(new ConfigurationStatement(statementName, arguments));
|
||||
public void AddStatement(ConfigurationStatement configurationStatement) => statements.Add(configurationStatement);
|
||||
public IEnumerable<ConfigurationStatement> GetStatements() => statements;
|
||||
public IEnumerable<ConfigurationStatement> GetStatements(string name) => statements.Where((st)=> st.Name.Equals(name));
|
||||
|
||||
void ToString(StringBuilder stringBuilder)
|
||||
{
|
||||
stringBuilder.AppendFormat("{0} {1} {{\n", Name, Key);
|
||||
foreach (ConfigurationStatement statement in statements)
|
||||
{
|
||||
stringBuilder.AppendLine(statement.ToString());
|
||||
}
|
||||
|
||||
foreach (Dictionary<object, ConfigurationContainer> containerList in children.Values)
|
||||
{
|
||||
foreach (ConfigurationContainer child in containerList.Values)
|
||||
child.ToString(stringBuilder);
|
||||
}
|
||||
stringBuilder.AppendFormat("}}\n");
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
ToString(stringBuilder);
|
||||
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
using ln.collections;
|
||||
using ln.parse.tokenizer;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace ln.application.configuration
|
||||
{
|
||||
public class ConfigurationParser
|
||||
{
|
||||
public ConfigurationContainer RootContainer { get; }
|
||||
|
||||
public ConfigurationParser()
|
||||
{
|
||||
RootContainer = new ConfigurationContainer();
|
||||
}
|
||||
public ConfigurationParser(ConfigurationContainer rootContainer)
|
||||
{
|
||||
RootContainer = rootContainer;
|
||||
}
|
||||
|
||||
public void Parse(String source)
|
||||
{
|
||||
Parse(configurationTokenizer.Parse(source, (token) => !(token is Token.WhiteSpaceToken)));
|
||||
}
|
||||
public void Parse(Token[] tokens)
|
||||
{
|
||||
Queue<Token> queue = new Queue<Token>(tokens);
|
||||
ParseContainer(queue, RootContainer);
|
||||
}
|
||||
|
||||
private void ParseContainer(Queue<Token> queue,ConfigurationContainer container)
|
||||
{
|
||||
Token identifier;
|
||||
while (queue.Count > 0)
|
||||
{
|
||||
identifier = queue.Dequeue();
|
||||
if (identifier is Token.BracketToken && "}".Equals(identifier.Value))
|
||||
return;
|
||||
|
||||
if (identifier is Token.IdentifierToken)
|
||||
{
|
||||
Token t2 = queue.Dequeue();
|
||||
if (t2 is Token.OperatorToken && ":".Equals(t2.Value))
|
||||
{
|
||||
List<Object> arguments = new List<object>();
|
||||
Token arg;
|
||||
while (!(((arg = queue.Dequeue()) is Token.OperatorToken) && ";".Equals(arg.Value)))
|
||||
{
|
||||
arguments.Add(arg.NativeValue);
|
||||
}
|
||||
container.AddStatement(identifier.Value,arguments.ToArray());
|
||||
} else {
|
||||
Token key = null;
|
||||
if (!t2.Is<Token.BracketToken>("{"))
|
||||
{
|
||||
key = t2;
|
||||
t2 = queue.Dequeue();
|
||||
}
|
||||
if (!t2.Is<Token.BracketToken>("{"))
|
||||
{
|
||||
throw new FormatException(String.Format("expected '{{' at {0}", t2.TextPosition));
|
||||
}
|
||||
|
||||
ConfigurationContainer childContainer = new ConfigurationContainer(container,identifier.Value,key.NativeValue);
|
||||
ParseContainer(queue, childContainer);
|
||||
// if (queue.Count == 0)
|
||||
// throw new FormatException(String.Format("Missing '}}'"));
|
||||
}
|
||||
} else {
|
||||
throw new FormatException(String.Format("unexepected token: {0}", identifier.Value));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static Tokenizer configurationTokenizer;
|
||||
|
||||
static ConfigurationParser() {
|
||||
configurationTokenizer = Tokenizer.CreateDefaultTokenizer();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
using System;
|
||||
|
||||
namespace ln.application.configuration
|
||||
{
|
||||
|
||||
public class ConfigurationStatement
|
||||
{
|
||||
public string Name { get; }
|
||||
public Object[] Arguments { get; }
|
||||
|
||||
public ConfigurationStatement(string name,object[] arguments)
|
||||
{
|
||||
Name = name;
|
||||
Arguments = arguments;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("{0}: {1}",Name, String.Join(' ', Arguments));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -3,18 +3,19 @@
|
|||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Version>0.1.0</Version>
|
||||
<Version>0.1.1</Version>
|
||||
<Authors>Harald Wolff-Thobaben</Authors>
|
||||
<AssemblyVersion>0.0.1.0</AssemblyVersion>
|
||||
<FileVersion>0.0.1.0</FileVersion>
|
||||
<AssemblyVersion>0.1.1.0</AssemblyVersion>
|
||||
<FileVersion>0.1.1.0</FileVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ln.parse\ln.parse.csproj" />
|
||||
<ProjectReference Include="..\ln.type\ln.type.csproj" />
|
||||
<Folder Include="configuration" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Runtime" Version="4.3.1" />
|
||||
<PackageReference Include="ln.parse" Version="0.0.5" />
|
||||
<PackageReference Include="ln.type" Version="0.1.1" />
|
||||
</ItemGroup>
|
||||
</Project>
|
Loading…
Reference in New Issue