From 6d1359c3d9eab3afa557132e9b69518119b5cdc7 Mon Sep 17 00:00:00 2001 From: Jan Date: Sun, 24 Nov 2019 01:56:57 +0100 Subject: [PATCH] ZoneCodeGenerator: Extend count statement without being able to specify * to more precisely state which count should be set --- .../Parsing/CommandFile/Tests/TestCount.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/ZoneCodeGenerator/Parsing/CommandFile/Tests/TestCount.cs b/src/ZoneCodeGenerator/Parsing/CommandFile/Tests/TestCount.cs index 7dc63298..9f3a1887 100644 --- a/src/ZoneCodeGenerator/Parsing/CommandFile/Tests/TestCount.cs +++ b/src/ZoneCodeGenerator/Parsing/CommandFile/Tests/TestCount.cs @@ -12,14 +12,16 @@ namespace ZoneCodeGenerator.Parsing.CommandFile.Tests class TestCount : TestWithEvaluation { private StructureInformation referencedType; - private const string TypeNameToken = "typeName"; + private const string TokenTypeName = "typeName"; + private const string TokenPointerResolve = "pointerResolve"; // set count ; private static readonly TokenMatcher[] matchers = { new MatcherLiteral("set"), new MatcherLiteral("count"), - new MatcherTypename().WithName(TypeNameToken), + new MatcherGroupLoop(MatcherGroupLoop.LoopMode.ZeroOneMultiple, new MatcherLiteral("*").WithName(TokenPointerResolve)), + new MatcherTypename().WithName(TokenTypeName), new MatcherWithTag(TagEvaluation), new MatcherLiteral(";") }; @@ -31,7 +33,7 @@ namespace ZoneCodeGenerator.Parsing.CommandFile.Tests protected override void ProcessMatch(ICommandParserState state) { - var typeName = NextMatch(TypeNameToken); + var typeName = NextMatch(TokenTypeName); var typeNameParts = typeName.Split(new[] { "::" }, StringSplitOptions.None); if (state.DataTypeInUse != null && state.GetMembersFromParts(typeNameParts, state.DataTypeInUse, out var typeMembers)) @@ -59,8 +61,10 @@ namespace ZoneCodeGenerator.Parsing.CommandFile.Tests var evaluation = ProcessEvaluation(state); var referencedMember = typeMembers.Last(); - var reference = referencedMember.Member.VariableType.References.OfType() - .LastOrDefault(); + var reference = referencedMember.Member.VariableType.References + .OfType() + .Skip(GetMatcherTokenCount(TokenPointerResolve)) + .FirstOrDefault(); if (reference != null) reference.Count = evaluation;