From 8f8f715f76d9fd342cc1c68697f426cf31d02ea3 Mon Sep 17 00:00:00 2001 From: jangko Date: Sat, 16 Apr 2022 18:26:33 +0700 Subject: [PATCH] fix nnkAccQuoted entry processing in config-file fixes #47 --- confutils/config_file.nim | 20 +++++++++++++++++--- tests/test_config_file.nim | 19 +++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/confutils/config_file.nim b/confutils/config_file.nim index 1c6aec5..84f28fa 100644 --- a/confutils/config_file.nim +++ b/confutils/config_file.nim @@ -66,8 +66,16 @@ proc traversePostfix(postfix: NimNode, typ: NimNode, isDiscriminator: bool, isCommandOrArgument = false, defaultValue = "", namePragma = ""): ConfFileSection = postfix.expectKind nnkPostfix - traverseIdent(postfix[1], typ, isDiscriminator, isCommandOrArgument, - defaultValue, namePragma) + + case postfix[1].kind + of nnkIdent: + traverseIdent(postfix[1], typ, isDiscriminator, isCommandOrArgument, + defaultValue, namePragma) + of nnkAccQuoted: + traverseIdent(postfix[1][0], typ, isDiscriminator, isCommandOrArgument, + defaultValue, namePragma) + else: + raiseAssert "[Postfix] Unsupported child node:\n" & postfix[1].treeRepr proc shortEnumName(n: NimNode): NimNode = if n.kind == nnkDotExpr: @@ -111,10 +119,14 @@ proc traversePragmaExpr(pragmaExpr: NimNode, typ: NimNode, pragmaExpr.expectKind nnkPragmaExpr let (isCommandOrArgument, defaultValue, namePragma) = traversePragma(pragmaExpr[1]) + case pragmaExpr[0].kind of nnkIdent: traverseIdent(pragmaExpr[0], typ, isDiscriminator, isCommandOrArgument, defaultValue, namePragma) + of nnkAccQuoted: + traverseIdent(pragmaExpr[0][0], typ, isDiscriminator, isCommandOrArgument, + defaultValue, namePragma) of nnkPostfix: traversePostfix(pragmaExpr[0], typ, isDiscriminator, isCommandOrArgument, defaultValue, namePragma) @@ -130,6 +142,8 @@ proc traverseIdentDefs(identDefs: NimNode, parent: ConfFileSection, case child.kind of nnkIdent: result.add traverseIdent(child, typ, isDiscriminator) + of nnkAccQuoted: + result.add traverseIdent(child[0], typ, isDiscriminator) of nnkPostfix: result.add traversePostfix(child, typ, isDiscriminator) of nnkPragmaExpr: @@ -146,7 +160,7 @@ proc traverseOfBranch(ofBranch: NimNode, parent: ConfFileSection): ConfFileSecti result = ConfFileSection(fieldName: repr(shortEnumName(ofBranch[0])), isCaseBranch: true) for child in ofBranch: case child.kind: - of nnkIdent, nnkDotExpr: + of nnkIdent, nnkDotExpr, nnkAccQuoted: discard of nnkRecList: result.children.add traverseRecList(child, result) diff --git a/tests/test_config_file.nim b/tests/test_config_file.nim index 40cc0d7..66961ce 100644 --- a/tests/test_config_file.nim +++ b/tests/test_config_file.nim @@ -27,6 +27,7 @@ type VCStartUpCmd = enum VCNoCommand + `import` ValidatorKeyPath = TypedInputFile[ValidatorPrivKey, Txt, "privkey"] @@ -98,6 +99,24 @@ type desc: "Delay in seconds between retries after unsuccessful attempts to connect to a beacon node" name: "retry-delay" }: int + of `import`: + + blocksFile* {. + argument + desc: "Import RLP encoded block(s) from a file, validate, write to database and quit" + defaultValue: "" + name: "blocks-file" }: InputFile + + `type`* {. + desc: "Test nnkAccQuoted of public sub command entry" + defaultValue: "" + name: "import-type" }: string + + `seq` {. + desc: "Test nnkAccQuoted of private sub command entry" + defaultValue: "" + name: "import-seq" }: string + func defaultDataDir(conf: TestConf): string = discard