N NezamDocumentation

Rule grammar#

Rule grammar describes executable business rules with typed parameters, return types, and block bodies.

Source#

PropertyValue
Grammar filepackages/business/language/grammar/rule.g4
Grammar namerule
Grammar kindparser
Importscommon, type, expression
Imported byBusinessLanguage, module
Direct rule or token count1

How to use this page#

Read the examples first when authoring Business Language. Use the rule inventory when checking exact grammar coverage or when updating parser, lowering, editor, or documentation behavior.

Entry rules and syntax families#

Start with these rules when reading this grammar: ruleDeclaration.

  • Declarations: ruleDeclaration

Key grammar excerpts#

ruleDeclaration#

antlr
ruleDeclaration
    : RULE identifier OPEN_PAREN parameterList? CLOSE_PAREN COLON typeExpression blockStatement
    | RULE identifier SEMICOLON
      // @define @name_fields(identifier) @symbol(kind=global) @scope(level=3)
    ;

Complete rule and token inventory#

text
ruleDeclaration

Examples#

Business rule#

bl
rule invoice_requires_approval(invoice_id: InvoiceId): bool {
  return invoice_total(invoice_id) > approval_limit(invoice_id);
}

Rule declaration shell#

bl
rule vendor_is_active(vendor_id: VendorId): bool {
  return true;
}

Common authoring mistakes#

  • Do not copy examples without checking the rule inventory for the exact grammar boundary.
  • Do not add behavior that depends on missing configuration or undeclared user-facing errors.
  • /language/rules-tests-errors/
  • /language/configuration-resolver-patterns/

Authoring notes#

  • Represent tenant, company, country, process, and time-varying policy as configuration data.
  • Keep examples aligned with the grammar source, not with inferred syntax from another language.
  • Use declared messages for user-facing failures, and fail closed when required configuration is absent.
Source: packages/business/language/grammar-files/rule.md