@@ -20,51 +20,46 @@ productions map to AST nodes.
20
20
The following description of Scala tokens uses literal characters ` ‘c’ ` when
21
21
referring to the ASCII fragment ` \u0000 ` – ` \u007F ` .
22
22
23
- _ Unicode escapes_ are used to represent the [ Unicode character] ( https://www.w3.org/International/articles/definitions-characters/ ) with the given
24
- hexadecimal code:
25
-
26
- ``` ebnf
27
- UnicodeEscape ::= ‘\’ ‘u’ {‘u’} hexDigit hexDigit hexDigit hexDigit
28
- hexDigit ::= ‘0’ | … | ‘9’ | ‘A’ | … | ‘F’ | ‘a’ | … | ‘f’
29
- ```
30
-
31
- Informal descriptions are typeset as ` “some comment” ` .
32
-
33
23
## Lexical Syntax
34
24
35
- The lexical syntax of Scala is given by the following grammar in EBNF
36
- form.
25
+ The lexical syntax of Scala is given by the following grammar in EBNF form:
37
26
38
27
``` ebnf
39
28
whiteSpace ::= ‘\u0020’ | ‘\u0009’ | ‘\u000D’ | ‘\u000A’
40
- upper ::= ‘A’ | … | ‘Z’ | ‘\$’ | ‘_’ “… and Unicode category Lu”
41
- lower ::= ‘a’ | … | ‘z’ “… and Unicode category Ll”
42
- letter ::= upper | lower “… and Unicode categories Lo, Lt, Lm, Nl”
43
- digit ::= ‘0’ | … | ‘9’
29
+ upper ::= ‘A’ | ... | ‘Z’ | ‘$’ and any character in Unicode categories Lu, Lt or Nl,
30
+ and any character in Unicode categories Lo and Lm that doesn't have
31
+ contributory property Other_Lowercase
32
+ lower ::= ‘a’ | ... | ‘z’ | ‘_’ and any character in Unicode category Ll,
33
+ and any character in Unicode categories Lo or Lm that has contributory
34
+ property Other_Lowercase
35
+ letter ::= upper | lower
36
+ digit ::= ‘0’ | ... | ‘9’
44
37
paren ::= ‘(’ | ‘)’ | ‘[’ | ‘]’ | ‘{’ | ‘}’
45
38
delim ::= ‘`’ | ‘'’ | ‘"’ | ‘.’ | ‘;’ | ‘,’
46
39
opchar ::= ‘!’ | ‘#’ | ‘%’ | ‘&’ | ‘*’ | ‘+’ | ‘-’ | ‘/’ | ‘:’ |
47
40
‘<’ | ‘=’ | ‘>’ | ‘?’ | ‘@’ | ‘\’ | ‘^’ | ‘|’ | ‘~’
48
- “… and Unicode categories Sm, So”
49
- printableChar ::= “all characters in [\u0020, \u007E] inclusive”
41
+ and any character in Unicode categories Sm or So
42
+ printableChar ::= all characters in [\u0020, \u007E] inclusive
43
+ UnicodeEscape ::= ‘\’ ‘u’ {‘u’} hexDigit hexDigit hexDigit hexDigit
44
+ hexDigit ::= ‘0’ | ... | ‘9’ | ‘A’ | ... | ‘F’ | ‘a’ | ... | ‘f’
50
45
charEscapeSeq ::= ‘\’ (‘b’ | ‘t’ | ‘n’ | ‘f’ | ‘r’ | ‘"’ | ‘'’ | ‘\’)
46
+ escapeSeq ::= UnicodeEscape | charEscapeSeq
51
47
52
48
op ::= opchar {opchar}
53
49
varid ::= lower idrest
54
- alphaid ::= upper idrest
55
- | varid
50
+ boundvarid ::= varid
51
+ | ‘`’ varid ‘`’
56
52
plainid ::= alphaid
57
53
| op
58
54
id ::= plainid
59
- | ‘`’ { charNoBackQuoteOrNewline | UnicodeEscape | charEscapeSeq } ‘`’
55
+ | ‘`’ { charNoBackQuoteOrNewline | escapeSeq } ‘`’
60
56
idrest ::= {letter | digit} [‘_’ op]
61
57
quoteId ::= ‘'’ alphaid
62
58
spliceId ::= ‘$’ alphaid ;
63
59
64
60
integerLiteral ::= (decimalNumeral | hexNumeral) [‘L’ | ‘l’]
65
- decimalNumeral ::= ‘0’ | nonZeroDigit [{digit | ‘_’} digit]
61
+ decimalNumeral ::= ‘0’ | digit [{digit | ‘_’} digit]
66
62
hexNumeral ::= ‘0’ (‘x’ | ‘X’) hexDigit [{hexDigit | ‘_’} hexDigit]
67
- nonZeroDigit ::= ‘1’ | … | ‘9’
68
63
69
64
floatingPointLiteral
70
65
::= [decimalNumeral] ‘.’ digit [{digit | ‘_’} digit] [exponentPart] [floatType]
@@ -75,25 +70,25 @@ floatType ::= ‘F’ | ‘f’ | ‘D’ | ‘d’
75
70
76
71
booleanLiteral ::= ‘true’ | ‘false’
77
72
78
- characterLiteral ::= ‘'’ (printableChar | charEscapeSeq ) ‘'’
73
+ characterLiteral ::= ‘'’ (charNoQuoteOrNewline | escapeSeq ) ‘'’
79
74
80
75
stringLiteral ::= ‘"’ {stringElement} ‘"’
81
76
| ‘"""’ multiLineChars ‘"""’
82
- stringElement ::= printableChar \ (‘"’ | ‘\’)
83
- | UnicodeEscape
84
- | charEscapeSeq
85
- multiLineChars ::= {[‘"’] [‘"’] char \ ‘"’} {‘"’}
86
- processedStringLiteral
87
- ::= alphaid ‘"’ {[‘\’] processedStringPart | ‘\\’ | ‘\"’} ‘"’
88
- | alphaid ‘"""’ {[‘"’] [‘"’] char \ (‘"’ | ‘$’) | escape} {‘"’} ‘"""’
89
- processedStringPart
77
+ stringElement ::= charNoDoubleQuoteOrNewline
78
+ | escapeSeq
79
+ multiLineChars ::= {[‘"’] [‘"’] charNoDoubleQuote} {‘"’}
80
+
81
+ interpolatedString
82
+ ::= alphaid ‘"’ {[‘\’] interpolatedStringPart | ‘\\’ | ‘\"’} ‘"’
83
+ | alphaid ‘"""’ {[‘"’] [‘"’] char \ (‘"’ | ‘\ $’) | escape} {‘"’} ‘"""’
84
+ interpolatedStringPart
90
85
::= printableChar \ (‘"’ | ‘$’ | ‘\’) | escape
91
- escape ::= ‘$ $’
92
- | ‘$’ letter { letter | digit }
93
- | ‘{’ Block [‘;’ whiteSpace stringFormat whiteSpace] ‘}’
94
- stringFormat ::= {printableChar \ (‘"’ | ‘}’ | ‘ ’ | ‘\t’ | ‘\n’)}
95
-
96
- symbolLiteral ::= ‘'’ plainid // until 2.13
86
+ escape ::= ‘\$\ $’
87
+ | ‘\$"’
88
+ | ‘\$’ alphaid
89
+ | ‘\$’ BlockExpr
90
+ alphaid ::= upper idrest
91
+ | varid
97
92
98
93
comment ::= ‘/*’ “any sequence of characters; nested comments are allowed” ‘*/’
99
94
| ‘//’ “any sequence of characters up to end of line”
@@ -159,7 +154,7 @@ SimpleLiteral ::= [‘-’] integerLiteral
159
154
| characterLiteral
160
155
| stringLiteral
161
156
Literal ::= SimpleLiteral
162
- | processedStringLiteral
157
+ | interpolatedStringLiteral
163
158
| symbolLiteral
164
159
| ‘null’
165
160
0 commit comments