ivanakcheurov / desh.net

Parser, engine and tools for desh language in .net
MIT License
2 stars 0 forks source link

desh.net

Appveyor NuGet License
Build status Test status NuGet Usage License

Why Desh?

Desh is a concise and readable language to describe business rules.

Let's take an example of an online travel agency. Customers want to know if they need a visa when traveling to another country.

The following Desh document describes business rules if a person needs a visa:

nationality:
  - NL:
      destination:
        - US: electronic_online_visa
        - UA:
            days_of_stay:
              - number_greater_than: 90
                decide: paper_visa
              - else: no_visa
  - UA:
      destination:
        - US: paper_visa
        - NL:
            biometric_passport:
              - yes: no_visa
              - no: paper_visa

Then we need customer's data:

nationality: NL
destination: US

Then we can feed this to Desh engine.

var desh = @"
nationality:
  - NL:
      destination:
        - US: electronic_online_visa
        - UA:
            days_of_stay:
              - number_greater_than: 90
                decide: paper_visa
              - else: no_visa
  - UA:
      destination:
        - US: paper_visa
        - NL:
            biometric_passport:
              - yes: no_visa
              - no: paper_visa
";
var customer =
    new Dictionary<string, Func<Task<string>>>
    {
        { "nationality", () => Task.FromResult("NL") },
        { "destination", () => Task.FromResult("US") }
    };
var facade = new DeshFacade();
var visaDecision = await facade.ParseAndMakeStringDecision(desh, customer);
Console.WriteLine($"Visa requirement: {visaDecision}");
// outputs "Visa requirement: electronic_online_visa"

What does the name stand for?

Desh is a phonetic abbreviation of Decision Expressions.