Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some expression parse errors #135

Merged
merged 8 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions MonoDevelop.MSBuild.Tests/MSBuildConditionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,80 @@ public void TestMissingOperandWithSpace ()
);
}

[Test]
public void TestMultiLineCondition ()
{
TestParse (
" '$(ImportWindowsDesktopTargets)' == ''\r\n and ('$(UseWpf)' == 'true' Or '$(UseWindowsForms)' == 'true') ",
new ExpressionConditionOperator (
ExpressionOperatorKind.And,
new ExpressionConditionOperator (
ExpressionOperatorKind.Equal,
new QuotedExpression ('\'', new ExpressionProperty (2, "ImportWindowsDesktopTargets")),
new QuotedExpression ('\'', new ExpressionText (38, "", true))
),
new ExpressionParenGroup (73, 57,
new ExpressionConditionOperator (
ExpressionOperatorKind.Or,
new ExpressionConditionOperator (
ExpressionOperatorKind.Equal,
new QuotedExpression ('\'', new ExpressionProperty (75, "UseWpf")),
new QuotedExpression ('\'', new ExpressionText (90, "true", true))
),
new ExpressionConditionOperator (
ExpressionOperatorKind.Equal,
new QuotedExpression ('\'', new ExpressionProperty (100, "UseWindowsForms")),
new QuotedExpression ('\'', new ExpressionText (124, "true", true))
)
)
)
)
);
}

[Test]
public void TestNestedQuotes ()
{
TestParse (
"'@(PackageReference->AnyHaveMetadataValue('Identity', 'Microsoft.Net.Compilers.Toolset.Framework'))' == 'true'",
new ExpressionConditionOperator (
ExpressionOperatorKind.Equal,
new QuotedExpression ('\'',
new ExpressionItem (1, 98,
new ExpressionItemFunctionInvocation (3, 95,
new ExpressionItemName (3, "PackageReference"),
new ExpressionFunctionName (21, "AnyHaveMetadataValue"),
new ExpressionArgumentList (41, 57,
new QuotedExpression ('\'', new ExpressionText (43, "Identity", true)),
new QuotedExpression ('\'', new ExpressionText (55, "Microsoft.Net.Compilers.Toolset.Framework", true))
)
)
)
),
new QuotedExpression ('\'', new ExpressionText (105, "true", true))
)
);
}

[Test]
public void TestUnquotedComparandWithTrailingNewline ()
{
TestParse (
"@(Foo->Count()) == 0\n",
new ExpressionConditionOperator (
ExpressionOperatorKind.Equal,
new ExpressionItem (0, 15,
new ExpressionItemFunctionInvocation (2, 12,
new ExpressionItemName (2, "Foo"),
new ExpressionFunctionName (7, "Count"),
new ExpressionArgumentList (12, 2)
)
),
new ExpressionArgumentInt (19, 1, 0)
)
);
}

static void TestParse (string expression, ExpressionNode expected)
{
var expr = ExpressionParser.ParseCondition (expression, 0);
Expand Down
148 changes: 0 additions & 148 deletions MonoDevelop.MSBuild/Language/CoreDiagnostics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -527,154 +527,6 @@ class CoreDiagnostics
"Items outside targets must have Include, Update or Remove attribute",
MSBuildDiagnosticSeverity.Error);

public static (MSBuildDiagnosticDescriptor, object[]) GetExpressionError (ExpressionError error, ITypedSymbol info)
{
(MSBuildDiagnosticDescriptor, object[]) Return (MSBuildDiagnosticDescriptor desc, params object[] args) => (desc, args);
return error.Kind switch
{
ExpressionErrorKind.MetadataDisallowed => Return (MetadataDisallowed, DescriptionFormatter.GetKindNoun (info), info.Name),
ExpressionErrorKind.EmptyListEntry => Return (EmptyListValue),
ExpressionErrorKind.ExpectingItemName => Return (ExpectingItemName),
ExpressionErrorKind.ExpectingRightParen => Return (ExpectingChar, ')'),
ExpressionErrorKind.ExpectingRightParenOrPeriod => Return (ExpectingCharOrChar, ')', '.'),
ExpressionErrorKind.ExpectingPropertyName => Return (ExpectingPropertyName),
ExpressionErrorKind.ExpectingMetadataName => Return (ExpectingMetadataName),
ExpressionErrorKind.ExpectingMetadataOrItemName => Return (ExpectingMetadataOrItemName),
ExpressionErrorKind.ExpectingRightAngleBracket => Return (ExpectingChar, '>'),
ExpressionErrorKind.ExpectingRightParenOrDash => Return (ExpectingCharOrChar, ')', '-'),
ExpressionErrorKind.ItemsDisallowed => Return (ItemsDisallowed, DescriptionFormatter.GetKindNoun (info), info.Name),
ExpressionErrorKind.ExpectingMethodOrTransform => Return (ExpectingFunctionOrTransform),
ExpressionErrorKind.ExpectingMethodName => Return (ExpectingFunctionName),
ExpressionErrorKind.ExpectingLeftParen => Return (ExpectingChar, '('),
ExpressionErrorKind.ExpectingRightParenOrComma => Return (ExpectingCharOrChar, ')', ','),
ExpressionErrorKind.ExpectingRightParenOrValue => Return (ExpectingRightParenOrValue),
ExpressionErrorKind.ExpectingValue => Return (ExpectingValue),
ExpressionErrorKind.CouldNotParseNumber => Return (CouldNotParseNumber),
ExpressionErrorKind.IncompleteValue => Return (IncompleteValue),
ExpressionErrorKind.ExpectingBracketColonColon => Return (ExpectingChar, "]::"),
ExpressionErrorKind.ExpectingClassName => Return (ExpectingClassName),
ExpressionErrorKind.ExpectingClassNameComponent => Return (IncompleteClassName),
ExpressionErrorKind.IncompleteString => Return (IncompleteString),
ExpressionErrorKind.IncompleteProperty => Return (IncompleteProperty),
_ => throw new System.Exception ($"Unhandled ExpressionErrorKind '{error.Kind}'")
};
}

public const string MetadataDisallowed_Id = nameof(MetadataDisallowed);
public static readonly MSBuildDiagnosticDescriptor MetadataDisallowed = new (
MetadataDisallowed_Id,
"Metadata not permitted",
"{0} `{1}` does not permit metadata",
MSBuildDiagnosticSeverity.Error);

public const string ItemsDisallowed_Id = nameof(ItemsDisallowed);
public static readonly MSBuildDiagnosticDescriptor ItemsDisallowed = new (
ItemsDisallowed_Id,
"Items not permitted",
"{0} `{1}` does not permit items",
MSBuildDiagnosticSeverity.Error);

public const string EmptyListValue_Id = nameof(EmptyListValue);
public static readonly MSBuildDiagnosticDescriptor EmptyListValue = new (
EmptyListValue_Id,
"Empty list value",
MSBuildDiagnosticSeverity.Error);

public const string ExpectingItemName_Id = nameof(ExpectingItemName);
public static readonly MSBuildDiagnosticDescriptor ExpectingItemName = new (
ExpectingItemName_Id,
"Expecting item name",
MSBuildDiagnosticSeverity.Error);

public const string ExpectingChar_Id = nameof(ExpectingChar);
public static readonly MSBuildDiagnosticDescriptor ExpectingChar = new (
ExpectingChar_Id,
"Expecting `{0}`",
MSBuildDiagnosticSeverity.Error);

public const string ExpectingCharOrChar_Id = nameof(ExpectingCharOrChar);
public static readonly MSBuildDiagnosticDescriptor ExpectingCharOrChar = new (
ExpectingCharOrChar_Id,
"Expecting `{0}` or `{1}`",
MSBuildDiagnosticSeverity.Error);

public static readonly MSBuildDiagnosticDescriptor ExpectingPropertyName= new (
nameof (ExpectingPropertyName),
"Expecting property name",
MSBuildDiagnosticSeverity.Error);

public const string ExpectingMetadataName_Id = nameof(ExpectingMetadataName);
public static readonly MSBuildDiagnosticDescriptor ExpectingMetadataName = new (
ExpectingMetadataName_Id,
"Expecting metadata name",
MSBuildDiagnosticSeverity.Error);

public const string ExpectingMetadataOrItemName_Id = nameof(ExpectingMetadataOrItemName);
public static readonly MSBuildDiagnosticDescriptor ExpectingMetadataOrItemName = new (
ExpectingMetadataOrItemName_Id,
"Expecting metadata or item name",
MSBuildDiagnosticSeverity.Error);

public const string ExpectingFunctionName_Id = nameof(ExpectingFunctionName);
public static readonly MSBuildDiagnosticDescriptor ExpectingFunctionName = new (
ExpectingFunctionName_Id,
"Expecting function name",
MSBuildDiagnosticSeverity.Error);

public const string ExpectingValue_Id = nameof(ExpectingValue);
public static readonly MSBuildDiagnosticDescriptor ExpectingValue = new (
ExpectingValue_Id,
"Expecting value",
MSBuildDiagnosticSeverity.Error);

public const string ExpectingFunctionOrTransform_Id = nameof(ExpectingFunctionOrTransform);
public static readonly MSBuildDiagnosticDescriptor ExpectingFunctionOrTransform = new (
ExpectingFunctionOrTransform_Id,
"Expecting item function or transform",
MSBuildDiagnosticSeverity.Error);

public const string ExpectingClassName_Id = nameof(ExpectingClassName);
public static readonly MSBuildDiagnosticDescriptor ExpectingClassName = new (
ExpectingClassName_Id,
"Expecting class name",
MSBuildDiagnosticSeverity.Error);

public const string IncompleteClassName_Id = nameof(IncompleteClassName);
public static readonly MSBuildDiagnosticDescriptor IncompleteClassName = new (
IncompleteClassName_Id,
"Incomplete class name",
MSBuildDiagnosticSeverity.Error);

public const string IncompleteString_Id = nameof(IncompleteString);
public static readonly MSBuildDiagnosticDescriptor IncompleteString = new (
IncompleteString_Id,
"Incomplete string",
MSBuildDiagnosticSeverity.Error);

public const string IncompleteValue_Id = nameof(IncompleteValue);
public static readonly MSBuildDiagnosticDescriptor IncompleteValue = new (
IncompleteValue_Id,
"Incomplete value",
MSBuildDiagnosticSeverity.Error);

public const string IncompleteProperty_Id = nameof(IncompleteProperty);
public static readonly MSBuildDiagnosticDescriptor IncompleteProperty = new (
IncompleteProperty_Id,
"Incomplete property",
MSBuildDiagnosticSeverity.Error);

public const string CouldNotParseNumber_Id = nameof(CouldNotParseNumber);
public static readonly MSBuildDiagnosticDescriptor CouldNotParseNumber = new (
CouldNotParseNumber_Id,
"Invalid number format",
MSBuildDiagnosticSeverity.Error);

public const string ExpectingRightParenOrValue_Id = nameof(ExpectingRightParenOrValue);
public static readonly MSBuildDiagnosticDescriptor ExpectingRightParenOrValue = new (
ExpectingRightParenOrValue_Id,
"Expecting `)` or value",
MSBuildDiagnosticSeverity.Error);

public const string UnwrittenItem_Id = nameof(UnwrittenItem);
public static readonly MSBuildDiagnosticDescriptor UnwrittenItem = new (
UnwrittenItem_Id,
Expand Down
Loading
Loading