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
Unicode literal syntax thwarts common use cases for triple-quotes #4706
Comments
Imported From: https://issues.scala-lang.org/browse/SI-4706?orig=1 |
Jonathan Clark (jhclark) said: |
@Ichoran said (edited on Jun 17, 2011 3:48:57 PM UTC): Since Java has no string literals, there are no Java expectations to meet in this regard. There could be a compile-time flag to turn on unicode escapes even in string literals if you really want it. Otherwise, this is a gotcha waiting to happen for Windows users. |
@LilyLambda said (edited on Jun 20, 2011 12:16:35 AM UTC): |
@dcsobral said: |
Jonathan Clark (jhclark) said: "That" isn't really true. That == Yuvi's comment regarding the lexer's myopia? It might be that such context-dependent escapes (such as \n) are performed at a later parsing stage rather than at the lexing stage like the unicode escapes. However, this also answer's Yuvi's question as to how these can be implemented: When unicode escapes are disabled except within certain contexts, this translation can simply be moved to a stage at which the needed context is known. |
@adriaanm said: |
@VladUreche said: |
PROBLEM: The conversion of unicode literals causes triple-quotes and comments to behave unexpectedly in common use cases:
Generating LaTeX (compile error)
println("""\usepackage{geometry}""") // error: error in unicode escape
Windows paths (compile error)
println("""c:\users""") // error: error in unicode escape
Windows paths ("fails" silently)
val f = """C:\test\uuuFeedUs""" // f is not what the user expects
Escape codes in comments (cryptic compile error)
val x = 1 // using \u000a gives error: value inside is not a member of Int
The following is (unintuitive, undesirable?) valid scala code
val x: String = \u0022A string.\u0022
PROPOSED SOLUTION:
3 backwards-compatible compile flags similar to -Xno-uescape. This will allow source-compatibility since they are optional.
-Xuescape-squotes-only that restricts these unicode escape codes to single-quoted strings only. This gets rid of these above 5 undesired outcomes. However, it may interfere with certain libraries that rely on unicode escaping (e.g. scalaz)
-X-no-uescape-tquotes that doesn't perform unicode unescaping in triple-quoted strings. This gets rid of the first 3 undesired outcomes.
-X-no-uescape-comments that doesn't perform unicode unescaping in comments. This gets rid of the 4th undesired outcome.
Note: I would be happy to implement this solution, provided the change will be accepted into the compiler.
CURRENT WORKAROUNDS:
println("""""" + """usepackage{geometry}""")
(This issue is a summary of the discussion from the scala-user topic: https://groups.google.com/d/topic/scala-user/UoJ0sUn3yFU/discussion)
The text was updated successfully, but these errors were encountered: