-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
runnableExamples can now be used for var|let|const|type|fwd routines (all declarations now work); fix #18305 RFCs/309 #18604
Conversation
else: discard | ||
elif isRunnableExamplesRoot(n): | ||
if state in {rsStart, rsComment, rsRunnable}: | ||
let (rdoccmd, code) = prepareExample(d, n, topLevel) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this block is just re-indented
@@ -614,6 614,25 @@ type RunnableState = enum | |||
rsRunnable | |||
rsDone | |||
|
|||
when false: | |||
proc toStr(a: ItemFragment): string = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useful for debugging; I've used this in a few PR's; i can remove or move to another PR if needed
d116d55
to
747ef22
Compare
67f2d77
to
0f0b389
Compare
ping @Araq before this bitrots |
compiler/ast.nim
Outdated
@@ -863,6 863,7 @@ type | |||
bitsize*: int | |||
alignment*: int # for alignment | |||
else: nil | |||
examplesAttached*: seq[PNode] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Store it in a side-channel instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
This reverts commit be6d231.
0f0b389
to
9072bd1
Compare
PTAL |
ping @Araq |
ping @Araq, refs nim-lang/website#301 (comment); your only comment from #18604 (comment) was addressed a while ago |
if not d.examplesAttached.hasKey(d.lastSym.id): d.examplesAttached[d.lastSym.id] = @[] | ||
d.examplesAttached[d.lastSym.id].add n |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use mputOrGet
?
This pull request has been automatically marked as stale because it has not had recent activity. If you think it is still a valid PR, please rebase it on the latest devel; otherwise it will be closed. Thank you for your contributions. |
Ping @a-mr please take a look. |
ok @Araq , but i'm looking into Nim external "smart links" in my free time right now, i hope this PR is not too urgent, i'll try to check it a few days later. Offhand this needs at least 1) rebasing 2) test examples needs to be checked if they are not conflated too much. |
Take all the time you need. Thank you! |
I rebased the branch locally, but I have doubts about the proposed syntax itself... IMHO it would be more uniformly if it looked like: const Digits* =
## Docs
runnableExamples:
assert '0' in Digits
{'0'..'9'}
#instead of the proposed:
# const Digits* = {'0'..'9'} ## Docs
# runnableExamples: assert Digits.len == 10 # shows below docs for Digits
type Foo* =
runnableExamples:
discard
object
...
#instead of:
# type Foo* = object
# runnableExamples: discard It would be more logical if it was called |
This pull request is stale because it has been open for 1 year with no activity. Contribute more commits on the pull request and rebase it on the latest devel, or it will be closed in 30 days. Thank you for your contributions. |
This pull request has been marked as stale and closed due to inactivity after 395 days. |
runnableExamples
doesn't work for type|const|let|var #18305 (andrunnableExamples
should be attacheable for any declaration (egconst
) timotheecour/Nim#716)before PR
impossible to attach a runnableExamples to a var|let|const|type|fwd routine
after PR
we can attach a runnableExamples to a var|let|const|type|fwd routine, so that any declaration can have an attached runnableExamples that will appear next to it in docs
examples
here's a simple one:
it also works for fwd declarations, even if the implementation is in another include file:
compatibility note
a key aspect of this PR is that it won't break any compiler code or user macros, since the AST is not modified (instead, all that changes is how docgen interprets how runnableExamples are attached).
new warning:
warnInvalidDocSection
it currently triggers for https://nim-lang.github.io/Nim/switch_memory.html#memalign,csize,csize which was indeed incorrect (the comments are lumped on top but should be attached to APIs instead)
alternative considered and rejected
TLDR: it would break user defined macros.
attaching an extra PNode to declarations (eg const) as follows:
This would not work well, because it would break both compiler code (fixable, but tricky) and user defined macros (more problematic since we have no control);
indeed the following:
would become:
and this would break user defined macros for example code using
n[^2]
to access the type (inconst foo: int = 1
) would now point to the wrong node; note thatn[^2]
is indeed so far the correct thing to use instead ofn[1]
so that it works withconst foo1, foo2: int = 1
etc; ditto withn[^1]
to access the RHS.links