Skip to content

Parse SPDX License Expressions with sophisticated rules for choosing appropriate license

License

Notifications You must be signed in to change notification settings

progalgo/spdx.net

Repository files navigation

SPDX License Expression Parser and Evaluator

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.

Features

  • 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.

Getting Started

Prerequisites

  • .NET 6.0 SDK or later

Usage

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}");
    }
}

Running Tests

To run the tests, use the following command:

dotnet test

Contributing

We welcome contributions!

License

This project is licensed under the GPL License.

Acknowledgements

  • FParsec for the powerful F# parser combinator library used in this project.

Contact

For any questions or feedback, please open an issue on GitHub.

About

Parse SPDX License Expressions with sophisticated rules for choosing appropriate license

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published