Hi, I commented under the github Issue for this already, but let me post
my proposal to the mailing list as well:
My proposal is a `r""` syntax, with the option to pad the string on both
ends with `#` to allow any string inside:
foo == r"foo"
fo"o == r#"fo"o"#
"## == r###""##"###
As far as I know we don't allow `#` in an expression context, it's only
valid as part of the attribute syntax, so this should work.
Heck, it would even be ok in attributes themselves, I think:
#[foo = r##"test"##];
Alternatively, we could also throw away the `r` token itself and say
that any number of `#` followed by `"` starts an raw string literal:
let regex = #"[\d]+"#;
Or we make both forms valid: `r""` for short raw strings, and `#""#`,
`##""##`, ... as alternative to cover every possible string.
It would be similar to Luas syntax, but in my opinion has more advantages:
- It has the same advantage of being able to delimit any text.
- Only being limited to `#` is not a problem, you can still find a
delimiter sequence for any input, and only need to pad with more `#`s at
all if your string contains `"`, `"#`, `"##`etc.
- The default case `r""` has very low typing overhead, and looks very
similar to a regular string literal, no confusion about meaning, or
annoyance about it not being intuitive.
- Unlike Lua and a few of the other proposals here, r"" doesn't feel out
of place syntax-wise.
If we look at the uses casesAlex Crichton listed under the github issue:
1. Regular expressions:
r"([^:]*):(\d+):(\d+): (\d+):(\d+) (.*)$".match_groups();
2. Windows paths:
r"C:\Program Files\rust\bin\rust.exe".to_path()
3. `format!` strings:
println!(r"\\");
4. Blobs of text:
static MARKDOWN: &'static str = r###"
## Scope
This is an introductory tutorial for the Rust programming language. It
covers the fundamentals of the language, including the syntax, the
type system and memory model, generics, and modules. [Additional
tutorials](#what-next) cover specific language features in greater
depth.
This tutorial assumes that the reader is already familiar with one or
more languages in the C family. Understanding of pointers and general
memory management techniques will help.
"###;
So, what do you think?
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev