Skip to content

Commit

Permalink
change os.nim doc links to new style (#19102)
Browse files Browse the repository at this point in the history
  • Loading branch information
a-mr authored Nov 8, 2021
1 parent b423ab1 commit b21eb1e
Show file tree
Hide file tree
Showing 8 changed files with 345 additions and 321 deletions.
7 changes: 7 additions & 0 deletions compiler/docgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,13 @@ proc toLangSymbol(k: TSymKind, n: PNode, baseName: string): LangSymbol =
if kind != tkSpaces:
result.generics.add(literal.nimIdentNormalize)

if k == skType:
case n[2].kind
of nkEnumTy: result.symTypeKind = "enum"
of nkObjectTy: result.symTypeKind = "object"
of nkTupleTy: result.symTypeKind = "tuple"
else: discard

proc genItem(d: PDoc, n, nameNode: PNode, k: TSymKind, docFlags: DocFlags) =
if (docFlags != kForceExport) and not isVisible(d, nameNode): return
let
Expand Down
7 changes: 7 additions & 0 deletions doc/docgen.rst
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,13 @@ recognized fine::
no backticks: `func [][T](x: openArray[T]): T`_
escaped: `func \`[]\`[T](x: openArray[T]): T`_

.. Note:: Types that defined as `enum`, or `object`, or `tuple` can also be
referenced with those names directly (instead of `type`)::

type CopyFlag = enum
...
## Ref. `CopyFlag enum`_

Related Options
===============

Expand Down
19 changes: 15 additions & 4 deletions lib/packages/docutils/dochelpers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import rstast

type
LangSymbol* = object ## symbol signature in Nim
symKind*: string ## "proc", "const", etc
symKind*: string ## "proc", "const", "type", etc
symTypeKind*: string ## ""|enum|object|tuple -
## valid only when `symKind == "type"`
name*: string ## plain symbol name without any parameters
generics*: string ## generic parameters (without brackets)
isGroup*: bool ## is LangSymbol a group with overloads?
Expand Down Expand Up @@ -79,7 +81,14 @@ proc toLangSymbol*(linkText: PRstNode): LangSymbol =
assert linkText.kind in {rnRef, rnInner}

const NimDefs = ["proc", "func", "macro", "method", "iterator",
"template", "converter", "const", "type", "var"]
"template", "converter", "const", "type", "var",
"enum", "object", "tuple"]
template resolveSymKind(x: string) =
if x in ["enum", "object", "tuple"]:
result.symKind = "type"
result.symTypeKind = x
else:
result.symKind = x
type
State = enum
inBeginning
Expand All @@ -97,7 +106,7 @@ proc toLangSymbol*(linkText: PRstNode): LangSymbol =
if curIdent != "":
case state
of inBeginning: doAssert false, "incorrect state inBeginning"
of afterSymKind: result.symKind = curIdent
of afterSymKind: resolveSymKind curIdent
of beforeSymbolName: doAssert false, "incorrect state beforeSymbolName"
of atSymbolName: result.name = curIdent.nimIdentBackticksNormalize
of afterSymbolName: doAssert false, "incorrect state afterSymbolName"
Expand Down Expand Up @@ -195,7 +204,7 @@ proc toLangSymbol*(linkText: PRstNode): LangSymbol =
let isPostfixSymKind = i > 0 and i == L - 1 and
result.symKind == "" and s(i) in NimDefs
if isPostfixSymKind: # for links like `foo proc`_
result.symKind = s(i)
resolveSymKind s(i)
else:
case state
of inBeginning:
Expand Down Expand Up @@ -235,6 +244,8 @@ proc match*(generated: LangSymbol, docLink: LangSymbol): bool =
result = docLink.symKind in ["proc", "func"]
else:
result = generated.symKind == docLink.symKind
if result and docLink.symKind == "type" and docLink.symTypeKind != "":
result = generated.symTypeKind == docLink.symTypeKind
if not result: return
result = generated.name == docLink.name
if not result: return
Expand Down
42 changes: 21 additions & 21 deletions lib/pure/includes/osenv.nim
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ when not defined(nimscript):
##
## If the variable does not exist, `""` is returned. To distinguish
## whether a variable exists or it's value is just `""`, call
## `existsEnv(key) proc <#existsEnv,string>`_.
## `existsEnv(key) proc`_.
##
## See also:
## * `existsEnv proc <#existsEnv,string>`_
## * `putEnv proc <#putEnv,string,string>`_
## * `delEnv proc <#delEnv,string>`_
## * `envPairs iterator <#envPairs.i>`_
## * `existsEnv proc`_
## * `putEnv proc`_
## * `delEnv proc`_
## * `envPairs iterator`_
runnableExamples:
assert getEnv("unknownEnv") == ""
assert getEnv("unknownEnv", "doesn't exist") == "doesn't exist"
Expand All @@ -76,10 +76,10 @@ when not defined(nimscript):
## Returns true if it exists, false otherwise.
##
## See also:
## * `getEnv proc <#getEnv,string,string>`_
## * `putEnv proc <#putEnv,string,string>`_
## * `delEnv proc <#delEnv,string>`_
## * `envPairs iterator <#envPairs.i>`_
## * `getEnv proc`_
## * `putEnv proc`_
## * `delEnv proc`_
## * `envPairs iterator`_
runnableExamples:
assert not existsEnv("unknownEnv")

Expand All @@ -90,10 +90,10 @@ when not defined(nimscript):
## If an error occurs, `OSError` is raised.
##
## See also:
## * `getEnv proc <#getEnv,string,string>`_
## * `existsEnv proc <#existsEnv,string>`_
## * `delEnv proc <#delEnv,string>`_
## * `envPairs iterator <#envPairs.i>`_
## * `getEnv proc`_
## * `existsEnv proc`_
## * `delEnv proc`_
## * `envPairs iterator`_
when defined(windows):
if key.len == 0 or '=' in key:
raise newException(OSError, "invalid key, got: " & $(key, val))
Expand All @@ -108,10 +108,10 @@ when not defined(nimscript):
## If an error occurs, `OSError` is raised.
##
## See also:ven
## * `getEnv proc <#getEnv,string,string>`_
## * `existsEnv proc <#existsEnv,string>`_
## * `putEnv proc <#putEnv,string,string>`_
## * `envPairs iterator <#envPairs.i>`_
## * `getEnv proc`_
## * `existsEnv proc`_
## * `putEnv proc`_
## * `envPairs iterator`_
template bail = raiseOSError(osLastError(), key)
when defined(windows):
#[
Expand Down Expand Up @@ -190,10 +190,10 @@ iterator envPairs*(): tuple[key, value: string] {.tags: [ReadEnvEffect].} =
## in the second its value.
##
## Works in native backends, nodejs and vm, like the following APIs:
## * `getEnv proc <#getEnv,string,string>`_
## * `existsEnv proc <#existsEnv,string>`_
## * `putEnv proc <#putEnv,string,string>`_
## * `delEnv proc <#delEnv,string>`_
## * `getEnv proc`_
## * `existsEnv proc`_
## * `putEnv proc`_
## * `delEnv proc`_
when nimvm:
for ai in envPairsImplSeq(): yield ai
else:
Expand Down
21 changes: 10 additions & 11 deletions lib/pure/includes/oserr.nim
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ proc `$`*(err: OSErrorCode): string {.borrow.}
proc osErrorMsg*(errorCode: OSErrorCode): string =
## Converts an OS error code into a human readable string.
##
## The error code can be retrieved using the `osLastError proc <#osLastError>`_.
## The error code can be retrieved using the `osLastError proc`_.
##
## If conversion fails, or `errorCode` is `0` then `""` will be
## returned.
Expand All @@ -28,8 +28,8 @@ proc osErrorMsg*(errorCode: OSErrorCode): string =
## message.
##
## See also:
## * `raiseOSError proc <#raiseOSError,OSErrorCode,string>`_
## * `osLastError proc <#osLastError>`_
## * `raiseOSError proc`_
## * `osLastError proc`_
runnableExamples:
when defined(linux):
assert osErrorMsg(OSErrorCode(0)) == ""
Expand Down Expand Up @@ -63,18 +63,17 @@ proc newOSError*(
## Creates a new `OSError exception <system.html#OSError>`_.
##
## The `errorCode` will determine the
## message, `osErrorMsg proc <#osErrorMsg,OSErrorCode>`_ will be used
## message, `osErrorMsg proc`_ will be used
## to get this message.
##
## The error code can be retrieved using the `osLastError proc
## <#osLastError>`_.
## The error code can be retrieved using the `osLastError proc`_.
##
## If the error code is `0` or an error message could not be retrieved,
## the message `unknown OS error` will be used.
##
## See also:
## * `osErrorMsg proc <#osErrorMsg,OSErrorCode>`_
## * `osLastError proc <#osLastError>`_
## * `osErrorMsg proc`_
## * `osLastError proc`_
var e: owned(ref OSError); new(e)
e.errorCode = errorCode.int32
e.msg = osErrorMsg(errorCode)
Expand All @@ -90,7 +89,7 @@ proc newOSError*(
proc raiseOSError*(errorCode: OSErrorCode, additionalInfo = "") {.noinline.} =
## Raises an `OSError exception <system.html#OSError>`_.
##
## Read the description of the `newOSError proc <#newOSError,OSErrorCode,string>`_ to learn
## Read the description of the `newOSError proc`_ to learn
## how the exception object is created.
raise newOSError(errorCode, additionalInfo)

Expand All @@ -109,8 +108,8 @@ proc osLastError*(): OSErrorCode {.sideEffect.} =
## immediately after an OS call fails. On POSIX systems this is not a problem.
##
## See also:
## * `osErrorMsg proc <#osErrorMsg,OSErrorCode>`_
## * `raiseOSError proc <#raiseOSError,OSErrorCode,string>`_
## * `osErrorMsg proc`_
## * `raiseOSError proc`_
when defined(nimscript):
discard
elif defined(windows):
Expand Down
6 changes: 3 additions & 3 deletions lib/pure/includes/osseps.nim
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ const
when doslikeFileSystem: '/'
else: DirSep
## An alternative character used by the operating system to separate
## pathname components, or the same as `DirSep <#DirSep>`_ if only one separator
## pathname components, or the same as DirSep_ if only one separator
## character exists. This is set to `'/'` on Windows systems
## where `DirSep <#DirSep>`_ is a backslash (`'\\'`).
## where DirSep_ is a backslash (`'\\'`).

PathSep* =
when defined(macos) or defined(RISCOS): ','
Expand All @@ -55,7 +55,7 @@ const
defined(PalmOS) or defined(MorphOS): false
else: true
## True if the file system is case sensitive, false otherwise. Used by
## `cmpPaths proc <#cmpPaths,string,string>`_ to compare filenames properly.
## `cmpPaths proc`_ to compare filenames properly.

ExeExt* =
when doslikeFileSystem: "exe"
Expand Down
Loading

0 comments on commit b21eb1e

Please sign in to comment.