Function grammar#
Function grammar describes function signatures, parameters, return types, block bodies, expression bodies, and query bodies.
Source#
| Property | Value |
|---|---|
| Grammar file | packages/business/language/grammar/function.g4 |
| Grammar name | function |
| Grammar kind | parser |
| Imports | common, expression, literal, type, query, errorHandling |
| Imported by | BusinessLanguage, form, iac, module, validation |
| Direct rule or token count | 9 |
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: functionDeclaration, functionReturnType, functionBody, functionStatement, queryStatement, deleteQueryStatement.
- Declarations:
functionDeclaration - Statements:
deleteQueryStatement,functionStatement,queryStatement - Types:
functionReturnType - Bodies:
functionBody
Key grammar excerpts#
functionDeclaration#
functionDeclaration
: annotation* accessModifier? functionModifier* FUNCTION identifier OPEN_PAREN parameterList? CLOSE_PAREN ((COLON | ARROW) functionReturnType)? functionBody
// @define @name_fields(identifier) @symbol(kind=global) @scope(level=3) @runtime_ast_export
;functionReturnType#
functionReturnType: ASYNC? typeExpression;functionBody#
functionBody: OPEN_BRACE functionStatementList? CLOSE_BRACE # BlockFunctionBody
| SEMICOLON # AbstractFunctionBody
| FAT_ARROW deleteQueryStatement # ExpressionQueryFunctionBody
| FAT_ARROW queryStatement # ExpressionQueryFunctionBody
| FAT_ARROW functionStatement # StatementFunctionBody
| FAT_ARROW {
_input.LA(1) != SELECT
&& _input.LA(1) != DELETE
&& _input.LA(1) != INSERT
&& _input.LA(1) != UPDATE
&& _input.LA(1) != SAVE
&& _input.LA(1) != WITH
&& _input.LA(1) != MERGE
}? singleExpression SEMICOLON # ExpressionFunctionBody
;Complete rule and token inventory#
deleteQueryStatement, functionBody, functionDeclaration, functionReturnType, functionStatement, functionStatementList, parameter, parameterList
queryStatementExamples#
Block body#
public function vendor_exists(vendor_id: VendorId): bool {
select var vendor: Vendor where Vendor.vendor_id = vendor_id;
return vendor != null;
}Expression body#
function normalize_code(value: string): string => value.trim().upper();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/functions-services/
- /language/statements-control-flow/
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.