Skip to content

Commit 49db7e4

Browse files
authored
Merge pull request #15 from dotnetprojects/complSign
fix complex symbols
2 parents 73e7fe7 + 3ce09e1 commit 49db7e4

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

TiaCodeGen.Tests/SampleTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ public void ComplexVariableAccessTest1()
346346
var s = new Signal("#A.B.C[#D.E.F, 1]");
347347
s.AddXmlToStringBuilder(1, sb);
348348
var xml = sb.ToString();
349-
Assert.AreEqual("<Access Scope=\"LocalVariable\" UId=\"1\">\r\n<Symbol>\r\n<Component Name=\"A\">\r\n</Component>\r\n<Component Name=\"B\">\r\n</Component>\r\n<Component Name=\"C\">\r\n<Access Scope=\"LocalVariable\">\r\n<Symbol>\r\n<Component Name=\"D\" />\r\n<Component Name=\"E\" />\r\n<Component Name=\"F\" />\r\n<Access Scope=\"LiteralConstant\">\r\n<Constant>\r\n<ConstantType>DInt</ConstantType>\r\n<ConstantValue>1</ConstantValue>\r\n</Constant>\r\n</Access>\r\n</Symbol>\r\n</Access>\r\n</Component>\r\n</Symbol>\r\n</Access>\r\n".Replace("\n","").Replace("\r", ""), xml.Replace("\n", "").Replace("\r", ""));
349+
Assert.AreEqual("<Access Scope=\"LocalVariable\" UId=\"1\">\r\n<Symbol>\r\n<Component Name=\"A\">\r\n</Component>\r\n<Component Name=\"B\">\r\n</Component>\r\n<Component Name=\"C\">\r\n<Access Scope=\"LocalVariable\">\r\n<Symbol>\r\n<Component Name=\"D\" />\r\n<Component Name=\"E\" />\r\n<Component Name=\"F\" />\r\n</Symbol>\r\n</Access>\r\n<Access Scope=\"LiteralConstant\">\r\n<Constant>\r\n<ConstantType>DInt</ConstantType>\r\n<ConstantValue>1</ConstantValue>\r\n</Constant>\r\n</Access>\r\n</Component>\r\n</Symbol>\r\n</Access>\r\n".Replace("\n","").Replace("\r", ""), xml.Replace("\n", "").Replace("\r", ""));
350350
}
351351

352352
[Test]

TiaCodegen/Commands/Signals/Signal.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ public void AddXmlToStringBuilder(ulong id, StringBuilder sb)
350350
sb.AppendLine("<Access Scope=\"" + accessType + "\">");
351351
sb.AppendLine("<Symbol>");
352352
sb.AppendLine("<Component Name=\"" + p1 + "\" />");
353+
bool noClose = false;
353354
while (p1 != null)
354355
{
355356
i++;
@@ -361,14 +362,16 @@ public void AddXmlToStringBuilder(ulong id, StringBuilder sb)
361362
foreach (var p in innerParts.Skip(1))
362363
{
363364
var pNe = p.Trim();
364-
bool close = false;
365365
if (pNe.Contains("]"))
366366
{
367367
pNe = pNe.Substring(0, pNe.Length - 1);
368-
close = true;
369368
}
370369
if (int.TryParse(pNe, out _))
371370
{
371+
noClose = true;
372+
sb.AppendLine("</Symbol>");
373+
sb.AppendLine("</Access>");
374+
372375
sb.AppendLine("<Access Scope=\"LiteralConstant\">");
373376
sb.AppendLine("<Constant>");
374377
sb.AppendLine("<ConstantType>DInt</ConstantType>");
@@ -408,8 +411,11 @@ public void AddXmlToStringBuilder(ulong id, StringBuilder sb)
408411
sb.AppendLine("<Component Name=\"" + p1 + "\" />");
409412
}
410413
}
411-
sb.AppendLine("</Symbol>");
412-
sb.AppendLine("</Access>");
414+
if (!noClose)
415+
{
416+
sb.AppendLine("</Symbol>");
417+
sb.AppendLine("</Access>");
418+
}
413419
}
414420
else
415421
{

0 commit comments

Comments
 (0)