| dyvil | v0.31.0 |
|---|
Custom Operators can be defined in Header Files or in the header of a class file. Note that it is not possible to define custom operators anywhere else.
The following syntax is used to define a custom operator:
- The type of operator
infixprefixpostfix
- The keyword
operator - The symbol
- An secondary symbol for ternary operators and circumfix operators - only valid after
infix operatororprefix postfix operator - An optional list of additional comma-separated properties within curly braces. Allowed properties:
precedencefollowed by an integer literalassociativityfollowed by one ofnoneleftright
Example:
prefix operator &
postfix operator ^infix operators also need additional properties to be fully defined, namely a precedence value and an associativity type.
You can define these properties in curly brackets after the name of the operator:
infix operator +- { none, 120 }
// ^ associativity ^ precedenceIt is optional, but recommended for clarity, to type out which property is being defined:
infix operator +- { associativity none, precedence 120 }
infix operator +- { associativity none, 120 }
infix operator +- { none, precedence 120 }The order in which the properties are placed within the brackets does not matter. Duplicate properties are not permitted and will cause a diagnostic error.