I'm a fan of always having the r prefix. Its more consistent and it leaves #foo available for another language feature if required. Otherwise I like it.
I've tweaked the regex I posted slightly to ensure that the # tokens are well balanced. See it on regexpal [1]. [rR](#*)([^#"]*|#)\1"(.*?)"\1\2\1 The following match: r"raw text" r#"raw text"# r##"raw text"## r###"raw text"### r#eos#"raw text"#eos# r##eos##"raw text"##eos## r###eos###"raw text"###eos### The following don't match: r# eos #"raw text"# eos # -- unbalanced spaces r#eos"raw text"#eos -- unbalanced # around eos r#e#os#"raw text"#e#os# -- eos contains # I have mixed feeling regarding the inclusion of spaces in/around the eos string. [1] http://regexpal.com/?flags=gs®ex=%5BrR%5D(%23*)(%5B%5E%23%22%5D*%7C%23)%5C1%22(.*%3F)%22%5C1%5C2%5C1&input=The%20following%20match%3A%0A%0Ar%22raw%20text%22%0Ar%23%22raw%20text%22%23%0Ar%23%23%22raw%20text%22%23%23%0Ar%23%23%23%22raw%20text%22%23%23%23%0Ar%23eos%23%22raw%20text%22%23eos%23%0Ar%23%23eos%23%23%22raw%20text%22%23%23eos%23%23%0Ar%23%23%23eos%23%23%23%22raw%20text%22%23%23%23eos%23%23%23%0A%0AThe%20following%20don't%20match%3A%0A%0Ar%23%20eos%20%23%22raw%20text%22%23%20eos%20%20%23%20%20--%20unbalanced%20spaces%0Ar%23eos%22raw%20text%22%23eos%20%20%20%20%20%20%20%20%20--%20unbalanced%20%23%20around%20eos%0Ar%23e%23os%23%22raw%20text%22%23e%23os%23%20%20%20%20%20--%20eos%20contains%20%23 On Mon, Sep 23, 2013 at 7:58 PM, Marvin Löbel <loebel.mar...@gmail.com>wrote: > 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<https://mail.mozilla.org/listinfo/rust-dev> >
_______________________________________________ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev