summary refs log tree commit diff stats
path: root/lib/packages/docutils/dochelpers.nim
diff options
context:
space:
mode:
authorAndrey Makarov <ph.makarov@gmail.com>2021-11-08 15:10:01 +0300
committerGitHub <noreply@github.com>2021-11-08 13:10:01 +0100
commitb21eb1ed36aa068cc9b0a304742e4c81b5112304 (patch)
tree87893c2032b57e89eaea898617f861d35312de2b /lib/packages/docutils/dochelpers.nim
parentb423ab138f41c24db3b168fd30f1ecce7850a170 (diff)
downloadNim-b21eb1ed36aa068cc9b0a304742e4c81b5112304.tar.gz
change os.nim doc links to new style (#19102)
Diffstat (limited to 'lib/packages/docutils/dochelpers.nim')
-rw-r--r--lib/packages/docutils/dochelpers.nim19
1 files changed, 15 insertions, 4 deletions
diff --git a/lib/packages/docutils/dochelpers.nim b/lib/packages/docutils/dochelpers.nim
index c488c4d99..8f97a7119 100644
--- a/lib/packages/docutils/dochelpers.nim
+++ b/lib/packages/docutils/dochelpers.nim
@@ -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?
@@ -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
@@ -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"
@@ -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:
@@ -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