@@ -398,40 +398,46 @@ members of type `Boolean`.
398
398
### Character Literals
399
399
400
400
``` ebnf
401
- characterLiteral ::= ‘'’ (printableChar | charEscapeSeq) ‘'’
401
+ characterLiteral ::= ‘'’ (charNoQuoteOrNewline | UnicodeEscape | charEscapeSeq) ‘'’
402
402
```
403
403
404
404
A character literal is a single character enclosed in quotes.
405
- The character is either a printable unicode character or is described
406
- by an [ escape sequence] ( #escape-sequences ) .
405
+ The character can be any Unicode character except the single quote
406
+ delimiter or ` \u000A ` (LF) or ` \u000D ` (CR);
407
+ or any Unicode character represented by either a
408
+ [ Unicode escape] ( 01-lexical-syntax.html ) or by an [ escape sequence] ( #escape-sequences ) .
407
409
408
410
> ``` scala
409
411
> 'a' '\u0041 ' '\n ' '\t '
410
412
> ```
411
413
412
- Note that `'\u000A'` is _not_ a valid character literal because
413
- Unicode conversion is done before literal parsing and the Unicode
414
- character `\u000A` (line feed) is not a printable
415
- character. One can use instead the escape sequence `'\n'` or
416
- the octal escape `'\12'` ([see here]( # escape - sequences)) .
414
+ Note that although Unicode conversion is done early during parsing,
415
+ so that Unicode characters are generally equivalent to their escaped
416
+ expansion in the source text, literal parsing accepts arbitrary
417
+ Unicode escapes, including the character literal `'\u000A'`,
418
+ which can also be written using the escape sequence `'\n'` .
417
419
418
420
### String Literals
419
421
420
422
```ebnf
421
423
stringLiteral ::= ‘" ’ {stringElement} ‘" ’
422
- stringElement ::= printableCharNoDoubleQuote | charEscapeSeq
424
+ stringElement ::= charNoDoubleQuoteOrNewline | UnicodeEscape | charEscapeSeq
423
425
```
424
426
425
- A string literal is a sequence of characters in double quotes. The
426
- characters are either printable unicode character or are described by
427
- [ escape sequences] ( #escape-sequences ) . If the string literal
428
- contains a double quote character, it must be escaped,
429
- i.e. ` "\"" ` . The value of a string literal is an instance of
430
- class ` String ` .
427
+ A string literal is a sequence of characters in double quotes.
428
+ The characters can be any Unicode character except the double quote
429
+ delimiter or ` \u000A ` (LF) or ` \u000D ` (CR);
430
+ or any Unicode character represented by either a
431
+ [ Unicode escape] ( 01-lexical-syntax.html ) or by an [ escape sequence] ( #escape-sequences ) .
432
+
433
+ If the string literal contains a double quote character, it must be escaped using
434
+ ` "\"" ` .
435
+
436
+ The value of a string literal is an instance of class ` String ` .
431
437
432
438
> ``` scala
433
- > " Hello,\n World! "
434
- > " This string contains a \" character ."
439
+ > " Hello, world! \n "
440
+ > " \" Hello, \" replied the world ."
435
441
> ```
436
442
437
443
#### Multi - Line String Literals
@@ -443,11 +449,10 @@ multiLineChars ::= {[‘"’] [‘"’] charNoDoubleQuote} {‘"’}
443
449
444
450
A multi-line string literal is a sequence of characters enclosed in
445
451
triple quotes `" " " ... """ `. The sequence of characters is
446
- arbitrary, except that it may contain three or more consuctive quote characters
447
- only at the very end. Characters
448
- must not necessarily be printable; newlines or other
449
- control characters are also permitted. Unicode escapes work as everywhere else, but none
450
- of the escape sequences [here](#escape-sequences) are interpreted.
452
+ arbitrary, except that it may contain three or more consecutive quote characters
453
+ only at the very end. In particular, embedded newlines
454
+ are permitted. Unicode escapes work as everywhere else, but none
455
+ of the [escape sequences](#escape-sequences) are interpreted.
451
456
452
457
> ```scala
453
458
> """ the present string
0 commit comments