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

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

Open
Rekkonnect opened this issue Aug 1, 2021 · 0 comments
Open
Labels
enhancement New feature or request
Milestone

Comments

@Rekkonnect
Copy link
Owner

Rekkonnect commented Aug 1, 2021

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

@Rekkonnect Rekkonnect added the enhancement New feature or request label Aug 1, 2021
@Rekkonnect Rekkonnect added this to the Future milestone Aug 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant