From e89a35d5e03c8139596743b9f88ddfc18a484808 Mon Sep 17 00:00:00 2001 From: Rob Martens Date: Wed, 1 May 2024 14:27:30 -0400 Subject: [PATCH] Allow negative literals in conditions --- MonoDevelop.MSBuild.Tests/MSBuildConditionTests.cs | 2 ++ .../Language/Expressions/ExpressionParser.Conditions.cs | 2 +- MonoDevelop.MSBuild/Language/Expressions/ExpressionParser.cs | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/MonoDevelop.MSBuild.Tests/MSBuildConditionTests.cs b/MonoDevelop.MSBuild.Tests/MSBuildConditionTests.cs index 65cd3407..a939e574 100644 --- a/MonoDevelop.MSBuild.Tests/MSBuildConditionTests.cs +++ b/MonoDevelop.MSBuild.Tests/MSBuildConditionTests.cs @@ -131,6 +131,8 @@ public void TestParenGrouping () [TestCase ("'$(foo)' == '' and ('$(bar)' == '')")] // paren group at end of expression string [TestCase ("")] // empty expression [TestCase (" ")] // whitespace only + [TestCase ("'$(foo)' > 1.0")] // decimal literal + [TestCase ("'$(foo)' > -1.0")] // negative decimal literal public void TestParseNoError (string expressionString) { var expression = ExpressionParser.ParseCondition (expressionString, 0); diff --git a/MonoDevelop.MSBuild/Language/Expressions/ExpressionParser.Conditions.cs b/MonoDevelop.MSBuild/Language/Expressions/ExpressionParser.Conditions.cs index 8617dac3..1d80af84 100644 --- a/MonoDevelop.MSBuild/Language/Expressions/ExpressionParser.Conditions.cs +++ b/MonoDevelop.MSBuild/Language/Expressions/ExpressionParser.Conditions.cs @@ -161,7 +161,7 @@ static ExpressionNode ParseConditionOperand (string buffer, ref int offset, int int start = offset; var ch = buffer[start]; - if (ch == '.' || char.IsDigit (ch)) { + if (ch == '-' || ch == '.' || char.IsDigit (ch)) { return ReadArgumentNumber (buffer, ref offset, endOffset, baseOffset, out hasError); } diff --git a/MonoDevelop.MSBuild/Language/Expressions/ExpressionParser.cs b/MonoDevelop.MSBuild/Language/Expressions/ExpressionParser.cs index 22c4d828..34cd60f2 100644 --- a/MonoDevelop.MSBuild/Language/Expressions/ExpressionParser.cs +++ b/MonoDevelop.MSBuild/Language/Expressions/ExpressionParser.cs @@ -642,7 +642,7 @@ static ExpressionNode ReadArgumentNumber (string buffer, ref int offset, int end goto case '0'; case ',': case ')': case ']': case ' ': case '\r': case '\n': case '\t': return Result (ref offset, out hasError); - case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': + case '-': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': offset++; continue; default: