From 7275a035b580627a58aad76a4f5302e05c060afc Mon Sep 17 00:00:00 2001 From: apense Date: Mon, 15 Jun 2015 13:30:09 -0400 Subject: [PATCH] Updated type section a little Objects are ubiquitous. Concepts don't use ``concept`` in their name. Really, a lot more could be added here. --- doc/astspec.txt | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/doc/astspec.txt b/doc/astspec.txt index 0d94757498..1f46070df5 100644 --- a/doc/astspec.txt +++ b/doc/astspec.txt @@ -815,6 +815,50 @@ AST: ) ) +Note that not all ``nnkTypeDef`` utilize ``nnkIdent`` as their +their parameter. One of the most common uses of type declarations +is to work with objects. + +Concrete syntax: + +.. code-block:: nim + type IO = object of RootObj + +AST: + +.. code-block:: nim + # ... + nnkTypeDef( + nnkIdent(!"IO"), + nnkEmpty(), + nnkObjectTy( + nnkEmpty(), # no pragmas here + nnkOfInherit( + nnkIdent(!"RootObj") # inherits from RootObj + ) + nnkEmpty() + ) + ) + +The usage of ``concept`` (experimental) is similar. + +Concrete syntax: + +.. code-block:: nim + type Con = concept x,y,z + (x & y & z) is string + +AST: + +.. code-block:: nim + # ... + nnkTypeClassTy( # note this isn't nnkConceptTy! + nnkArglist( + # ... idents for x, y, z + ) + # ... + ) + Procedure declaration ---------------------