Constant Types
Edit pageLast modified: 02 February 2025Unlike 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.
note
With this in mind, note that any constant is interpreted as a named type.
Given the complete identity of the grammar of constants with named type, they cannot contain case-insensitive names true
, false
and null
of literals.
tip
Example of global constant (or type name)
JSON_THROW_ON_ERROR
tip
Example of namespaced constant (or type name)
pcov\version
warning
The standalone keywords (
true
) is NOT available as an Identifier regardless of case and is parsed as a literal value rather than an Identifier.TrUe
Class Constants
Class constants begin with any type name, then contain a double colon (::
) character, and then the constant name.
tip
Reference to a class constant in the global namespace.
ClassName::CONSTANT_NAME
tip
Reference a constant in a class that is located in some namespace.
Path\To\ClassName::ANOTHER_CONSTANT_NAME
warning
A constant in a class must be an Identifier and cannot contain its own namespace.
ClassName::SOME\ANY
An error similar to the one below should occur
ParseException: Syntax error, unexpected "\"
Constant Masks
A reference to a certain set of constants can be defined using a mask. The use of masks is identical to regular constants, but must be terminated with an asterisk (*
).
Prefixes on class constants can be omitted, so type will mean any class constant.
tip
Reference to any constant with the
JSON_*
prefix.JSON_*
tip
Reference to any class constant with the
PREFIX_
prefix.Path\To\ClassName::PREFIX_*
tip
Reference to any class constant
Path\To\ClassName::*
warning
It is not allowed to omit prefixes from global constants.
*
An error similar to the one below should occur
ParseException: Syntax error, unexpected "*"
warning
The asterisk (
*
) must be the final character.Path\To\ClassName::PREFIX_*_SUFFIX
An error similar to the one below should occur
ParseException: Syntax error, unexpected "_SUFFIX"