-
Notifications
You must be signed in to change notification settings - Fork 1
Simpra DSL Language Tutorial
Simpra DSL is a powerful, type-safe, and extensible expression language for .NET, designed for business rules, data validation, and dynamic logic. It is especially useful for financial and ISO 20022-based data models.
- Introduction
- Basic Syntax
- Variables and Assignment
- Data Types
- Operators
- Conditionals
- Lists and Indexing
- Functions
- Pattern Matching
- Null and Existence Checks
- Mutability
- ISO 20022-Specific Examples
- Advanced Examples
- Grammar and Syntax Reference
Simpra DSL allows you to write business logic and validation rules in a concise, readable way. It supports arithmetic, logical, and comparison operations, as well as advanced features like pattern matching, list operations, and custom functions. It is designed to be safe, predictable, and easy to integrate with .NET models, especially for financial and ISO 20022 data.
- Each statement ends with a newline
- Use
letto declare variables. - Use
returnto output a value.
let x = 10
let y = 20
return x + y
- Variables are declared with
letand can be reassigned if mutability is enabled. - Variable names are case-sensitive by default (can be changed with
$case_sensitivedirective).
let amount = Transfer.Amount
let currency = Transfer.Currency
return amount * 2
-
Numbers:
10,3.14,-5 -
Strings:
'USD',"Test" -
Booleans:
true,false -
Lists:
[1, 2, 3],['USD', 'EUR'] -
Enums:
Color.Red,Color.Green, or just'Green'for comparison -
Nullable:
NullableEnum,Nint1 -
Domain Primitives: e.g.,
Max35Text,NonNegativeAmount -
Dictionaries:
Countries['US'],DictionaryOfObjects['Georgia']
-
+,-,*,/,%,//(integer division)
let total = Transfer.Amount + 100
let percent = Transfer.Amount * 0.05
-
is,is not,<,<=,>,>=
return Transfer.Amount > 100
return Transfer.Currency is 'USD'
return NullableEnum has value
-
and,or,not
return Transfer.Amount > 100 and Transfer.Currency is 'USD'
return not (Transfer.Amount < 0)
-
in,not in
return Transfer.Currency in ['USD', 'EUR']
return Transfer.Currency not in ['USD', 'EUR']
-
matches(regex),like(SQL-like patterns)
return Remittance matches '[A-Z]{4,}'
return Transfer.Currency like 'U%'
let amount = Transfer.Amount
let result = when amount < 50 then 'Low'
when amount >= 50 and amount < 200 then 'Medium'
else 'High'
return result
let x = Transfer.Amount
if x > 100 then
return 'Large'
else
return 'Small'
end
- You can chain
else ifblocks as needed.
let currencies = ['USD', 'EUR', 'GBP']
let numbers = [1, 2, 3, 4]
- Lists and arrays are 1-based.
return currencies[1] // 'USD'
return Transfer.RegulatoryReporting[1].Authority.Country
let all = ['USD', 'EUR'] + 'GEL' // ['USD', 'EUR', 'GEL']
let diff = ['USD', 'EUR', 'GEL'] - ['GEL'] // ['USD', 'EUR']
let sumVal = sum([1, 2, 3]) // 6
let len = length(['USD', 'EUR']) // 2
-
sum(list)- Sum of numeric list -
length(list)- Number of elements -
Upper(str)- Uppercase string -
Lower(str)- Lowercase string
let values = [10, 20, 30]
return sum(values) / length(values)
return Upper('usd') // 'USD'
You can call user-defined functions registered in your host application.
return ListSomeCountries('GE') // ["RU", "BE", "GE"]
let value = 'abc123'
return value matches '[a-zA-Z_][a-zA-Z_0-9]*'
let str = 'foobar'
return str like 'foo%'
- Use
has valueto check for non-null/non-empty values.
return Transfer.Customer has value
return NullableEnum has value
return not (NullableEnum has value) // check if null
By default, Simpra is immutable. Enable mutability to allow assignments:
$mutable on
let x = 10
x = x + 5
return x
You can also assign to model properties:
$mutable on
Transfer.Amount = Transfer.Amount + 50
return Transfer.Amount
// Accessing nested fields
return Transfer.RegulatoryReporting[1].Authority.Country
// Checking for a specific country
return Transfer.RegulatoryReporting[1].Authority.Country is 'US'
// Handling nullable fields
return Transfer.RegulatoryReporting[1].Details[1].Information[0] has value
// Comparing domain primitives
return Transfer.RegulatoryReporting[1].Details[1].Information[0] is 'Information1'
let amounts = [10, 20, 30, 40]
let maxAmount = amounts[3]
return Transfer.Amount > maxAmount
return Remittance matches '[A-Z]{4,}'
return Transfer.Currency in ['USD', 'EUR', 'GBP']
let transfer = Transfer
let amount = transfer.Amount
let ccy = transfer.Currency
let validCurrencies = ['USD', 'EUR', 'GBP']
let increasedAmount = when ccy in validCurrencies then amount + (amount * 0.05) else amount end
return increasedAmount > 180 and increasedAmount < 500
return Countries['US'] is 'United States'
return DictionaryOfObjects['Georgia'].Id
let divisor = 0
let safeDivision = when divisor is not 0 then Transfer.Amount / divisor else 0 end
return safeDivision
return Transfer.RegulatoryReporting[1].Details[1].Information[0]
return Transfer.Customer.Id is 1 // returns false if Transfer or Customer is null
let x = Transfer.Amount
if x > 7 then
return 10
else if x > 5 then
return 6
else if x > 1 then
return 2
else
return round(1000)
end
-
$mutable on|off- Enable/disable mutability -
$case_sensitive on|off- Enable/disable case sensitivity for identifiers
- Variable declaration:
let name = expr - Assignment (if mutable):
name = exprorModel.Property = expr - Return:
return expr - Conditional:
when ... then ... else ... end,if ... then ... else ... end - Function call:
FunctionName(args) - List:
[expr1, expr2, ...] - Indexing:
list[index],dict[key] - Member access:
object.Property
- Numbers, strings, booleans, lists, enums, domain primitives, dictionaries
- Arithmetic:
+,-,*,/,%,// - Comparison:
is,is not,<,<=,>,>= - Logical:
and,or,not - Membership:
in,not in - Pattern:
matches,like - Null:
has value
Simpra DSL is a robust, extensible language for business rules and ISO 20022 data validation. It supports advanced data access, pattern matching, list operations, and custom functions, making it ideal for financial and regulatory applications.
For more details, see the README or your project's documentation.