Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nim doc .. fails when runnableExamples uses $ [devel] [regression] #14485

Closed
kaushalmodi opened this issue May 28, 2020 · 0 comments · Fixed by #14487
Closed

nim doc .. fails when runnableExamples uses $ [devel] [regression] #14485

kaushalmodi opened this issue May 28, 2020 · 0 comments · Fixed by #14487

Comments

@kaushalmodi
Copy link
Contributor

kaushalmodi commented May 28, 2020

While the recently merged PR #14439 fixed a lot of nim doc issues in my real world project, it has introduced a regression on devel where nim doc fails if a runnableExamples block has $ somewhere, like in the below example.

Example

# t.nim
proc foo*(): int =
  ## Some proc
  runnableExamples:
    echo "foo() = ", $foo()
  return

Run nim doc t.nim.

Current Output

strutils.nim(2693)       invalidFormatString
Error: unhandled exception: invalid format string [ValueError]

Expected Output

No error

Additional Information

By adding some debug info to the invalidFormatString (#14486) and the first % proc in strutils.nim like below:

proc `%` *(formatstr: string, a: openArray[string]): string {.noSideEffect,
  rtl, extern: "nsuFormatOpenArray".} =
  # ..
  ## * `strformat module<strformat.html>`_ for string interpolation and formatting
  debugEcho "formatstr = ", formatstr, ", a = ", a
  result = newStringOfCap(formatstr.len + a.len shl 4)
  addf(result, formatstr, a)

, on rebuilding nim and running nim doc t.nim (t.nim is the above minimal example), I get this debug info:

...
formatstr = $1, a = ["t"]
formatstr = autogenerated by docgen
loc: $1
rdoccmd: $2, a = ["/home/kmodi/sandbox/nim/bug_reports/t14485/t.nim(3, 3)", ""]
formatstr = <pre class="listing">, a = ["1", "langNim"]
formatstr = <span class="$1">$2</span>, a = ["Identifier", "echo"]
formatstr = <span class="$1">$2</span>, a = ["Whitespace", " "]
formatstr = <span class="$1">$2</span>, a = ["StringLit", "&quot;foo() = &quot;"]
formatstr = <span class="$1">$2</span>, a = ["Punctuation", ","]
formatstr = <span class="$1">$2</span>, a = ["Whitespace", " "]
formatstr = <span class="$1">$2</span>, a = ["Operator", "$"]
strutils.nim(2693)       invalidFormatString
Error: unhandled exception: invalid format string: <span class="Operator">$</span> [ValueError]

Error: unhandled exception: invalid format string: <span class="Operator">$</span> [ValueError]

$ nim -v
Nim Compiler Version 1.3.5 [Linux: amd64]
Compiled at 2020-05-28
Copyright (c) 2006-2020 by Andreas Rumpf

git hash: e013ebc91a22eeccc9546498994b0c561e438599
active boot switches: -d:release

/cc @timotheecour

@kaushalmodi kaushalmodi changed the title koch docs (nim doc lib/pure/strutils.nim) fails [devel] [regression] nim doc .. fails when runnableExamples uses $ [devel] [regression] May 28, 2020
timotheecour added a commit to timotheecour/Nim that referenced this issue May 28, 2020
timotheecour added a commit to timotheecour/Nim that referenced this issue May 28, 2020
timotheecour added a commit to timotheecour/Nim that referenced this issue May 28, 2020
timotheecour added a commit that referenced this issue May 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant