Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Feb 19, 2024. It is now read-only.
This repository was archived by the owner on Feb 19, 2024. It is now read-only.

Constraint scripting "language" used through attribute compiling it #44

@Rekkonnect

Description

@Rekkonnect

Credits

Suggested by @KoziLord

Feature Review

The feature would implement a way for the user to specify the constriants in a more natural way through a variation of C#'s syntax for generic constraints that would be parsed and compiled. Syntax errors will be reported as diagnostic errors within the string.

Syntax Error Reporting

The diagnostics reported for syntax errors within the scripting code will have to make use of a brand new rule prefix, GAS. This is so that it can follow the respective C# error rule ID system, without reporting actual CS errors.

Example

Here is an example of an early concept of the implemenation:

[TypeConstraintScript(
@"
IEquatable<int>, IEnumerable<string>, new();
(class; unmanaged), IEquatable<long>, IEnumerable<char>
")]

In that example, the , denotes an AND, ; denotes an OR, and parentheses work as better proioritizing the expression within them. AND has a higher priority than OR, meaning that the first line is a constraint, and the second line is another constraint, requiring that one of the two constraints be met.

More specifically, the type argument must meet one of the following criteria in this case:

  • Implement IEquatable<int>, IEnumerable<string>, and have a new() constructor, OR
  • Be either a class, or an unmanaged struct, and also implement IEquatable<long>, IEnumerable<char>

Passes:

struct S0 : IEquatable<int>, IEnumerable<string>
{
    // implement interfaces
}

Fails:

struct S1 : IEquatable<long>, IEnumerable<char>
{
    private string s;
    // implement interfaces
}

API Design

TODO

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions