-
Notifications
You must be signed in to change notification settings - Fork 16
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
How to represent Declarator Docs in plain RakuDoc #439
Comments
Just to get the discussion started, here is the first thing I was able to come up with.
The output in a file
Immediate questions:
@finanalyst I believe you currently have the deepest insight into implementing renderers. Thus the ping. |
I forgot but just found that back in 2020 we did get the ability to keep the leading declarator block in its original form with use of an environment variable RAKUDO_POD_DECL_BLOCK_USER_FORMAT. That implementation was the quickest and easiest way to affect Raku parsing. When that is true, and you run 'raku --doc ...', you will get text from the leading declarator blocks as input by the author of the code. I used that for documenting my code. I hope that is retained and improved for RakuAST. The test for it is in roast file 'S26-documentation/block-leading-user-format.t'. I |
It is retained if you use |
What I implemented for #| before subset
subset Positive of Int where * > 0; #= after subset
#| before enum
enum Frobnicate <Yes No>; #= after enum
#| before regex
my regex zippo { z } #= after regex
#| before block
{ … } #= after block
#| before pointy block
{ … } #= after pointy block
#| the main class
class A { #= that we have
#| a method before
multi method a( #= method after
#| parameter before
Int:D $foo #= parameter after
) {
#| a variable
my $a = 42; #= with the answer
}
} produces:
|
Note that this was just a first attempt and no way intended to be cast in stone... Very much open to improvements :-) |
@lizmat It's a nice surprise you actually started working on it already. I did not see that coming. You've implemented support for quite a list already. Nice! The first elements that come to mind I still miss are: doc-sub, doc-constant, doc-has, doc-token, doc-rule, doc-grammar Questions:
|
Hmmm looks like decks on constants are currently broken. Re: #| before sub
sub foo() { #= after sub
} produces: =begin doc-sub :name<foo>
=leading before sub
=trailing after sub
=end doc-sub But it looks like Looks like "doc-token" and "doc-rule" are already being rendered correctly, as they are a special case of "doc-regex". "doc-grammar" and all other package types, are already being rendered. |
There are spectests for it. |
And there the line between internal and external documentation blurs. So are decks for external or internal documentation? |
All RakuDoc is based on a RakuAST tree. However you build such a tree, is open to debate. I guess one could join multiple ASTs from different files into a single AST. Then it all depends on the scoping of such a merge. |
Yes, you could. But this could become quite a lot. And wasn't it the point to not have any code in safe RakuDoc? |
Sure, we could do that. |
rakudo/rakudo@27565cc1f7 now renders attributes as |
rakudo/rakudo@8162f3eb3b now renders |
The point is to not have any Raku code that needs to be parsed. But a string containing some Raku code (i.e. no different from a =code block in RakuDoc) is not a problem.
My feeling is, that the code (especially for routines - the declarator) carries a lot of meaning in itself and would help a lot to have it available in the docs. For each Signature parameter, the ':' tells if it's a named arg, the '!' tells, if it's mandatory, the order of positional args is clear, the types tell what you're meant to pass in, ...
I think that's the reason why [in many places](https://docs.raku.org/type/Proc/Async) in the official Raku docs the routine declarators are shown.
Alternatively we could expose all the different bits of information separately. In the case of Signature parameters that might look like:
=begin doc-parameter :name<foo>
= :mandatory
= :type<Int:D>
= :container<Scalar>
= :kind<Positional>
= :position(0)
= :where(...)
= :aliases(...)
= :default(...)
parameter before
parameter after
=end doc-parameter
It's definitely more work to provide the information separately instead of just giving
`:code<Int:D $foo>`, but could possibly simplify the job of the consumers of this data. In the end most renderers will want to display something like `Int:D $foo` to the user.
In my ideal world I'd love to have a cleaned up version of the code where comments are removed, whitespace is normalized and stuff like `name($!bind-var)` is cleaned up (i.e. that `!` should be removed).
…On September 22, 2024 1:01:39 PM GMT+02:00, Elizabeth Mattijsen ***@***.***> wrote:
> Can we have the literal code of the respective element in there? (What I put in :code() in my attempt.)
Yes, you could. But this could become quite a lot. And wasn't it the point to **not** have any code in safe RakuDoc?
--
Reply to this email directly or view it on GitHub:
#439 (comment)
You are receiving this because you authored the thread.
Message ID: ***@***.***>
|
That's a question that is difficult to answer. There is clearly a use case for both. Question is, which of the use cases do we want to support? My feeling is that explicitly excluding one of the two use cases diminishes the usability.
I would say, let's just leave it unspecified for now, provide a generic tool and see how it's used and what works and what doesn't.
If we find, that there is a need to separate the two uses more strongly, we can adjust later on.
…On September 22, 2024 12:58:38 PM GMT+02:00, Elizabeth Mattijsen ***@***.***> wrote:
> ~~Same can be asked for my variables.~~ No, it makes perfect sense - e.g. for IDE support for maintainers.
And there the line between internal and external documentation blurs. So are decks for external or internal documentation?
--
Reply to this email directly or view it on GitHub:
#439 (comment)
You are receiving this because you authored the thread.
Message ID: ***@***.***>
|
I've just realized, that we'll probably not only want to generate content for the elements that have a deck attached, but for all elements that are part of a files public API.
We should also generate entries for |
That could only work if the class specification itself has a deck. Otherwise it'd be hard to go back through the attribute to the class and get the sequence in the doc correct. |
Could we do it differently and extract all the wanted elements (packages, classes, methods, ...) directly instead of going backwards from the decks? Going via the decks has the additional disadvantage, that only elements that have some deck attached somewhere in their hierarchy are exported. Deckless elements would be ignored. |
At the moment, it would be useful for me at least, if we could focus on how to manage the AST that is now being generated.
Running on a CLI, we have
If we filter out just the RakuDoc (the .rakudoc method on an AST), which is what a renderer will do, we get:
I don't have much idea about how this might look. Suppose that all declarations are gathered together into a Table, perhaps called DECTABLE, is treated as an implicitly hidden semantic block. Then any where inside a Rakudoc source we could have
As for security, here is a speculation: |
We are dealing with two separate sets of documentation that follow a different structure.
I think we should not try to bend decks (2.) to fit into the RakuDoc documentation (1.) structure. I think it's not possible to do this cleanly as we are working against the preexisting structure. My current best idea is to keep the two structures separate. So when processing the documentation we'll produce two separate sets of documentation each following their own structure.
That should be cleanly possible. Building on that we can allow linking to and embedding parts of 2. in 1. (Linking might also make sense in reverse, embedding not so much.) Module authors should be able to disable generating the API docs if they want to provide 1. only (still being able to embed parts of 2.).
I believe this will work and is a quick solution freeing us of the need to define syntax for RakuDoc representations of Raku code. I still see value in having such a representation, as the intermediate format is then plain RakuDoc. This incentivizes creating tools that process RakuDoc exclusively. Also the intermediate format is then human readable and writable. |
This does not seem to be a good description. All sources (by which I mean the files with .rakumod or .rakudoc extensions) are parsed into ASTs. The AST describes the structure. Sources are themselves gathered into directories. Hence the name 'Collection' for how to process them all. The RakuDoc specification makes no mention of the directories, and the Raku documentation suite is not a flat list of filenames. The sum of all decks is a structure, which we can create as we run through the AST, gathering decks from branches. The same is true of the ToC, Footnotes, Semantic, and Index structures, where information is gathered from How these data are then rendered is quite arbitrary. What I suggested above would be easily added to the existing rakuast-rakudoc-render by adding a handler for Declarator blocks, and a template for rendering them. |
Prelude:
Toolchain wise we've long had the issue that tools to display documentation (GitHub, GitLab, raku.land, ...) have an issue with running the Rakudo parser on source code to reach for the embedded docs as that code can contain BEGIN blocks, which is a big safety concern.
A possible way forward is to split the task of rendering RakuDoc (and Declarator Docs in particular) into two phases:
Extractor
extracts and converts all docs in a Raku source file and outputs a pure .rakudoc file. This is an unsafe procedure.RakuDoc parser
, then parses that pure.rakudoc
file. It barfs on anything that is not plain RakuDoc. This is a safe process.Platforms that wish to render RakuDoc (e.g. GitHub) can safely use the
RakuDoc
parser. Platforms that want to render the full documentation (e.g. raku.land) can run theExtractor
in a sandbox.All of the above is not part of the issue this ticket wants to address.
The question I want to discuss is: What should the output of the above mentioned
Extractor
that can convert a.rakumod
file into a.rakudoc
file look like?The issue is mostly orthogonal to #438 in that it is not concerned with how Declarator Docs should look in code, but how they should be represented in RakuDoc.
The text was updated successfully, but these errors were encountered: