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

Add docs for SubstitutionString #27134

Merged
merged 7 commits into from
Jun 18, 2018

Conversation

digital-carver
Copy link
Contributor

Resolves #26497

"""
@s_str -> SubstitutionString

Construct a substitution string, used for regular expression substitutions. Within the
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to escape all the backslashes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've corrected that and fixed some doc reference errors (thanks to help from @fredrikekre), committed that to the PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually you need single backslashes; the examples don't work with double ones. That's because non-standard string literal macros are passed the raw string, and escapes are not interpreted.

Copy link
Sponsor Member

@KristofferC KristofferC May 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example is inside a julia string and escapes are interpreted.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, I chose the wrong thread. My comment applies to uses of s"..." below.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where? Everything here is inside a normal julia string.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Sponsor Member

@KristofferC KristofferC May 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it won't have double slashes in the rendered documentation? Again, because this is inside a normal julia string.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahah, got it, that's tricky. Indeed that's a special string inside a standard (doc)string...

@@ -466,6 +466,9 @@ julia> replace("The quick foxes run quickly.", "quick" => "slow", count=1)

julia> replace("The quick foxes run quickly.", "quick" => "", count=1)
"The foxes run quickly."

julia> replace("The quick foxes run quickly.", r"fox(es)?" => s"bus\1")
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Escape backslash?

base/regex.jl Outdated
SubstitutionString(substr)

Stores the given string `substr` as a SubstitutionString, for use in regular expression
substitutions. Most commonly constructed using the [`@s_str`](@ref) macro.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to show an example of how to use the macro, as the link between @s_str and s"..." isn't completely obvious.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned in the other comment, I'm leaning towards just merging this into the doc for @s_str and removing the doc here. That would also parallel what's done with Regex - @r_str has documentation, the type itself doesn't. The link in replace's doc will then just have to be changed to "r is a SubstitutionString (constructed with @s_str)", which would lead the user more directly to the actual construct they'd need to use in the code. Do you think that make sense?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather keep this docstring, especially since you've written it. ;-) The fact that Regex isn't documented is rather something to fix: all public types and methods should have docstrings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added an example of using the s"..." macro and added SubstitutionString to exports.jl. Does this PR need anything else or is this good to go?

"""
@s_str -> SubstitutionString

Construct a substitution string, used for regular expression substitutions. Within the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually you need single backslashes; the examples don't work with double ones. That's because non-standard string literal macros are passed the raw string, and escapes are not interpreted.

@@ -21,6 +21,8 @@ Base.codeunit
Base.codeunits
Base.ascii
Base.@r_str
Base.SubstitutionString
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK we only list exported objects here, yet SubstitutionString isn't exported. I guess it should be?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seem to be a few exceptions to that (eg. BroadcastStyle in arrays.md, OneTo in math.md). I added SubstitutionString here only because Documenter needed that to be able to generate cross-reference from replace's doc. I'm not sure it makes sense to export SubstitutionString though: it's somewhat cumbersome to use as a constructor (with the longer name than s"" and the need for additional backslashes), and as a type it's useful (afaict) only to the very few people building RegEx libraries. Perhaps I should go with my original idea of only documenting @s_str and linking directly to that from replace's doc - that's probably more useful from a practical point of view too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regex is exported even though the same objections apply, so I don't think that's a problem.

Copy link
Member

@nalimilan nalimilan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good to me. The CI failure seems to be unrelated, though it would be nice to have it fixed elsewhere before merging.

@kshyatt kshyatt added domain:docs This change adds or pertains to documentation domain:strings "Strings!" labels May 27, 2018
@nalimilan nalimilan closed this Jun 16, 2018
@nalimilan nalimilan reopened this Jun 16, 2018
@nalimilan
Copy link
Member

@StefanKarpinski Is it OK to export SubstitutionString? If so, should be OK to merge.

@StefanKarpinski
Copy link
Sponsor Member

Sure, go for it.

@nalimilan nalimilan merged commit 404e0fe into JuliaLang:master Jun 18, 2018
@nalimilan
Copy link
Member

Thanks @digital-carver!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:docs This change adds or pertains to documentation domain:strings "Strings!"
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants