Add parseEnum support for triple quoted string and raw string enum values (#25401)

(cherry picked from commit ae8a1739f8)
This commit is contained in:
Esteban C Borsani
2025-12-31 21:31:33 -03:00
committed by narimiran
parent fda7c2e5bb
commit 0ae9f5e4df
2 changed files with 26 additions and 2 deletions

View File

@@ -47,7 +47,7 @@ macro genEnumCaseStmt*(typ: typedesc, argSym: typed, default: typed,
of nnkEnumFieldDef:
fVal = f[0].strVal
case f[1].kind
of nnkStrLit:
of nnkStrLit .. nnkTripleStrLit:
fStr = f[1].strVal
of nnkTupleConstr:
fStr = f[1][1].strVal
@@ -57,7 +57,7 @@ macro genEnumCaseStmt*(typ: typedesc, argSym: typed, default: typed,
fNum = f[1].intVal
else:
let fAst = f[0].getImpl
if fAst.kind == nnkStrLit:
if fAst.kind in {nnkStrLit .. nnkTripleStrLit}:
fStr = fAst.strVal
else:
error("Invalid tuple syntax!", f[1])

View File

@@ -642,6 +642,30 @@ template main() =
let myA = CAMPAIGN_TABLE
doAssert $parseEnum[Tables](myA) == "wikientries_campaign"
block:
const tripleQuotedStr = """foobar"""
type MyEnum = enum
a = tripleQuotedStr
b = """bazquz"""
let myA = tripleQuotedStr
doAssert $parseEnum[MyEnum](myA) == myA
let myB = "bazquz"
doAssert $parseEnum[MyEnum](myB) == myB
block:
const rawStr = r"foobar"
type MyEnum = enum
a = rawStr
b = r"bazquz"
let myA = rawStr
doAssert $parseEnum[MyEnum](myA) == myA
let myB = r"bazquz"
doAssert $parseEnum[MyEnum](myB) == myB
block: # check enum defined in block
type
Bar = enum