Identifiers & Keywords

Identifiers in Nim can be any string of letters, digits and underscores, with the following restrictions:

  • begins with a letter
  • does not end with an underscore _
  • two immediate following underscores __ are not allowed::

    letter ::= ‘A’..’Z’ | ‘a’..’z’ | ‘x80’..’xff’ digit ::= ‘0’..’9’ IDENTIFIER ::= letter ( [‘_‘] (letter | digit) )*

Currently any Unicode character with an ordinal value > 127 (non ASCII) is classified as a letter and may thus be part of an identifier but later versions of the language may assign some Unicode characters to belong to the operator characters instead.

The following keywords are reserved and cannot be used as identifiers:

  1. addr and as asm
  2. bind block break
  3. case cast concept const continue converter
  4. defer discard distinct div do
  5. elif else end enum except export
  6. finally for from func
  7. if import in include interface is isnot iterator
  8. let
  9. macro method mixin mod
  10. nil not notin
  11. object of or out
  12. proc ptr
  13. raise ref return
  14. shl shr static
  15. template try tuple type
  16. using
  17. var
  18. when while
  19. xor
  20. yield

Some keywords are unused; they are reserved for future developments of the language.