Class grammar#
Class grammar describes object-style declarations, constructors, methods, fields, access modifiers, inheritance, and class members.
Source#
| Property | Value |
|---|---|
| Grammar file | packages/business/language/grammar/class.g4 |
| Grammar name | class |
| Grammar kind | parser |
| Imports | common, type, expression, literal, table, source_ui |
| Imported by | BusinessLanguage, module |
| Direct rule or token count | 34 |
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#
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#
businessFieldDeclaration
: annotation* accessModifier? FIELD? identifier COLON typeExpression fieldSuffix
// @define @name_fields(identifier) @symbol(kind=non_local)
;methodDeclaration#
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#
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, validationRuleReferenceExamples#
Class with method#
class InvoiceTotals {
field subtotal: money;
public function total_with_tax(rate: decimal): money {
return subtotal + (subtotal * rate);
}
}Constructor shape#
class VendorSummary {
field vendor_id: VendorId;
field display_name: string;
}Bound implementation view#
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.
Related guides#
- /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.