type_sections.txt 857 B

123456789101112131415161718192021222324
  1. Type sections
  2. =============
  3. Example:
  4. .. code-block:: nim
  5. type # example demonstrating mutually recursive types
  6. Node = ref NodeObj # a traced pointer to a NodeObj
  7. NodeObj = object
  8. le, ri: Node # left and right subtrees
  9. sym: ref Sym # leaves contain a reference to a Sym
  10. Sym = object # a symbol
  11. name: string # the symbol's name
  12. line: int # the line the symbol was declared in
  13. code: Node # the symbol's abstract syntax tree
  14. A type section begins with the ``type`` keyword. It contains multiple
  15. type definitions. A type definition binds a type to a name. Type definitions
  16. can be recursive or even mutually recursive. Mutually recursive types are only
  17. possible within a single ``type`` section. Nominal types like ``objects``
  18. or ``enums`` can only be defined in a ``type`` section.