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

fix #22926, raw string escaping rules that allow writing all strings #24621

Merged
merged 1 commit into from
Nov 16, 2017

Conversation

JeffBezanson
Copy link
Sponsor Member

I implemented @vtjnash 's proposal since that seemed to be the most popular.

@JeffBezanson JeffBezanson added kind:breaking This change will break code parser Language parsing and surface syntax domain:strings "Strings!" labels Nov 15, 2017
NEWS.md Outdated
@@ -130,6 +130,10 @@ Language changes
* Like `_`, variable names consisting only of underscores can be assigned,
but accessing their values is deprecated ([#24221]).

* Raw string literal escaping rules have been changed to make it possible to write all strings.
The rule is that backslashes escape both quotes and other backslashes, but only when appearing
directly before a quote character ([#22926]).
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

"but only when a sequence of backslashes precedes a quote character. Thus, 2n backslashes followed by a quote encodes n backslashes and the end of the literal while 2n+1 backslashes followed by a quote encodes n backslashes followed by a quote character."

The exception is that quotation marks still must be escaped.
The exception is that quotation marks still must be escaped. Backslashes
escape both question marks and other backslashes, but only when immediately
preceding a quote character.
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Ditto.

@vtjnash
Copy link
Sponsor Member

vtjnash commented Nov 15, 2017

Looks like there's a couple other tests to fix though too:

julia/test/syntax.jl

Lines 742 to 745 in 2028ae8

@test :(x"s\"`\x\$\\") == :(@x_str "s\"`\\x\\\$\\\\")
@test :(x`s`) == :(@x_cmd "s")
@test :(x`s`flag) == :(@x_cmd "s" "flag")
@test :(x`s\`"\x\$\\`) == :(@x_cmd "s`\"\\x\\\$\\\\")

@@ -371,15 +371,25 @@ macro b_str(s); :(Vector{UInt8}($(unescape_string(s)))); end
@raw_str -> String

Create a raw string without interpolation and unescaping.
The exception is that quotation marks still must be escaped.
The exception is that quotation marks still must be escaped. Backslashes
escape both question marks and other backslashes, but only when a sequence
Copy link
Contributor

Choose a reason for hiding this comment

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

"question" -> "quotation" ?

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

Good catch.

@JeffBezanson JeffBezanson merged commit 81e245c into master Nov 16, 2017
@JeffBezanson JeffBezanson deleted the jb/rawstrings branch November 16, 2017 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:strings "Strings!" 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.

5 participants