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?
This commit is contained in:
Vindaar
2021-07-29 07:47:34 +02:00
committed by GitHub
parent e616675c41
commit 7d3c3e00ef

View File

@@ -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)