N NezamDocumentation

Table grammar#

Table grammar describes tables, table fields, keys, indexes, relations, storage metadata, audit policy, and constraints.

Source#

PropertyValue
Grammar filepackages/business/language/grammar/table.g4
Grammar nametable
Grammar kindparser
Importscommon, type, expression, literal, source_ui
Imported byBusinessLanguage, class, module
Direct rule or token count37

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: tableDeclaration, eventsDeclaration, tableFieldDeclaration, tableUiDeclaration, computedFieldDeclaration, computedFieldBody, getterFieldDeclaration, constraintDeclaration, constraintType, indexDeclaration.

  • Declarations: computedFieldDeclaration, constraintDeclaration, eventsDeclaration, getterFieldDeclaration, indexDeclaration, tableDeclaration, tableFieldDeclaration, tableUiDeclaration, and 1 more
  • Types: constraintType
  • Bodies: computedFieldBody

Key grammar excerpts#

tableDeclaration#

antlr
tableDeclaration
    : annotation* accessModifier? (TABLE | ENTITY) identifier tableInheritance? OPEN_BRACE tableMemberList? CLOSE_BRACE
      // @define @name_fields(identifier) @role(member_owner) @kind(layout:table) @symbol(kind=global) @scope(level=2)
    ;

eventsDeclaration#

antlr
eventsDeclaration
    : annotation* EVENTS identifier OPEN_BRACE eventDefinitionList? CLOSE_BRACE
      // @define @name_fields(identifier) @symbol(kind=non_local)
    ;

tableFieldDeclaration#

antlr
tableFieldDeclaration
    : annotation* FIELD? identifier COLON typeExpression fieldSuffix
      // @define @name_fields(identifier) @role(member_definition) @kind(member:field) @symbol(kind=non_local)
    ;

Complete rule and token inventory#

text
associatedModifier, checkConstraint, computedFieldBody, computedFieldDeclaration, computedFieldEntry, computedFieldEntryList, constraintDeclaration, constraintDefinition
constraintType, eventDefinition, eventDefinitionList, eventParameter, eventParameterList, eventsDeclaration, fieldModifier, fieldReference
fieldSuffix, foreignKeyConstraint, getterFieldDeclaration, indexDeclaration, indexDeclarationOption, indexDeclarationOptions, primaryKeyConstraint, referentialAction
tableDeclaration, tableFieldDeclaration, tableInheritance, tableMember, tableMemberList, tableUiDeclaration, tableValidationDeclaration, typeExpressionList
uniqueConstraint, validationExpr, validationRule, validationRuleList, validationRuleReference

Examples#

Persistent table#

bl
table Invoice {
  field invoice_id: InvoiceId key origin;
  field vendor_id: VendorId index;
  field invoice_total: money;
}

Configuration table shape#

bl
table ApprovalPolicy {
  field company_code: CompanyCode key;
  field document_type: DocumentType key;
  field threshold_amount: money required;
  field approver_role: string required;
}

Constraints, index, and validation#

bl
table VendorSearch {
  field vendor_id: VendorId key;
  field display_name: string required searchable;
  computed sort_name: string = display_name.lower();
  get label => display_name;

  constraint primary key (vendor_id);
  check (display_name is not null);

  index by_display_name on (display_name) {
    unique: false;
  }

  validation {
    has_name: display_name is not null;
  }
}

Events and foreign key#

bl
table VendorBankAccount {
  field vendor_id: VendorId key;
  field bank_id: BankId key;

  events VendorBankEvents {
    VendorBankCreated created(vendor_id: VendorId, bank_id: BankId);
  }

  foreign key (vendor_id) references Vendor (vendor_id) on delete restrict;
}

Common authoring mistakes#

  • Do not hide configurable policy in function branches when a configuration table can represent it.
  • Declare keys and origin fields deliberately so resolver functions can fail closed on missing or ambiguous rows.
  • /language/table-schema-reference/
  • /language/configuration-tables/

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