Skip to content

Syntax

Constants

Unlike identifiers (type names), constants cannot contain the dash (-) character. However, the grammar of the type name and the constant are identical, so this conflict of semantics will have to be resolved independently during the implementation of a custom solution that uses the TypeLang grammar.

Namespaces specifying a reference to a constant are also allowed.

Given the complete identity of the grammar of constants with named type, they cannot contain case-insensitive names true, false and null of literals.

Example of global constant (or type name)

JSON_THROW_ON_ERROR
type

resultTypeLang\Type\NamedTypeNode

Example of namespaced constant (or type name)

pcov\version
type

resultTypeLang\Type\NamedTypeNode

Class constants begin with any type name, then contain a double colon (::) character, and then the constant name.

Reference to a class constant in the global namespace.

ClassName::CONSTANT_NAME
const

resultTypeLang\Type\Constant\ConstTypeNode

Reference a constant in a class that is located in some namespace.

Path\To\ClassName::ANOTHER_CONSTANT_NAME
const

resultTypeLang\Type\Constant\ConstTypeNode

A reference to a certain set of constants can be defined using a mask: A sequence of name segments with an asterisk (*) standing wherever the name is left unsaid.

A mask is made of at least one asterisk, and its segments and asterisks alternate, so two asterisks in a row describe nothing a single one does not.

Prefixes on class constants can be omitted, so type will mean any class constant.

A global constant may be left unsaid from its very beginning as well, and the namespace it belongs to may be written in front of the mask. A name separated from the mask by a backslash is a namespace whole, so the mask then means any constant that namespace holds.

Reference to any constant with the JSON_ prefix.

JSON_*
mask

resultTypeLang\Type\Constant\ConstMaskTypeNode

Reference to any constant with the _SUFFIX suffix.

*_SUFFIX
mask

resultTypeLang\Type\Constant\ConstMaskTypeNode

Reference to any constant with the JSON_ prefix in the Path\To namespace.

Path\To\JSON_*
mask

resultTypeLang\Type\Constant\ConstMaskTypeNode

Reference to any constant of the Path\To namespace.

Path\To\*
mask

resultTypeLang\Type\Constant\ConstMaskTypeNode

Reference to any constant of the global namespace explicitly.

\*
mask

resultTypeLang\Type\Constant\ConstMaskTypeNode

Several asterisks in one mask.

A*B*C
mask

resultTypeLang\Type\Constant\ConstMaskTypeNode

Reference to any class constant with the PREFIX_ prefix.

Path\To\ClassName::PREFIX_*
mask

resultTypeLang\Type\Constant\ConstMaskTypeNode

Reference to any class constant with the _SUFFIX suffix.

Path\To\ClassName::*_SUFFIX
mask

resultTypeLang\Type\Constant\ConstMaskTypeNode

Reference to any class constant written of the PREFIX_ and _SUFFIX segments, in that order.

Path\To\ClassName::PREFIX_*_SUFFIX
mask

resultTypeLang\Type\Constant\ConstMaskTypeNode

Reference to any class constant

Path\To\ClassName::*
mask

resultTypeLang\Type\Constant\ConstMaskTypeNode