This library parses and evaluates SPDX license expressions. This library provides a robust and efficient way to handle license expressions in your .NET applications, ensuring compliance with SPDX standards.
- SPDX License Expression Parsing: Parse complex SPDX license expressions with ease.
- License Evaluation: Evaluate license expressions against a given context to determine compliance.
- Customizable Context: Implement your own context to evaluate licenses based on your specific requirements.
- .NET 6.0 SDK or later
Here's a simple example of how to use the library to parse and evaluate a license expression:
using Progalgo.SPDX;
class AcceptedLicensesContext : HashSet<string>, ILegalContext<bool>
{
public bool Evaluate(License license, IEnumerable<Exception> exceptions)
{
return this.Contains(license.Id);
}
public bool EvaluateOption(IEnumerable<bool> vals)
{
return vals.Any(x => x);
}
public bool EvaluateAnd(IEnumerable<bool> vals)
{
return vals.All(x => x);
}
}
class Program
{
static void Main()
{
LicenseExpression expression = new("MIT OR Apache-2.0");
var context = new AcceptedLicensesContext { "MIT" };
bool isCompliant = expression.Evaluate(context);
Console.WriteLine($"Is compliant: {isCompliant}");
}
}
To run the tests, use the following command:
dotnet test
We welcome contributions!
This project is licensed under the GPL License.
- FParsec for the powerful F# parser combinator library used in this project.
For any questions or feedback, please open an issue on GitHub.