N NezamDocumentation

Type grammar#

Type grammar describes primitive types, references, generics, optionals, arrays, maps, unions, intersections, and function types.

Source#

PropertyValue
Grammar filepackages/business/language/grammar/type.g4
Grammar nametype
Grammar kindparser
Importscommon, literal
Imported byannotation, api, app, BusinessLanguage, class, entity, enum, errorHandling, form, function, interface, message, module, query, rule, service, struct, subscription, table, test, validation
Direct rule or token count46

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: typeDeclaration, typeExpression, intersectionType, conditionalType, postfixType, primaryType, builtinType, primitiveType, arrayType, customType.

  • Declarations: typeDeclaration
  • Expressions: conditionalTypeExpression, intersectionTypeExpression, typeExpression, unionTypeExpression
  • Types: arrayType, builtinType, conditionalType, customType, functionType, genericType, intersectionType, mappedType, and 5 more
  • Bodies: constraintBody

Key grammar excerpts#

typeDeclaration#

antlr
typeDeclaration
    : TYPE identifier (COLON typeExpression)? SEMICOLON                      # TypeAlias
    | TYPE identifier OPEN_BRACE typeMemberList? CLOSE_BRACE                # TypeObject
      // @define @name_fields(identifier) @symbol(kind=global) @scope(level=2)
    ;

typeExpression#

antlr
typeExpression
    : intersectionType (PIPE_OP intersectionType)*
      // @kind(type)
    ;

intersectionType#

antlr
intersectionType
    : conditionalType (AMP_OP conditionalType)*
    ;

Complete rule and token inventory#

text
arraySuffix, arraySuffixList, arrayType, builtinType, conditionalType, conditionalTypeExpression, conditionalTypeNoNullable, constraintBody
customType, functionType, genericArgumentSuffix, genericParameter, genericParameterList, genericParameters, genericType, intersectionType
intersectionTypeExpression, intersectionTypeNoNullable, intersectionTypeTail, mappedType, nullableSuffix, postfixType, postfixTypeNoNullable, primaryType
primitiveType, referenceType, tupleType, typeArgumentList, typeArguments, typeConstraint, typeDeclaration, typeExpression
typeExpressionNoNullable, typeLiteralArgument, typeLiteralParameters, typeMember, typeMemberList, typeParameter, typeParameterListCore, typeParameters
typeSuffix, typeSuffixList, typeSuffixListNoNullable, typeSuffixNoNullable, unionTypeExpression, unionTypeTail

Examples#

Optional and array types#

bl
field Tags: string[];
field OptionalVendor: Vendor?;

Generic map type#

bl
field LocalizedText: map<string, string>;

Alias and object types#

bl
type ExternalPartyId: string | uuid;

type PostingPayload {
  invoice_id: InvoiceId;
  amount: money;
}

Grouped, reference, tuple, and mapped aliases#

bl
type IdentifierList: (string | uuid)[];
type InvoiceRef: ref<Invoice>;
type CoordinatePair: (decimal, decimal);
type LocalizedValues: { [K in LocaleKey]: string };

Function type aliases#

bl
type InvoicePredicate: (Invoice) -> bool;
type NowProvider: () -> datetime;

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/types-literals/
  • /language/expressions/

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/type.md