Strukturanalyse im Parser ist komplett, Daten müssen nur noch gemapped werden

This commit is contained in:
2014-04-04 08:45:50 +02:00
parent feee17d5d6
commit 709b088a22
3 changed files with 39 additions and 1 deletions

View File

@@ -55,6 +55,7 @@
<Compile Include="src\Parser.cs" /> <Compile Include="src\Parser.cs" />
<Compile Include="src\Backend.cs" /> <Compile Include="src\Backend.cs" />
<Compile Include="src\StringUtils.cs" /> <Compile Include="src\StringUtils.cs" />
<Compile Include="src\ParsingException.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="src\DefaultGui\" /> <Folder Include="src\DefaultGui\" />

View File

@@ -43,7 +43,13 @@ namespace WorldOfPeacecraft
// If package is not complete wait for more lines // If package is not complete wait for more lines
if (!IsCompletePackage()) if (!IsCompletePackage())
return; return;
Block mainBlock = new Block(message, 0, message.Count - 1);
MapData(mainBlock);
}
public void MapData (Block block)
{
// TODO Implement
} }
public bool IsCompletePackage() public bool IsCompletePackage()
@@ -74,12 +80,27 @@ namespace WorldOfPeacecraft
public Block (String[] message, int start, int end) public Block (String[] message, int start, int end)
{ {
int pos = start; int pos = start;
Name = StringUtils.SubstringAfter(message[pos], ":");
pos++;
while (pos < end) while (pos < end)
{ {
// Is the next element a block or a value? // Is the next element a block or a value?
if (message[pos].StartsWith("begin:")) if (message[pos].StartsWith("begin:"))
{ {
// It's a block // It's a block
int blockstart = pos;
int begins = 1;
while (begins > 0)
{
pos++;
if (pos >= end)
throw new ParsingException("The message is missing end:-lines");
if (message[pos].StartsWith("end:"))
begins--;
else if(message[pos].StartsWith("begin:"))
begins++;
}
Blocks.Add(new Block(message, blockstart, pos));
} }
else else
{ {

16
src/ParsingException.cs Normal file
View File

@@ -0,0 +1,16 @@
using System;
using System.Runtime.Serialization;
namespace WorldOfPeacecraft
{
public class ParsingException : Exception
{
public ParsingException () : base();
public ParsingException (string message) : base(message);
public ParsingException (SerializationInfo info, StreamingContext context) : base(info, context);
public ParsingException (string message, Exception innerException) : base(message, innerException);
}
}