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
resultTypeLang\Type\NamedTypeNode
Example of namespaced constant (or type name)
pcov\version
resultTypeLang\Type\NamedTypeNode
A reserved word alone, in any case, is a literal, not a constant.
TrUe
resultTypeLang\Type\Literal\BoolLiteralNode
Class constants
Section titled “Class constants”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
resultTypeLang\Type\Constant\ConstTypeNode
Reference a constant in a class that is located in some namespace.
Path\To\ClassName::ANOTHER_CONSTANT_NAME
resultTypeLang\Type\Constant\ConstTypeNode
A constant in a class must be an Identifier and cannot contain its own namespace.
ClassName::SOME\ANY
errorUnexpectedTokenException Unexpected "SOME\", expected an identifier, "true", "false", "null" and other
Constant masks
Section titled “Constant masks”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_*
resultTypeLang\Type\Constant\ConstMaskTypeNode
Reference to any constant with the _SUFFIX suffix.
*_SUFFIX
resultTypeLang\Type\Constant\ConstMaskTypeNode
Reference to any constant with the JSON_ prefix in the Path\To namespace.
Path\To\JSON_*
resultTypeLang\Type\Constant\ConstMaskTypeNode
Reference to any constant of the Path\To namespace.
Path\To\*
resultTypeLang\Type\Constant\ConstMaskTypeNode
Reference to any constant of the global namespace explicitly.
\*
resultTypeLang\Type\Constant\ConstMaskTypeNode
Several asterisks in one mask.
A*B*C
resultTypeLang\Type\Constant\ConstMaskTypeNode
Reference to any class constant with the PREFIX_ prefix.
Path\To\ClassName::PREFIX_*
resultTypeLang\Type\Constant\ConstMaskTypeNode
Reference to any class constant with the _SUFFIX suffix.
Path\To\ClassName::*_SUFFIX
resultTypeLang\Type\Constant\ConstMaskTypeNode
Reference to any class constant written of the PREFIX_ and _SUFFIX
segments, in that order.
Path\To\ClassName::PREFIX_*_SUFFIX
resultTypeLang\Type\Constant\ConstMaskTypeNode
Reference to any class constant
Path\To\ClassName::*
resultTypeLang\Type\Constant\ConstMaskTypeNode
A global mask needs at least one segment of a name, whether it stands in front of the asterisk or behind it. A lone asterisk would mean any constant there is, and that is not a type.
*
errorUnexpectedTokenException Unexpected "*", expected a type name, an identifier, "true", "false" and other
Two asterisks in a row are not a mask.
Path\To\ClassName::PREFIX_**
errorUnexpectedTokenException Unexpected "*"