Service grammar#
Service grammar describes service declarations, operations, endpoints, dependencies, and service-level configuration.
Source#
| Property | Value |
|---|---|
| Grammar file | packages/business/language/grammar/service.g4 |
| Grammar name | service |
| Grammar kind | parser |
| Imports | common, type, expression, literal |
| Imported by | BusinessLanguage, module |
| Direct rule or token count | 14 |
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#
serviceDeclaration
: accessModifier? SERVICE identifier serviceImplements? OPEN_BRACE serviceMemberList? CLOSE_BRACE
;serviceInjectDeclaration#
serviceInjectDeclaration: INJECT identifier COLON typeExpression SEMICOLON?;functionReturnType#
functionReturnType: ASYNC? typeExpression;Complete rule and token inventory#
functionReturnType, methodBody, parameter, parameterList, serviceConfigBlock, serviceConfigProperty, serviceConfigPropertyList, serviceDeclaration
serviceFunction, serviceImplements, serviceInjectDeclaration, serviceLifecycleHook, serviceMember, serviceMemberListExamples#
Service operation#
service VendorService {
public function get_vendor(vendor_id: VendorId): VendorDto;
}Injected dependency and configuration#
public service InvoiceService {
inject repo: InvoiceRepository;
configuration {
client_name: "invoice-repository";
connection_pool: "default";
}
}Lifecycle hook#
service ExchangeRateService {
on startup {
let ready = true;
}
}Implemented service with async operation#
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.
Related guides#
- /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.