With respect to non-semantic whitespace, the literal proposal presents these 3 cases:
// 1
/whitespace is significant/
// 2
#/whitespace is significant/#
// 3
#/
whitespace is **not** significant # nor are comments
#/
Getting behavior such as in #3 is highly desirable, via some delimiter-enabled way. We couldn't find a better one than #/
followed by a newline. The alternative #///
's has some issues with comments, and ///
isn't workable AFAICT, but @hamishknight can you comment further?
An argument could be made that #2 should be non-semantic as well, as "extended delimiter" could mean "extended syntax" (and we'd likely error out on a line-ending comment). The downside is that changing a /hello world/
to a #/hello world/#
would change meaning of whitespace and that would be weird (as you point out). I'd (weakly) recommend against this direction.
An argument could also be made that all regex literals, including #1, has non-semantic whitespace. That does get weird with the no-leading-space lexing rule (which IIUC we could restrict to start-of-line if we needed to). It's also surprising that /hello world/
doesn't match "hello world"
, without the newline that #3 has.
edit: to clarify, the below are all compilation errors. The multi-line story only happens if the #/
is immediately followed by a newline:
// Error
/
abcd
/
// Error
/ ab
cd
/
// Error
#/ ab
cd
/#
// Ok
#/
ab
cd
/#