N NezamDocumentation

Class grammar#

Class grammar describes object-style declarations, constructors, methods, fields, access modifiers, inheritance, and class members.

Source#

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

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: classDeclaration, businessFieldDeclaration, methodDeclaration, functionReturnType, methodBody, constructorDeclaration, propertyDeclaration, classBindingDeclaration, classUiDeclaration.

  • Declarations: businessFieldDeclaration, classBindingDeclaration, classDeclaration, classUiDeclaration, constructorDeclaration, methodDeclaration, propertyDeclaration
  • Types: functionReturnType
  • Bodies: methodBody

Key grammar excerpts#

classDeclaration#

antlr
classDeclaration
    : annotation* accessModifier? classModifier* CLASS identifier classInheritance? OPEN_BRACE classMemberList? CLOSE_BRACE
      // @define @name_fields(identifier) @role(member_owner) @symbol(kind=global) @scope(level=2)
    ;

businessFieldDeclaration#

antlr
businessFieldDeclaration
    : annotation* accessModifier? FIELD? identifier COLON typeExpression fieldSuffix
      // @define @name_fields(identifier) @symbol(kind=non_local)
    ;

methodDeclaration#

antlr
methodDeclaration
    : annotation* accessModifier? functionModifier* FUNCTION identifier OPEN_PAREN parameterList? CLOSE_PAREN (COLON functionReturnType)? methodBody
      // @define @name_fields(identifier) @symbol(kind=non_local) @scope(level=3)
    ;

Complete rule and token inventory#

text
businessFieldDeclaration, businessRuleMethod, businessRuleMethodList, businessRuleProperty, businessRulePropertyList, businessRulePropertyValue, classBindingDeclaration, classBindingOption
classBindingOptionList, classBindingOptions, classBusinessRule, classDeclaration, classInheritance, classMember, classMemberList, classModifier
classUiDeclaration, classValidation, classValidationRule, classValidationRuleList, constructorDeclaration, functionReturnType, genericParameters, methodBody
methodDeclaration, nestedClass, parameter, parameterList, propertyDeclaration, typeExpressionList, typeParameter, typeParameterList
validationExpr, validationRuleReference

Examples#

Class with method#

bl
class InvoiceTotals {
  field subtotal: money;

  public function total_with_tax(rate: decimal): money {
    return subtotal + (subtotal * rate);
  }
}

Constructor shape#

bl
class VendorSummary {
  field vendor_id: VendorId;
  field display_name: string;
}

Bound implementation view#

bl
class InvoiceWorklist {
  property title: string;

  bind table Invoice as invoices with {
    mode: "readwrite";
    cache: true;
  };

  function refresh(company_code: CompanyCode): Json;
}

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/classes-interfaces/
  • /language/functions-services/

Authoring notes#

  • 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/class.md