utils.nim 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. ##[
  2. .. include:: ./utils_overview.rst
  3. # This is now a header
  4. ## Next header
  5. ### And so on
  6. # More headers
  7. ###### Up to level 6
  8. #. An enumeration
  9. #. Second idea here.
  10. More text.
  11. 1. Other case value
  12. 2. Second case.
  13. Ref group fn2_ or specific function like `fn2()`_
  14. or `fn2( int )`_ or `fn2(int,
  15. float)`_.
  16. Ref generics like this: binarySearch_ or `binarySearch(openArray[T], K,
  17. proc (T, K))`_ or `proc binarySearch(openArray[T], K, proc (T, K))`_ or
  18. in different style: `proc binarysearch(openarray[T], K, proc(T, K))`_.
  19. Can be combined with export symbols and type parameters:
  20. `binarysearch*[T, K](openArray[T], K, proc (T, K))`_.
  21. With spaces `binary search`_.
  22. Note that `proc` can be used in postfix form: `binarySearch proc`_.
  23. Ref. type like G_ and `type G`_ and `G[T]`_ and `type G*[T]`_.
  24. Group ref. with capital letters works: fN11_ or fn11_
  25. ]##
  26. include ./utils_helpers
  27. type
  28. SomeType* = enum
  29. enumValueA,
  30. enumValueB,
  31. enumValueC
  32. G*[T] = object
  33. val: T
  34. proc someType*(): SomeType =
  35. ## constructor.
  36. SomeType(2)
  37. proc fn2*() = discard ## comment
  38. proc fn2*(x: int) =
  39. ## fn2 comment
  40. discard
  41. proc fn2*(x: int, y: float) =
  42. discard
  43. proc binarySearch*[T, K](a: openArray[T]; key: K;
  44. cmp: proc (x: T; y: K): int {.closure.}): int =
  45. discard
  46. proc fn3*(): auto = 1 ## comment
  47. proc fn4*(): auto = 2 * 3 + 4 ## comment
  48. proc fn5*() ## comment
  49. proc fn5*() = discard
  50. proc fn6*() =
  51. ## comment
  52. proc fn7*() =
  53. ## comment
  54. discard
  55. proc fn8*(): auto =
  56. ## comment
  57. 1+1
  58. func fn9*(a: int): int = 42 ## comment
  59. func fn10*(a: int): int = a ## comment
  60. # Note capital letter N will be handled correctly in
  61. # group references like fN11_ or fn11_
  62. # (or [fN11] or [fn11] in Markdown Syntax):
  63. func fN11*() = discard
  64. func fN11*(x: int) = discard
  65. # bug #9235
  66. template aEnum*(): untyped =
  67. type
  68. A* {.inject.} = enum ## The enum A.
  69. aA
  70. template bEnum*(): untyped =
  71. type
  72. B* {.inject.} = enum ## The enum B.
  73. bB
  74. func someFunc*() =
  75. ## My someFunc.
  76. ## Stuff in `quotes` here.
  77. ## [Some link](https://nim-lang.org)
  78. discard
  79. template fromUtilsGen*(): untyped =
  80. ## should be shown in utils.html only
  81. runnableExamples:
  82. discard "should be in utils.html only, not in module that calls fromUtilsGen"
  83. ## ditto
  84. iterator fromUtils1*(): int =
  85. runnableExamples:
  86. # ok1
  87. assert 1 == 1
  88. # ok2
  89. yield 15
  90. template fromUtils2*() =
  91. ## ok3
  92. runnableExamples:
  93. discard """should be shown as examples for fromUtils2
  94. in module calling fromUtilsGen"""
  95. proc fromUtils3*() =
  96. ## came form utils but should be shown where `fromUtilsGen` is called
  97. runnableExamples: discard """should be shown as examples for fromUtils3
  98. in module calling fromUtilsGen"""
  99. proc f*(x: G[int]) =
  100. ## There is also variant `f(G[string])`_
  101. discard
  102. proc f*(x: G[string]) =
  103. ## See also `f(G[int])`_.
  104. discard
  105. ## Ref. `[]`_ is the same as `proc \`[]\`(G[T])`_ because there are no
  106. ## overloads. The full form: `proc \`[]\`*[T](x: G[T]): T`_
  107. proc `[]`*[T](x: G[T]): T = x.val
  108. ## Ref. `[]=`_ aka `\`[]=\`(G[T], int, T)`_.
  109. proc `[]=`*[T](a: var G[T], index: int, value: T) = discard
  110. ## Ref. `$`_ aka `proc $`_ or `proc \`$\``_.
  111. proc `$`*[T](a: G[T]): string = ""
  112. ## Ref. `$(a: ref SomeType)`_.
  113. proc `$`*[T](a: ref SomeType): string = ""
  114. ## Ref. foo_bar_ aka `iterator foo_bar_`_.
  115. iterator fooBar*(a: seq[SomeType]): int = discard
  116. ## Ref. `fn[T; U,V: SomeFloat]()`_.
  117. proc fn*[T; U, V: SomeFloat]() = discard
  118. ## Ref. `'big`_ or `func \`'big\``_ or `\`'big\`(string)`_.
  119. func `'big`*(a: string): SomeType = discard
  120. ##[
  121. Pandoc Markdown
  122. ===============
  123. Now repeat all the auto links of above in Pandoc Markdown Syntax.
  124. Ref group [fn2] or specific function like [fn2()]
  125. or [fn2( int )] or [fn2(int,
  126. float)].
  127. Ref generics like this: [binarySearch] or [binarySearch(openArray[T], K,
  128. proc (T, K))] or [proc binarySearch(openArray[T], K, proc (T, K))] or
  129. in different style: [proc binarysearch(openarray[T], K, proc(T, K))].
  130. Can be combined with export symbols and type parameters:
  131. [binarysearch*[T, K](openArray[T], K, proc (T, K))].
  132. With spaces [binary search].
  133. Note that `proc` can be used in postfix form: [binarySearch proc].
  134. Ref. type like [G] and [type G] and [G[T]] and [type G*[T]].
  135. Group ref. with capital letters works: [fN11] or [fn11]
  136. Ref. [`[]`] is the same as [proc `[]`(G[T])] because there are no
  137. overloads. The full form: [proc `[]`*[T](x: G[T]): T]
  138. Ref. [`[]=`] aka [`[]=`(G[T], int, T)].
  139. Ref. [$] aka [proc $] or [proc `$`].
  140. Ref. [$(a: ref SomeType)].
  141. Ref. [foo_bar] aka [iterator foo_bar_].
  142. Ref. [fn[T; U,V: SomeFloat]()].
  143. Ref. ['big] or [func `'big`] or [`'big`(string)].
  144. Link name syntax
  145. ----------------
  146. Pandoc Markdown has synax for changing text of links:
  147. Ref. [this proc][`[]`] or [another symbol][G[T]].
  148. Symbols documentation
  149. ---------------------
  150. Let us repeat auto links from symbols section below:
  151. There is also variant [f(G[string])].
  152. See also [f(G[int])].
  153. ]##