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

disallow extra lines between a docstring and the documented object, special parsing for @doc #25938

Merged
merged 1 commit into from
Feb 9, 2018

Conversation

JeffBezanson
Copy link
Sponsor Member

I think this rule makes sense; it would be pretty confusing if a string still acted as a doc string despite any number of intervening blank and comment lines.

@Keno @yuyichao In addition to this, I'd consider restricting doc string parsing to basic string literals. For any other kind of string you'd have to use @doc xyz""" """ -> .... That syntax is ugly but the parsing rule is equally simple. Thoughts?

@JeffBezanson JeffBezanson added kind:breaking This change will break code parser Language parsing and surface syntax docsystem The documentation building system labels Feb 7, 2018
@yuyichao
Copy link
Contributor

yuyichao commented Feb 7, 2018

I'd consider restricting doc string parsing to basic string literals. For any other kind of string you'd have to use @doc xyz""" """ -> .... That syntax is ugly but the parsing rule is equally simple. Thoughts?

Isn't that what was there before? IIRC the decision at the time was that we should allow arbitrary string macros for docstring with @doc but should encourage a single default one (markdown) by only supporting that as the one that can be used without @doc. I think this still makes sense though I don't have a preference.

@JeffBezanson
Copy link
Sponsor Member Author

Before there was also a special case allowing doc""" """.

@JeffBezanson JeffBezanson added the status:triage This should be discussed on a triage call label Feb 8, 2018
@JeffBezanson
Copy link
Sponsor Member Author

This is not fully resolved yet, but here are a couple options from triage:

  1. Only doc" " is parsed as a doc string (in addition to normal string literals, as before), but use a suffix to specify the format:
doc"""
    text text text
"""latex
f(x) = x

The doc_str macro would convert its argument to a call to latex_str instead, based on the suffix.

  1. Use a naming convention, e.g. any string macro ending in doc is parsed as a doc string:
latexdoc"""
"""
f(x) = x
  1. Allow all string literals as doc strings, and use _cmd macros for things like Cxx instead (cxx``` ... ``` ).

  2. Have some way to register that a certain string macro is or isn't valid as a doc string, in order to give a clear error message when something unintentionally becomes a doc string.

  3. Only allow normal string literals as doc strings, and use @doc for everything else. The main problem is that the full syntax is pretty ugly:

@doc latex"""
""" ->
f(x) = x

That could potentially be fixed by giving @doc special parsing to at least allow removing the ->. That's not so bad since @doc is built in, unlike doc" ".

@JeffBezanson
Copy link
Sponsor Member Author

I'm kind of leaning towards option 5 --- if we're willing to give doc" " special parsing, we might as well give @doc special parsing instead, since it's more general. You can use @doc <anything> to use any expression as a doc string.

@StefanKarpinski
Copy link
Sponsor Member

I like option 5 as well. What would the parsing rule be? If @doc is called with only a single expression, then consume the following expression in the manner of doc strings as well?

@JeffBezanson
Copy link
Sponsor Member Author

Yes, I think that's it.

- disallow extra lines between a docstring and the documented object
- parse an extra expression after a newline in calls to `@doc`
- deprecate special parsing of `doc" "`
- deprecate `->` for doc strings
@JeffBezanson
Copy link
Sponsor Member Author

OK, implemented! I also deprecated all the things:

  • deprecation warning for multiple lines between docstring and object
  • special parsing of doc" " is deprecated
  • using -> in @doc calls is deprecated

@JeffBezanson JeffBezanson changed the title disallow extra lines between a docstring and the documented object disallow extra lines between a docstring and the documented object, special parsing for @doc Feb 9, 2018
@JeffBezanson JeffBezanson removed the status:triage This should be discussed on a triage call label Feb 9, 2018
@JeffBezanson JeffBezanson merged commit dcc39f4 into master Feb 9, 2018
@JeffBezanson JeffBezanson deleted the jb/docstrlines branch February 9, 2018 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docsystem The documentation building system kind:breaking This change will break code parser Language parsing and surface syntax
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants