summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorVindaar <basti90@gmail.com>2021-07-29 07:47:34 +0200
committerGitHub <noreply@github.com>2021-07-29 07:47:34 +0200
commit7d3c3e00efe777dcbda15f2125fa77aa7d17cad4 (patch)
tree0cc13b7695fa311abad988b201803ce0c989e996
parente616675c419552a85bdf0b47f47586852be8b5be (diff)
downloadNim-7d3c3e00efe777dcbda15f2125fa77aa7d17cad4.tar.gz
Allow `nnkAccQuoted` in `genEnumCaseStmt` (#18606)
* [enumutils] provide node kind for `Invalid node type` error

* [enumutils] add support for nnkAccQuoted in `genEnumCaseStmt`

For reasons unknown to me, when running `nim doc` on a file that uses
`parseEnum` with an enum that contains accented quotes errors at CT
with the `Invalid node for type` error. Further errors are raised,
probably because the enum parsing fails?
-rw-r--r--lib/std/enumutils.nim6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/std/enumutils.nim b/lib/std/enumutils.nim
index 6269950c7..81e602ad5 100644
--- a/lib/std/enumutils.nim
+++ b/lib/std/enumutils.nim
@@ -36,6 +36,10 @@ macro genEnumCaseStmt*(typ: typedesc, argSym: typed, default: typed,
     case f.kind
     of nnkEmpty: continue # skip first node of `enumTy`
     of nnkSym, nnkIdent: fStr = f.strVal
+    of nnkAccQuoted:
+      fStr = ""
+      for ch in f:
+        fStr.add ch.strVal
     of nnkEnumFieldDef:
       case f[1].kind
       of nnkStrLit: fStr = f[1].strVal
@@ -46,7 +50,7 @@ macro genEnumCaseStmt*(typ: typedesc, argSym: typed, default: typed,
         fStr = f[0].strVal
         fNum = f[1].intVal
       else: error("Invalid tuple syntax!", f[1])
-    else: error("Invalid node for enum type!", f)
+    else: error("Invalid node for enum type `" & $f.kind & "`!", f)
     # add field if string not already added
     if fNum >= userMin and fNum <= userMax:
       fStr = normalizer(fStr)