change os.nim doc links to new style (#19102)
This commit is contained in:
parent
b423ab138f
commit
b21eb1ed36
8 changed files with 345 additions and 321 deletions
|
|
@ -954,6 +954,13 @@ proc toLangSymbol(k: TSymKind, n: PNode, baseName: string): LangSymbol =
|
||||||
if kind != tkSpaces:
|
if kind != tkSpaces:
|
||||||
result.generics.add(literal.nimIdentNormalize)
|
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) =
|
proc genItem(d: PDoc, n, nameNode: PNode, k: TSymKind, docFlags: DocFlags) =
|
||||||
if (docFlags != kForceExport) and not isVisible(d, nameNode): return
|
if (docFlags != kForceExport) and not isVisible(d, nameNode): return
|
||||||
let
|
let
|
||||||
|
|
|
||||||
|
|
@ -399,6 +399,13 @@ recognized fine::
|
||||||
no backticks: `func [][T](x: openArray[T]): T`_
|
no backticks: `func [][T](x: openArray[T]): T`_
|
||||||
escaped: `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
|
Related Options
|
||||||
===============
|
===============
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,9 @@ import rstast
|
||||||
|
|
||||||
type
|
type
|
||||||
LangSymbol* = object ## symbol signature in Nim
|
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
|
name*: string ## plain symbol name without any parameters
|
||||||
generics*: string ## generic parameters (without brackets)
|
generics*: string ## generic parameters (without brackets)
|
||||||
isGroup*: bool ## is LangSymbol a group with overloads?
|
isGroup*: bool ## is LangSymbol a group with overloads?
|
||||||
|
|
@ -79,7 +81,14 @@ proc toLangSymbol*(linkText: PRstNode): LangSymbol =
|
||||||
assert linkText.kind in {rnRef, rnInner}
|
assert linkText.kind in {rnRef, rnInner}
|
||||||
|
|
||||||
const NimDefs = ["proc", "func", "macro", "method", "iterator",
|
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
|
type
|
||||||
State = enum
|
State = enum
|
||||||
inBeginning
|
inBeginning
|
||||||
|
|
@ -97,7 +106,7 @@ proc toLangSymbol*(linkText: PRstNode): LangSymbol =
|
||||||
if curIdent != "":
|
if curIdent != "":
|
||||||
case state
|
case state
|
||||||
of inBeginning: doAssert false, "incorrect state inBeginning"
|
of inBeginning: doAssert false, "incorrect state inBeginning"
|
||||||
of afterSymKind: result.symKind = curIdent
|
of afterSymKind: resolveSymKind curIdent
|
||||||
of beforeSymbolName: doAssert false, "incorrect state beforeSymbolName"
|
of beforeSymbolName: doAssert false, "incorrect state beforeSymbolName"
|
||||||
of atSymbolName: result.name = curIdent.nimIdentBackticksNormalize
|
of atSymbolName: result.name = curIdent.nimIdentBackticksNormalize
|
||||||
of afterSymbolName: doAssert false, "incorrect state afterSymbolName"
|
of afterSymbolName: doAssert false, "incorrect state afterSymbolName"
|
||||||
|
|
@ -195,7 +204,7 @@ proc toLangSymbol*(linkText: PRstNode): LangSymbol =
|
||||||
let isPostfixSymKind = i > 0 and i == L - 1 and
|
let isPostfixSymKind = i > 0 and i == L - 1 and
|
||||||
result.symKind == "" and s(i) in NimDefs
|
result.symKind == "" and s(i) in NimDefs
|
||||||
if isPostfixSymKind: # for links like `foo proc`_
|
if isPostfixSymKind: # for links like `foo proc`_
|
||||||
result.symKind = s(i)
|
resolveSymKind s(i)
|
||||||
else:
|
else:
|
||||||
case state
|
case state
|
||||||
of inBeginning:
|
of inBeginning:
|
||||||
|
|
@ -235,6 +244,8 @@ proc match*(generated: LangSymbol, docLink: LangSymbol): bool =
|
||||||
result = docLink.symKind in ["proc", "func"]
|
result = docLink.symKind in ["proc", "func"]
|
||||||
else:
|
else:
|
||||||
result = generated.symKind == docLink.symKind
|
result = generated.symKind == docLink.symKind
|
||||||
|
if result and docLink.symKind == "type" and docLink.symTypeKind != "":
|
||||||
|
result = generated.symTypeKind == docLink.symTypeKind
|
||||||
if not result: return
|
if not result: return
|
||||||
result = generated.name == docLink.name
|
result = generated.name == docLink.name
|
||||||
if not result: return
|
if not result: return
|
||||||
|
|
|
||||||
|
|
@ -56,13 +56,13 @@ when not defined(nimscript):
|
||||||
##
|
##
|
||||||
## If the variable does not exist, `""` is returned. To distinguish
|
## If the variable does not exist, `""` is returned. To distinguish
|
||||||
## whether a variable exists or it's value is just `""`, call
|
## whether a variable exists or it's value is just `""`, call
|
||||||
## `existsEnv(key) proc <#existsEnv,string>`_.
|
## `existsEnv(key) proc`_.
|
||||||
##
|
##
|
||||||
## See also:
|
## See also:
|
||||||
## * `existsEnv proc <#existsEnv,string>`_
|
## * `existsEnv proc`_
|
||||||
## * `putEnv proc <#putEnv,string,string>`_
|
## * `putEnv proc`_
|
||||||
## * `delEnv proc <#delEnv,string>`_
|
## * `delEnv proc`_
|
||||||
## * `envPairs iterator <#envPairs.i>`_
|
## * `envPairs iterator`_
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
assert getEnv("unknownEnv") == ""
|
assert getEnv("unknownEnv") == ""
|
||||||
assert getEnv("unknownEnv", "doesn't exist") == "doesn't exist"
|
assert getEnv("unknownEnv", "doesn't exist") == "doesn't exist"
|
||||||
|
|
@ -76,10 +76,10 @@ when not defined(nimscript):
|
||||||
## Returns true if it exists, false otherwise.
|
## Returns true if it exists, false otherwise.
|
||||||
##
|
##
|
||||||
## See also:
|
## See also:
|
||||||
## * `getEnv proc <#getEnv,string,string>`_
|
## * `getEnv proc`_
|
||||||
## * `putEnv proc <#putEnv,string,string>`_
|
## * `putEnv proc`_
|
||||||
## * `delEnv proc <#delEnv,string>`_
|
## * `delEnv proc`_
|
||||||
## * `envPairs iterator <#envPairs.i>`_
|
## * `envPairs iterator`_
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
assert not existsEnv("unknownEnv")
|
assert not existsEnv("unknownEnv")
|
||||||
|
|
||||||
|
|
@ -90,10 +90,10 @@ when not defined(nimscript):
|
||||||
## If an error occurs, `OSError` is raised.
|
## If an error occurs, `OSError` is raised.
|
||||||
##
|
##
|
||||||
## See also:
|
## See also:
|
||||||
## * `getEnv proc <#getEnv,string,string>`_
|
## * `getEnv proc`_
|
||||||
## * `existsEnv proc <#existsEnv,string>`_
|
## * `existsEnv proc`_
|
||||||
## * `delEnv proc <#delEnv,string>`_
|
## * `delEnv proc`_
|
||||||
## * `envPairs iterator <#envPairs.i>`_
|
## * `envPairs iterator`_
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
if key.len == 0 or '=' in key:
|
if key.len == 0 or '=' in key:
|
||||||
raise newException(OSError, "invalid key, got: " & $(key, val))
|
raise newException(OSError, "invalid key, got: " & $(key, val))
|
||||||
|
|
@ -108,10 +108,10 @@ when not defined(nimscript):
|
||||||
## If an error occurs, `OSError` is raised.
|
## If an error occurs, `OSError` is raised.
|
||||||
##
|
##
|
||||||
## See also:ven
|
## See also:ven
|
||||||
## * `getEnv proc <#getEnv,string,string>`_
|
## * `getEnv proc`_
|
||||||
## * `existsEnv proc <#existsEnv,string>`_
|
## * `existsEnv proc`_
|
||||||
## * `putEnv proc <#putEnv,string,string>`_
|
## * `putEnv proc`_
|
||||||
## * `envPairs iterator <#envPairs.i>`_
|
## * `envPairs iterator`_
|
||||||
template bail = raiseOSError(osLastError(), key)
|
template bail = raiseOSError(osLastError(), key)
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
#[
|
#[
|
||||||
|
|
@ -190,10 +190,10 @@ iterator envPairs*(): tuple[key, value: string] {.tags: [ReadEnvEffect].} =
|
||||||
## in the second its value.
|
## in the second its value.
|
||||||
##
|
##
|
||||||
## Works in native backends, nodejs and vm, like the following APIs:
|
## Works in native backends, nodejs and vm, like the following APIs:
|
||||||
## * `getEnv proc <#getEnv,string,string>`_
|
## * `getEnv proc`_
|
||||||
## * `existsEnv proc <#existsEnv,string>`_
|
## * `existsEnv proc`_
|
||||||
## * `putEnv proc <#putEnv,string,string>`_
|
## * `putEnv proc`_
|
||||||
## * `delEnv proc <#delEnv,string>`_
|
## * `delEnv proc`_
|
||||||
when nimvm:
|
when nimvm:
|
||||||
for ai in envPairsImplSeq(): yield ai
|
for ai in envPairsImplSeq(): yield ai
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ proc `$`*(err: OSErrorCode): string {.borrow.}
|
||||||
proc osErrorMsg*(errorCode: OSErrorCode): string =
|
proc osErrorMsg*(errorCode: OSErrorCode): string =
|
||||||
## Converts an OS error code into a human readable 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
|
## If conversion fails, or `errorCode` is `0` then `""` will be
|
||||||
## returned.
|
## returned.
|
||||||
|
|
@ -28,8 +28,8 @@ proc osErrorMsg*(errorCode: OSErrorCode): string =
|
||||||
## message.
|
## message.
|
||||||
##
|
##
|
||||||
## See also:
|
## See also:
|
||||||
## * `raiseOSError proc <#raiseOSError,OSErrorCode,string>`_
|
## * `raiseOSError proc`_
|
||||||
## * `osLastError proc <#osLastError>`_
|
## * `osLastError proc`_
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
when defined(linux):
|
when defined(linux):
|
||||||
assert osErrorMsg(OSErrorCode(0)) == ""
|
assert osErrorMsg(OSErrorCode(0)) == ""
|
||||||
|
|
@ -63,18 +63,17 @@ proc newOSError*(
|
||||||
## 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`_ 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>`_.
|
|
||||||
##
|
##
|
||||||
## 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`_
|
||||||
## * `osLastError proc <#osLastError>`_
|
## * `osLastError proc`_
|
||||||
var e: owned(ref OSError); new(e)
|
var e: owned(ref OSError); new(e)
|
||||||
e.errorCode = errorCode.int32
|
e.errorCode = errorCode.int32
|
||||||
e.msg = osErrorMsg(errorCode)
|
e.msg = osErrorMsg(errorCode)
|
||||||
|
|
@ -90,7 +89,7 @@ proc newOSError*(
|
||||||
proc raiseOSError*(errorCode: OSErrorCode, additionalInfo = "") {.noinline.} =
|
proc raiseOSError*(errorCode: OSErrorCode, additionalInfo = "") {.noinline.} =
|
||||||
## Raises an `OSError exception <system.html#OSError>`_.
|
## 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.
|
## how the exception object is created.
|
||||||
raise newOSError(errorCode, additionalInfo)
|
raise newOSError(errorCode, additionalInfo)
|
||||||
|
|
||||||
|
|
@ -109,8 +108,8 @@ proc osLastError*(): OSErrorCode {.sideEffect.} =
|
||||||
## 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:
|
||||||
## * `osErrorMsg proc <#osErrorMsg,OSErrorCode>`_
|
## * `osErrorMsg proc`_
|
||||||
## * `raiseOSError proc <#raiseOSError,OSErrorCode,string>`_
|
## * `raiseOSError proc`_
|
||||||
when defined(nimscript):
|
when defined(nimscript):
|
||||||
discard
|
discard
|
||||||
elif defined(windows):
|
elif defined(windows):
|
||||||
|
|
|
||||||
|
|
@ -37,9 +37,9 @@ const
|
||||||
when doslikeFileSystem: '/'
|
when doslikeFileSystem: '/'
|
||||||
else: DirSep
|
else: DirSep
|
||||||
## An alternative character used by the operating system to separate
|
## 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
|
## character exists. This is set to `'/'` on Windows systems
|
||||||
## where `DirSep <#DirSep>`_ is a backslash (`'\\'`).
|
## where DirSep_ is a backslash (`'\\'`).
|
||||||
|
|
||||||
PathSep* =
|
PathSep* =
|
||||||
when defined(macos) or defined(RISCOS): ','
|
when defined(macos) or defined(RISCOS): ','
|
||||||
|
|
@ -55,7 +55,7 @@ const
|
||||||
defined(PalmOS) or defined(MorphOS): false
|
defined(PalmOS) or defined(MorphOS): false
|
||||||
else: true
|
else: true
|
||||||
## True if the file system is case sensitive, false otherwise. Used by
|
## 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* =
|
ExeExt* =
|
||||||
when doslikeFileSystem: "exe"
|
when doslikeFileSystem: "exe"
|
||||||
|
|
|
||||||
558
lib/pure/os.nim
558
lib/pure/os.nim
File diff suppressed because it is too large
Load diff
|
|
@ -153,3 +153,9 @@ suite "Integration with Nim":
|
||||||
outType: "T")
|
outType: "T")
|
||||||
check(input1.toLangSymbol == expected)
|
check(input1.toLangSymbol == expected)
|
||||||
check(input2.toLangSymbol == expected)
|
check(input2.toLangSymbol == expected)
|
||||||
|
|
||||||
|
test "type of type":
|
||||||
|
check ("`CopyFlag enum`_".rstParseTest.toLangSymbol ==
|
||||||
|
LangSymbol(symKind: "type",
|
||||||
|
symTypeKind: "enum",
|
||||||
|
name: "Copyflag"))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue