Validation grammar#
Validation grammar describes validation declarations, validation rules, conditions, severity, targets, and declared message use.
Source#
| Property | Value |
|---|---|
| Grammar file | packages/business/language/grammar/validation.g4 |
| Grammar name | validation |
| Grammar kind | parser |
| Imports | common, type, expression, literal, function |
| Imported by | BusinessLanguage, module |
| Direct rule or token count | 5 |
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#
validationDeclaration
: VALIDATION identifier OPEN_BRACE validationRuleMember* CLOSE_BRACE
// @define @name_fields(identifier) @symbol(kind=global) @scope(level=2)
;ensureStatement#
ensureStatement: ENSURE expression (MESSAGE stringLiteral)?;checkStatement#
checkStatement: CHECK expression (ON identifier)?;Complete rule and token inventory#
checkStatement, ensureStatement, requireStatement, validationDeclaration, validationRuleMemberExamples#
Ensure, check, and require#
validation InvoiceValidation {
ensure invoice_total > 0 message "InvalidInvoiceTotal";
check vendor_active on vendor_id;
require company_code != "" else "CompanyCodeRequired";
}Reusable validation function#
validation PostingPolicyValidation {
validate policy_exists(company_code: CompanyCode): bool {
return company_code != "";
}
}Validation helper with parameters#
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.
Related guides#
- /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.