use single backtick (#17141)

This commit is contained in:
flywind 2021-02-21 21:53:28 -06:00 • committed by GitHub
commit 4556901572
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 68 additions and 68 deletions

View file

@ -7,7 +7,7 @@
# distribution, for details about the copyright. # distribution, for details about the copyright.
# #
# An ``include`` file for the different hash set implementations. # An `include` file for the different hash set implementations.
template maxHash(t): untyped = high(t.data) template maxHash(t): untyped = high(t.data)

View file

@ -60,13 +60,13 @@ template withLock(t, x: untyped) =
template withValue*[A, B](t: var SharedTable[A, B], key: A, template withValue*[A, B](t: var SharedTable[A, B], key: A,
value, body: untyped) = value, body: untyped) =
## retrieves the value at ``t[key]``. ## retrieves the value at `t[key]`.
## `value` can be modified in the scope of the ``withValue`` call. ## `value` can be modified in the scope of the `withValue` call.
## ##
## .. code-block:: nim ## .. code-block:: nim
## ##
## sharedTable.withValue(key, value) do: ## sharedTable.withValue(key, value) do:
## # block is executed only if ``key`` in ``t`` ## # block is executed only if `key` in `t`
## # value is threadsafe in block ## # value is threadsafe in block
## value.name = "username" ## value.name = "username"
## value.uid = 1000 ## value.uid = 1000
@ -84,18 +84,18 @@ template withValue*[A, B](t: var SharedTable[A, B], key: A,
template withValue*[A, B](t: var SharedTable[A, B], key: A, template withValue*[A, B](t: var SharedTable[A, B], key: A,
value, body1, body2: untyped) = value, body1, body2: untyped) =
## retrieves the value at ``t[key]``. ## retrieves the value at `t[key]`.
## `value` can be modified in the scope of the ``withValue`` call. ## `value` can be modified in the scope of the `withValue` call.
## ##
## .. code-block:: nim ## .. code-block:: nim
## ##
## sharedTable.withValue(key, value) do: ## sharedTable.withValue(key, value) do:
## # block is executed only if ``key`` in ``t`` ## # block is executed only if `key` in `t`
## # value is threadsafe in block ## # value is threadsafe in block
## value.name = "username" ## value.name = "username"
## value.uid = 1000 ## value.uid = 1000
## do: ## do:
## # block is executed when ``key`` not in ``t`` ## # block is executed when `key` not in `t`
## raise newException(KeyError, "Key not found") ## raise newException(KeyError, "Key not found")
## ##
acquire(t.lock) acquire(t.lock)
@ -112,8 +112,8 @@ template withValue*[A, B](t: var SharedTable[A, B], key: A,
release(t.lock) release(t.lock)
proc mget*[A, B](t: var SharedTable[A, B], key: A): var B = proc mget*[A, B](t: var SharedTable[A, B], key: A): var B =
## retrieves the value at ``t[key]``. The value can be modified. ## retrieves the value at `t[key]`. The value can be modified.
## If `key` is not in `t`, the ``KeyError`` exception is raised. ## If `key` is not in `t`, the `KeyError` exception is raised.
withLock t: withLock t:
var hc: Hash var hc: Hash
var index = rawGet(t, key, hc) var index = rawGet(t, key, hc)
@ -126,10 +126,10 @@ proc mget*[A, B](t: var SharedTable[A, B], key: A): var B =
raise newException(KeyError, "key not found") raise newException(KeyError, "key not found")
proc mgetOrPut*[A, B](t: var SharedTable[A, B], key: A, val: B): var B = proc mgetOrPut*[A, B](t: var SharedTable[A, B], key: A, val: B): var B =
## retrieves value at ``t[key]`` or puts ``val`` if not present, either way ## retrieves value at `t[key]` or puts `val` if not present, either way
## returning a value which can be modified. **Note**: This is inherently ## returning a value which can be modified. **Note**: This is inherently
## unsafe in the context of multi-threading since it returns a pointer ## unsafe in the context of multi-threading since it returns a pointer
## to ``B``. ## to `B`.
withLock t: withLock t:
mgetOrPutImpl(enlarge) mgetOrPutImpl(enlarge)
@ -144,24 +144,24 @@ template tabCellHash(i) = t.data[i].hcode
proc withKey*[A, B](t: var SharedTable[A, B], key: A, proc withKey*[A, B](t: var SharedTable[A, B], key: A,
mapper: proc(key: A, val: var B, pairExists: var bool)) = mapper: proc(key: A, val: var B, pairExists: var bool)) =
## Computes a new mapping for the ``key`` with the specified ``mapper`` ## Computes a new mapping for the `key` with the specified `mapper`
## procedure. ## procedure.
## ##
## The ``mapper`` takes 3 arguments: ## The `mapper` takes 3 arguments:
## ##
## 1. ``key`` - the current key, if it exists, or the key passed to ## 1. `key` - the current key, if it exists, or the key passed to
## ``withKey`` otherwise; ## `withKey` otherwise;
## 2. ``val`` - the current value, if the key exists, or default value ## 2. `val` - the current value, if the key exists, or default value
## of the type otherwise; ## of the type otherwise;
## 3. ``pairExists`` - ``true`` if the key exists, ``false`` otherwise. ## 3. `pairExists` - `true` if the key exists, `false` otherwise.
## ##
## The ``mapper`` can can modify ``val`` and ``pairExists`` values to change ## The `mapper` can can modify `val` and `pairExists` values to change
## the mapping of the key or delete it from the table. ## the mapping of the key or delete it from the table.
## When adding a value, make sure to set ``pairExists`` to ``true`` along ## When adding a value, make sure to set `pairExists` to `true` along
## with modifying the ``val``. ## with modifying the `val`.
## ##
## The operation is performed atomically and other operations on the table ## The operation is performed atomically and other operations on the table
## will be blocked while the ``mapper`` is invoked, so it should be short and ## will be blocked while the `mapper` is invoked, so it should be short and
## simple. ## simple.
## ##
## Example usage: ## Example usage:
@ -196,7 +196,7 @@ proc `[]=`*[A, B](t: var SharedTable[A, B], key: A, val: B) =
putImpl(enlarge) putImpl(enlarge)
proc add*[A, B](t: var SharedTable[A, B], key: A, val: B) = proc add*[A, B](t: var SharedTable[A, B], key: A, val: B) =
## puts a new (key, value)-pair into `t` even if ``t[key]`` already exists. ## puts a new (key, value)-pair into `t` even if `t[key]` already exists.
## This can introduce duplicate keys into the table! ## This can introduce duplicate keys into the table!
withLock t: withLock t:
addImpl(enlarge) addImpl(enlarge)

View file

@ -49,8 +49,8 @@ else:
proc c_unsetenv(env: cstring): cint {. proc c_unsetenv(env: cstring): cint {.
importc: "unsetenv", header: "<stdlib.h>".} importc: "unsetenv", header: "<stdlib.h>".}
# Environment handling cannot be put into RTL, because the ``envPairs`` # Environment handling cannot be put into RTL, because the `envPairs`
# iterator depends on ``environment``. # iterator depends on `environment`.
var var
envComputed {.threadvar.}: bool envComputed {.threadvar.}: bool

View file

@ -20,10 +20,10 @@ proc osErrorMsg*(errorCode: OSErrorCode): string =
## ##
## The error code can be retrieved using the `osLastError proc <#osLastError>`_. ## The error code can be retrieved using the `osLastError proc <#osLastError>`_.
## ##
## If conversion fails, or ``errorCode`` is ``0`` then ``""`` will be ## If conversion fails, or `errorCode` is `0` then `""` will be
## returned. ## returned.
## ##
## On Windows, the ``-d:useWinAnsi`` compilation flag can be used to ## On Windows, the `-d:useWinAnsi` compilation flag can be used to
## make this procedure use the non-unicode Win API calls to retrieve the ## make this procedure use the non-unicode Win API calls to retrieve the
## message. ## message.
## ##
@ -62,15 +62,15 @@ proc newOSError*(
): owned(ref OSError) {.noinline.} = ): owned(ref OSError) {.noinline.} =
## Creates a new `OSError exception <system.html#OSError>`_. ## Creates a new `OSError exception <system.html#OSError>`_.
## ##
## The ``errorCode`` will determine the ## The `errorCode` will determine the
## message, `osErrorMsg proc <#osErrorMsg,OSErrorCode>`_ will be used ## message, `osErrorMsg proc <#osErrorMsg,OSErrorCode>`_ will be used
## to get this message. ## to get this message.
## ##
## The error code can be retrieved using the `osLastError proc ## The error code can be retrieved using the `osLastError proc
## <#osLastError>`_. ## <#osLastError>`_.
## ##
## If the error code is ``0`` or an error message could not be retrieved, ## If the error code is `0` or an error message could not be retrieved,
## the message ``unknown OS error`` will be used. ## the message `unknown OS error` will be used.
## ##
## See also: ## See also:
## * `osErrorMsg proc <#osErrorMsg,OSErrorCode>`_ ## * `osErrorMsg proc <#osErrorMsg,OSErrorCode>`_
@ -99,13 +99,13 @@ proc osLastError*(): OSErrorCode {.sideEffect.} =
## ##
## This procedure is useful in the event when an OS call fails. In that case ## This procedure is useful in the event when an OS call fails. In that case
## this procedure will return the error code describing the reason why the ## this procedure will return the error code describing the reason why the
## OS call failed. The ``OSErrorMsg`` procedure can then be used to convert ## OS call failed. The `OSErrorMsg` procedure can then be used to convert
## this code into a string. ## this code into a string.
## ##
## **Warning**: ## **Warning**:
## The behaviour of this procedure varies between Windows and POSIX systems. ## The behaviour of this procedure varies between Windows and POSIX systems.
## On Windows some OS calls can reset the error code to ``0`` causing this ## On Windows some OS calls can reset the error code to `0` causing this
## procedure to return ``0``. It is therefore advised to call this procedure ## procedure to return `0`. It is therefore advised to call this procedure
## immediately after an OS call fails. On POSIX systems this is not a problem. ## immediately after an OS call fails. On POSIX systems this is not a problem.
## ##
## See also: ## See also:

View file

@ -1,5 +1,5 @@
# Include file that implements 'DirSep' and friends. Do not import this when # Include file that implements 'DirSep' and friends. Do not import this when
# you also import ``os.nim``! # you also import `os.nim`!
# Improved based on info in 'compiler/platform.nim' # Improved based on info in 'compiler/platform.nim'
@ -88,7 +88,7 @@ const
ExtSep* = '.' ExtSep* = '.'
## The character which separates the base filename from the extension; ## The character which separates the base filename from the extension;
## for example, the `'.'` in ``os.nim``. ## for example, the `'.'` in `os.nim`.
# MacOS paths # MacOS paths
# =========== # ===========

View file

@ -13,24 +13,24 @@
import unicode import unicode
proc editDistance*(a, b: string): int {.noSideEffect.} = proc editDistance*(a, b: string): int {.noSideEffect.} =
## Returns the **unicode-rune** edit distance between ``a`` and ``b``. ## Returns the **unicode-rune** edit distance between `a` and `b`.
## ##
## This uses the `Levenshtein`:idx: distance algorithm with only a linear ## This uses the `Levenshtein`:idx: distance algorithm with only a linear
## memory overhead. ## memory overhead.
runnableExamples: static: doAssert editdistance("Kitten", "Bitten") == 1 runnableExamples: static: doAssert editdistance("Kitten", "Bitten") == 1
if len(a) > len(b): if len(a) > len(b):
# make ``b`` the longer string # make `b` the longer string
return editDistance(b, a) return editDistance(b, a)
# strip common prefix # strip common prefix
var var
iStart = 0 ## The character starting index of the first rune in both strings ``a`` and ``b`` iStart = 0 ## The character starting index of the first rune in both strings `a` and `b`
iNextA = 0 iNextA = 0
iNextB = 0 iNextB = 0
runeA, runeB: Rune runeA, runeB: Rune
lenRunesA = 0 ## The number of relevant runes in string ``a``. lenRunesA = 0 ## The number of relevant runes in string `a`.
lenRunesB = 0 ## The number of relevant runes in string ``b``. lenRunesB = 0 ## The number of relevant runes in string `b`.
block commonPrefix: block commonPrefix:
# ``a`` is the shorter string # `a` is the shorter string
while iStart < len(a): while iStart < len(a):
iNextA = iStart iNextA = iStart
a.fastRuneAt(iNextA, runeA, doInc = true) a.fastRuneAt(iNextA, runeA, doInc = true)
@ -44,9 +44,9 @@ proc editDistance*(a, b: string): int {.noSideEffect.} =
var var
# we know that we are either at the start of the strings # we know that we are either at the start of the strings
# or that the current value of runeA is not equal to runeB # or that the current value of runeA is not equal to runeB
# => start search for common suffix after the current rune (``i_next_*``) # => start search for common suffix after the current rune (`i_next_*`)
iEndA = iNextA ## The exclusive upper index bound of string ``a``. iEndA = iNextA ## The exclusive upper index bound of string `a`.
iEndB = iNextB ## The exclusive upper index bound of string ``b``. iEndB = iNextB ## The exclusive upper index bound of string `b`.
iCurrentA = iNextA iCurrentA = iNextA
iCurrentB = iNextB iCurrentB = iNextB
block commonSuffix: block commonSuffix:
@ -69,8 +69,8 @@ proc editDistance*(a, b: string): int {.noSideEffect.} =
addRunesB = 0 addRunesB = 0
iCurrentA = iNextA iCurrentA = iNextA
iCurrentB = iNextB iCurrentB = iNextB
if iCurrentA >= len(a): # ``a`` exhausted if iCurrentA >= len(a): # `a` exhausted
if iCurrentB < len(b): # ``b`` not exhausted if iCurrentB < len(b): # `b` not exhausted
iEndA = iCurrentA iEndA = iCurrentA
iEndB = iCurrentB iEndB = iCurrentB
inc(lenRunesA, addRunesA) inc(lenRunesA, addRunesA)
@ -79,7 +79,7 @@ proc editDistance*(a, b: string): int {.noSideEffect.} =
b.fastRuneAt(iEndB, runeB) b.fastRuneAt(iEndB, runeB)
inc(lenRunesB) inc(lenRunesB)
if iEndB >= len(b): break if iEndB >= len(b): break
elif iCurrentB >= len(b): # ``b`` exhausted and ``a`` not exhausted elif iCurrentB >= len(b): # `b` exhausted and `a` not exhausted
iEndA = iCurrentA iEndA = iCurrentA
iEndB = iCurrentB iEndB = iCurrentB
inc(lenRunesA, addRunesA) inc(lenRunesA, addRunesA)

View file

@ -12,7 +12,7 @@
## **Since**: Version 1.4. ## **Since**: Version 1.4.
## ##
## One can test for the existance of this standard module ## One can test for the existance of this standard module
## via ``defined(nimHasEffectTraitsModule)``. ## via `defined(nimHasEffectTraitsModule)`.
import macros import macros
@ -22,33 +22,33 @@ proc isGcSafeImpl(n: NimNode): bool = discard "see compiler/vmops.nim"
proc hasNoSideEffectsImpl(n: NimNode): bool = discard "see compiler/vmops.nim" proc hasNoSideEffectsImpl(n: NimNode): bool = discard "see compiler/vmops.nim"
proc getRaisesList*(fn: NimNode): NimNode = proc getRaisesList*(fn: NimNode): NimNode =
## Extracts the ``.raises`` list of the func/proc/etc ``fn``. ## Extracts the `.raises` list of the func/proc/etc `fn`.
## ``fn`` has to be a resolved symbol of kind ``nnkSym``. This ## `fn` has to be a resolved symbol of kind `nnkSym`. This
## implies that the macro that calls this proc should accept ``typed`` ## implies that the macro that calls this proc should accept `typed`
## arguments and not ``untyped`` arguments. ## arguments and not `untyped` arguments.
expectKind fn, nnkSym expectKind fn, nnkSym
result = getRaisesListImpl(fn) result = getRaisesListImpl(fn)
proc getTagsList*(fn: NimNode): NimNode = proc getTagsList*(fn: NimNode): NimNode =
## Extracts the ``.tags`` list of the func/proc/etc ``fn``. ## Extracts the `.tags` list of the func/proc/etc `fn`.
## ``fn`` has to be a resolved symbol of kind ``nnkSym``. This ## `fn` has to be a resolved symbol of kind `nnkSym`. This
## implies that the macro that calls this proc should accept ``typed`` ## implies that the macro that calls this proc should accept `typed`
## arguments and not ``untyped`` arguments. ## arguments and not `untyped` arguments.
expectKind fn, nnkSym expectKind fn, nnkSym
result = getTagsListImpl(fn) result = getTagsListImpl(fn)
proc isGcSafe*(fn: NimNode): bool = proc isGcSafe*(fn: NimNode): bool =
## Return true if the func/proc/etc ``fn`` is `gcsafe`. ## Return true if the func/proc/etc `fn` is `gcsafe`.
## ``fn`` has to be a resolved symbol of kind ``nnkSym``. This ## `fn` has to be a resolved symbol of kind `nnkSym`. This
## implies that the macro that calls this proc should accept ``typed`` ## implies that the macro that calls this proc should accept `typed`
## arguments and not ``untyped`` arguments. ## arguments and not `untyped` arguments.
expectKind fn, nnkSym expectKind fn, nnkSym
result = isGcSafeImpl(fn) result = isGcSafeImpl(fn)
proc hasNoSideEffects*(fn: NimNode): bool = proc hasNoSideEffects*(fn: NimNode): bool =
## Return true if the func/proc/etc ``fn`` has `noSideEffect`. ## Return true if the func/proc/etc `fn` has `noSideEffect`.
## ``fn`` has to be a resolved symbol of kind ``nnkSym``. This ## `fn` has to be a resolved symbol of kind `nnkSym`. This
## implies that the macro that calls this proc should accept ``typed`` ## implies that the macro that calls this proc should accept `typed`
## arguments and not ``untyped`` arguments. ## arguments and not `untyped` arguments.
expectKind fn, nnkSym expectKind fn, nnkSym
result = hasNoSideEffectsImpl(fn) result = hasNoSideEffectsImpl(fn)

View file

@ -1,5 +1,5 @@
## This module provides further logic operators like 'forall' and 'exists' ## This module provides further logic operators like 'forall' and 'exists'
## They are only supported in ``.ensures`` etc pragmas. ## They are only supported in `.ensures` etc pragmas.
proc `->`*(a, b: bool): bool {.magic: "Implies".} proc `->`*(a, b: bool): bool {.magic: "Implies".}
proc `<->`*(a, b: bool): bool {.magic: "Iff".} proc `<->`*(a, b: bool): bool {.magic: "Iff".}

View file

@ -60,7 +60,7 @@ func sumPairwise[T](x: openArray[T], i0, n: int): T =
result = sumPairwise(x, i0, n2) + sumPairwise(x, i0 + n2, n - n2) result = sumPairwise(x, i0, n2) + sumPairwise(x, i0 + n2, n - n2)
func sumPairs*[T](x: openArray[T]): T = func sumPairs*[T](x: openArray[T]): T =
## Pairwise (cascade) summation of ``x[i0:i0+n-1]``, with O(log n) error growth ## Pairwise (cascade) summation of `x[i0:i0+n-1]`, with O(log n) error growth
## (vs O(n) for a simple loop) with negligible performance cost if ## (vs O(n) for a simple loop) with negligible performance cost if
## the base case is large enough. ## the base case is large enough.
## ##

View file

@ -11,7 +11,7 @@ when defined(nimdoc):
type type
Impl = distinct int64 Impl = distinct int64
Time* = Impl ## \ Time* = Impl ## \
## Wrapper for ``time_t``. On posix, this is an alias to ``posix.Time``. ## Wrapper for `time_t`. On posix, this is an alias to `posix.Time`.
elif defined(windows): elif defined(windows):
when defined(i386) and defined(gcc): when defined(i386) and defined(gcc):
type Time* {.importc: "time_t", header: "<time.h>".} = distinct int32 type Time* {.importc: "time_t", header: "<time.h>".} = distinct int32

View file

@ -7,7 +7,7 @@
# distribution, for details about the copyright. # distribution, for details about the copyright.
# #
## This module implements the ``with`` macro for easy ## This module implements the `with` macro for easy
## function chaining. See https://github.com/nim-lang/RFCs/issues/193 ## function chaining. See https://github.com/nim-lang/RFCs/issues/193
## and https://github.com/nim-lang/RFCs/issues/192 for details leading to this ## and https://github.com/nim-lang/RFCs/issues/192 for details leading to this
## particular design. ## particular design.