ZoneCodeGenerator: Make GroupOptional always add Tag due to consistency (Tags get added when matches succeeds)

This commit is contained in:
Jan 2019-10-29 12:20:08 +01:00
parent 7a6df40be5
commit 23f82894b7
2 changed files with 9 additions and 4 deletions

View File

@ -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);

View File

@ -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()