-
-
Notifications
You must be signed in to change notification settings - Fork 5.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
Limit doc string to plain string and custom literals that start with doc #11970
Conversation
I don't think it should be doing anything at all with plain strings either, unless they are "void" (not used in any expression). I think this will cause breakage, for example if somebody is returning a string from a method. |
@one-more-minute Thoughts? |
@Keno, what's the idea here? Why limit them like this? The main motivation I can think of is wanting the |
Because otherwise using custom string literals becomes an absolute nightmare for anything other than documentation. There are a number good reasons to use custom string literals that are not for documentation (in particular Cxx.jl, but I'm sure there are others). |
I know this would be hard to implement in the parser (as it is now) but and we evaluate the string macro first and only treat it as doc string if it is of certain types? (and let all doc string types inherit that type) |
IIRC, @one-more-minute was showing using |
There's no problem in adding an |
(though that would still leave the repl pasting issue, which I guess I'm ok with). |
I like this one (if implementing it is not overly complicated). I was just thinking about registering the type of the expension but registering the macro sounds better. |
Why? (If the |
Actually thinking about it more, starting with I would slightly prefer limiting it to |
+1 to registering rather than checking for containing/starting with "doc", Part of the reason was for this to allow the rst macro (or other doc system). Having to write doc_rst or doc_md everywhere seems unnecessarily long-winded (noting the push back on writing doc"..."). An |
+1 for this. How about only having doc"""
...
"""rst
f(x) = x
|
+1 to that, @MichaelHatherly |
Yes, that sounds like a good solution. |
This seems awful to me. Please can we illicit more feedback before rolling with this. |
@hayd, any particular reasons why that would be an awful approach? |
Do we have support for postfix modifiers on custom string literals? How does that work, or does it need to be implemented in the parser first? |
In the same way as macro doc_str(text, format...)
format = isempty(format) ? "md" : format[1]
...
end |
I didn't know that we do until I tried it out either. julia> Meta.show_sexpr(:(a"b"c))
(:macrocall, symbol("@a_str"), "b", "c") I think this is what makes the suffix a great idea. |
With
Is that just an oversight? |
The parsing should be fixed by this. However, the suffix seems to be used for "flavor" in the current diff --git a/src/julia-parser.scm b/src/julia-parser.scm
index d20c92d..12f2ca8 100644
--- a/src/julia-parser.scm
+++ b/src/julia-parser.scm
@@ -2068,7 +2068,8 @@
(define (any-string-literal? e)
(or (simple-string-literal? e)
- (and (length= e 3) (eq? (car e) 'macrocall)
+ (and (or (length= e 3) (length= e 4))
+ (eq? (car e) 'macrocall)
(simple-string-literal? (caddr e))
(let ((mname (string (cadr e))))
(equal? (string.sub mname (string.dec mname (length mname) 4)) julia> Meta.show_sexpr(quote
baremodule A
doc"""
<doc>
"""md
f() = 1
end
end)
(:block,
(:line, 2, :none),
(:module, false, :A, (:block,
:( # line 3:),
(:macrocall, (:., :Base, (:quote, #QuoteNode
symbol("@doc")
)), (:macrocall, symbol("@doc_str"), "<doc>\n", "md"), (:(=), (:call, :f), (:block,
(:line, 6, :none),
1
)))
))
) |
The reason I don't like it, is that it's noisy (and a little because the noise is both at the start and the end, when you expect it at the beginning - if you have a long docstring this'll be especially annoying). This noise was an original concern when writing If you're postfixing, to label the format/flavour, will it work without the doc?
|
No because it won't be parsed as string macro
Maybe a little but shouldn't be too bad. At least this is still standard julia syntax. Also since plain string works as md, I expect most people should just use that and non-md format would only be needed in special cases (very long ones for module maby?) |
It's not necessary if we only ever support markdown. Other than these three ways:
I'm not sure there's any other syntax that could be used to specify the format. |
Just a question, if we're already parsing plain text, how much more work would it be to also parse rst"""
*ReStrucuturedText*
""" and md"""
Markdown
========
""" ? Could these even be changed into |
@kmsquire I don't quite understand your question. We already parse
And similar stuff as doc string. However, this means that string macros that should never be used as doc string ( With my patch above #11970 (comment), we would also parse There's two ways I can think about right now.
|
Got it--thanks for the explanation, @yuyichao! |
I'm definitely sympathetic to Keno's use case here and, since we're pushing for markdown docs anyway, I'm not vehemently opposed to making custom doc strings a little noisier. That said, it's worth considering the other option of making string macro code, as opposed to docs, more explicit. Both of the following should work already: sql"CREATE TABLE foo"; or begin
cxx"""
blah blah blah
"""
end The first one especially doesn't seem so bad, and it might be a good thing that these are very clearly running as code. Going the other way, the other thing we could do is set doc syntax for the current module, e.g. module Foo
@docsyntax rst
"""
foo bar
"""
foo() = ...
end The |
That's a nice approach, +1.
Disallowing that might be a good thing. |
Not sure if I agree with disallowing it but setting module/file level syntax should make most cases less noisy. |
Is another option was to have some |
That's not ideal because then the outcome of parsing depends on hidden state, and you can't fully parse a Julia program without also evaluating it. It's probably not a disaster but keeping the parser simple is really helpful for tooling. c.f. this Perl disaster. |
It's not really necessary to change the result of parsing. I suppose what we can do is
The help system then use these info to call the corresponding conversion function. This way the parsing should not depend on any magical state. On possible concern is that whoever read the code would have to find the place where the global doc format is defined and it would be slightly harder to move doc string arround (still possible by explicitly specify the format as suffix). |
How about instead of parsing everything to |
What about doc string without the |
What I meant was to translate |
I would be ok with only doing the special parsing for plain strings and
|
I have to agree that I don't find supporting multiple documentation markup formats to be very important. In fact, I'd say that it's a positive thing to force people as much as possible to use a common format and make sure that one format is good enough for all realistic use cases. I know some people disagree, but maybe it's my inner dictatorial tendencies showing themselves. Make a good decision and go with it. |
BOFL: Benevolent Oligarchy For Life |
I guess there's a pragmatic argument: people may already have documentation in other formats kicking about... like julia's own documentation (that's in rst). |
@one-more-minute Does that sound ok? |
Absolutely, I'm very much on board with what everyone else has said. |
Ok, since it's such a small change I'll just re-do this. |
Fixes #11968. cc @one-more-minute and @JeffBezanson