N NezamDocumentation

Function grammar#

Function grammar describes function signatures, parameters, return types, block bodies, expression bodies, and query bodies.

Source#

PropertyValue
Grammar filepackages/business/language/grammar/function.g4
Grammar namefunction
Grammar kindparser
Importscommon, expression, literal, type, query, errorHandling
Imported byBusinessLanguage, form, iac, module, validation
Direct rule or token count9

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#

antlr
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#

antlr
functionReturnType: ASYNC? typeExpression;

functionBody#

antlr
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#

text
deleteQueryStatement, functionBody, functionDeclaration, functionReturnType, functionStatement, functionStatementList, parameter, parameterList
queryStatement

Examples#

Block body#

bl
public function vendor_exists(vendor_id: VendorId): bool {
  select var vendor: Vendor where Vendor.vendor_id = vendor_id;
  return vendor != null;
}

Expression body#

bl
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.
  • /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.
Source: packages/business/language/grammar-files/function.md