N NezamDocumentation

Service grammar#

Service grammar describes service declarations, operations, endpoints, dependencies, and service-level configuration.

Source#

PropertyValue
Grammar filepackages/business/language/grammar/service.g4
Grammar nameservice
Grammar kindparser
Importscommon, type, expression, literal
Imported byBusinessLanguage, module
Direct rule or token count14

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: serviceDeclaration, serviceInjectDeclaration, functionReturnType, methodBody.

  • Declarations: serviceDeclaration, serviceInjectDeclaration
  • Types: functionReturnType
  • Bodies: methodBody

Key grammar excerpts#

serviceDeclaration#

antlr
serviceDeclaration
    : accessModifier? SERVICE identifier serviceImplements? OPEN_BRACE serviceMemberList? CLOSE_BRACE
    ;

serviceInjectDeclaration#

antlr
serviceInjectDeclaration: INJECT identifier COLON typeExpression SEMICOLON?;

functionReturnType#

antlr
functionReturnType: ASYNC? typeExpression;

Complete rule and token inventory#

text
functionReturnType, methodBody, parameter, parameterList, serviceConfigBlock, serviceConfigProperty, serviceConfigPropertyList, serviceDeclaration
serviceFunction, serviceImplements, serviceInjectDeclaration, serviceLifecycleHook, serviceMember, serviceMemberList

Examples#

Service operation#

bl
service VendorService {
  public function get_vendor(vendor_id: VendorId): VendorDto;
}

Injected dependency and configuration#

bl
public service InvoiceService {
  inject repo: InvoiceRepository;

  configuration {
    client_name: "invoice-repository";
    connection_pool: "default";
  }
}

Lifecycle hook#

bl
service ExchangeRateService {
  on startup {
    let ready = true;
  }
}

Implemented service with async operation#

bl
internal service VendorSyncService implements SyncService, AuditService {
  inject repo: VendorRepository;

  config {
    client_name: "vendor-sync";
    batch_size: 200;
  }

  on startup {
    let ready = true;
  }

  public function sync(company_code: CompanyCode, dry_run: bool = false) -> async Json;
}

Common authoring mistakes#

  • Do not use service-local config blocks for tenant, company, process, or date-varying business policy.
  • Keep service configuration to implementation metadata; resolve routing, retry, approval, and threshold policy from tables and fail closed.
  • /language/services-apis/
  • /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/service.md