diff --git a/src/ZoneCodeGenerator/Parsing/CommandFile/Tests/TestWithEvaluation.cs b/src/ZoneCodeGenerator/Parsing/CommandFile/Tests/TestWithEvaluation.cs index df6bb1a0..09667594 100644 --- a/src/ZoneCodeGenerator/Parsing/CommandFile/Tests/TestWithEvaluation.cs +++ b/src/ZoneCodeGenerator/Parsing/CommandFile/Tests/TestWithEvaluation.cs @@ -50,7 +50,7 @@ namespace ZoneCodeGenerator.Parsing.CommandFile.Tests private static readonly TokenMatcher evaluation = new MatcherGroupAnd( new MatcherGroupOr( new MatcherGroupAnd( - new MatcherGroupOptional(new MatcherLiteral("!")).WithTag(TagEvaluationNot), + new MatcherGroupOptional(new MatcherLiteral("!").WithTag(TagEvaluationNot)), new MatcherLiteral("("), new MatcherWithTag(TagEvaluation), new MatcherLiteral(")") @@ -60,7 +60,7 @@ namespace ZoneCodeGenerator.Parsing.CommandFile.Tests new MatcherGroupOptional(new MatcherGroupAnd( new MatcherWithTag(TagOperationType), new MatcherWithTag(TagEvaluation) - )).WithTag(TagEvaluationOperation) + ).WithTag(TagEvaluationOperation)) ).WithTag(TagEvaluation); diff --git a/src/ZoneCodeGenerator/Parsing/Matching/Matchers/MatcherGroupOptional.cs b/src/ZoneCodeGenerator/Parsing/Matching/Matchers/MatcherGroupOptional.cs index 7792cd4d..7e88f5d8 100644 --- a/src/ZoneCodeGenerator/Parsing/Matching/Matchers/MatcherGroupOptional.cs +++ b/src/ZoneCodeGenerator/Parsing/Matching/Matchers/MatcherGroupOptional.cs @@ -12,9 +12,14 @@ protected override TokenMatchingResult PerformTest(MatchingContext context, int tokenOffset) { var result = matcher.Test(context, tokenOffset); - result.PrependTag(Tag); - return !result.Successful ? new TokenMatchingResult(true, 0) : result; + if (!result.Successful) + { + result = new TokenMatchingResult(true, 0); + } + + result.PrependTag(Tag); + return result; } protected override string GetIdentifier()