N NezamDocumentation

Validation grammar#

Validation grammar describes validation declarations, validation rules, conditions, severity, targets, and declared message use.

Source#

PropertyValue
Grammar filepackages/business/language/grammar/validation.g4
Grammar namevalidation
Grammar kindparser
Importscommon, type, expression, literal, function
Imported byBusinessLanguage, module
Direct rule or token count5

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: validationDeclaration, ensureStatement, checkStatement, requireStatement.

  • Declarations: validationDeclaration
  • Statements: checkStatement, ensureStatement, requireStatement

Key grammar excerpts#

validationDeclaration#

antlr
validationDeclaration
    : VALIDATION identifier OPEN_BRACE validationRuleMember* CLOSE_BRACE
      // @define @name_fields(identifier) @symbol(kind=global) @scope(level=2)
    ;

ensureStatement#

antlr
ensureStatement: ENSURE expression (MESSAGE stringLiteral)?;

checkStatement#

antlr
checkStatement: CHECK expression (ON identifier)?;

Complete rule and token inventory#

text
checkStatement, ensureStatement, requireStatement, validationDeclaration, validationRuleMember

Examples#

Ensure, check, and require#

bl
validation InvoiceValidation {
  ensure invoice_total > 0 message "InvalidInvoiceTotal";
  check vendor_active on vendor_id;
  require company_code != "" else "CompanyCodeRequired";
}

Reusable validation function#

bl
validation PostingPolicyValidation {
  validate policy_exists(company_code: CompanyCode): bool {
    return company_code != "";
  }
}

Validation helper with parameters#

bl
validation VendorPayloadValidation {
  validate valid_vendor(vendor_id: VendorId, company_code: CompanyCode) -> bool {
    return vendor_id != "" && company_code != "";
  }
}

Common authoring mistakes#

  • Do not make validation silently pass when required lookup data is absent.
  • Point validation failures at declared messages so UI, tests, and service callers receive stable diagnostics.
  • /language/rules-tests-errors/
  • /language/messages-errors/

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/validation.md