Skip to content

Commit 51bbee0

Browse files
authored
Specification: Various integrations from the reference (#17383)
* Syntax * Type lambdas and `AnyKind` * Auto-application * Union and intersection types
2 parents 1aa3372 + 5dd886c commit 51bbee0

25 files changed

+548
-1347
lines changed

docs/_docs/internals/syntax-3.1.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ hexadecimal code:
1111

1212
```ebnf
1313
UnicodeEscape ::= ‘\’ ‘u’ {‘u’} hexDigit hexDigit hexDigit hexDigit
14-
hexDigit ::= ‘0’ | | ‘9’ | ‘A’ | | ‘F’ | ‘a’ | | ‘f’
14+
hexDigit ::= ‘0’ | ... | ‘9’ | ‘A’ | ... | ‘F’ | ‘a’ | ... | ‘f’
1515
```
1616

1717
Informal descriptions are typeset as `“some comment”`.
@@ -22,15 +22,15 @@ form.
2222

2323
```ebnf
2424
whiteSpace ::= ‘\u0020’ | ‘\u0009’ | ‘\u000D’ | ‘\u000A’
25-
upper ::= ‘A’ | | ‘Z’ | ‘\$’ | ‘_’ “ and Unicode category Lu”
26-
lower ::= ‘a’ | | ‘z’ “ and Unicode category Ll”
27-
letter ::= upper | lower “ and Unicode categories Lo, Lt, Lm, Nl”
28-
digit ::= ‘0’ | | ‘9’
25+
upper ::= ‘A’ | ... | ‘Z’ | ‘\$’ | ‘_’ “... and Unicode category Lu”
26+
lower ::= ‘a’ | ... | ‘z’ “... and Unicode category Ll”
27+
letter ::= upper | lower “... and Unicode categories Lo, Lt, Lm, Nl”
28+
digit ::= ‘0’ | ... | ‘9’
2929
paren ::= ‘(’ | ‘)’ | ‘[’ | ‘]’ | ‘{’ | ‘}’ | ‘'(’ | ‘'[’ | ‘'{’
3030
delim ::= ‘`’ | ‘'’ | ‘"’ | ‘.’ | ‘;’ | ‘,’
3131
opchar ::= ‘!’ | ‘#’ | ‘%’ | ‘&’ | ‘*’ | ‘+’ | ‘-’ | ‘/’ | ‘:’ |
3232
‘<’ | ‘=’ | ‘>’ | ‘?’ | ‘@’ | ‘\’ | ‘^’ | ‘|’ | ‘~’
33-
and Unicode categories Sm, So”
33+
... and Unicode categories Sm, So”
3434
printableChar ::= “all characters in [\u0020, \u007E] inclusive”
3535
charEscapeSeq ::= ‘\’ (‘b’ | ‘t’ | ‘n’ | ‘f’ | ‘r’ | ‘"’ | ‘'’ | ‘\’)
3636
@@ -49,7 +49,7 @@ integerLiteral ::= (decimalNumeral | hexNumeral) [‘L’ | ‘l’]
4949
decimalNumeral ::= ‘0’ | nonZeroDigit {digit}
5050
hexNumeral ::= ‘0’ (‘x’ | ‘X’) hexDigit {hexDigit}
5151
digit ::= ‘0’ | nonZeroDigit
52-
nonZeroDigit ::= ‘1’ | | ‘9’
52+
nonZeroDigit ::= ‘1’ | ... | ‘9’
5353
5454
floatingPointLiteral
5555
::= digit {digit} ‘.’ {digit} [exponentPart] [floatType]

docs/_docs/internals/syntax.md

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,51 +20,46 @@ productions map to AST nodes.
2020
The following description of Scala tokens uses literal characters `‘c’` when
2121
referring to the ASCII fragment `\u0000``\u007F`.
2222

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-
3323
## Lexical Syntax
3424

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:
3726

3827
```ebnf
3928
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’
4437
paren ::= ‘(’ | ‘)’ | ‘[’ | ‘]’ | ‘{’ | ‘}’
4538
delim ::= ‘`’ | ‘'’ | ‘"’ | ‘.’ | ‘;’ | ‘,’
4639
opchar ::= ‘!’ | ‘#’ | ‘%’ | ‘&’ | ‘*’ | ‘+’ | ‘-’ | ‘/’ | ‘:’ |
4740
‘<’ | ‘=’ | ‘>’ | ‘?’ | ‘@’ | ‘\’ | ‘^’ | ‘|’ | ‘~’
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’
5045
charEscapeSeq ::= ‘\’ (‘b’ | ‘t’ | ‘n’ | ‘f’ | ‘r’ | ‘"’ | ‘'’ | ‘\’)
46+
escapeSeq ::= UnicodeEscape | charEscapeSeq
5147
5248
op ::= opchar {opchar}
5349
varid ::= lower idrest
54-
alphaid ::= upper idrest
55-
| varid
50+
boundvarid ::= varid
51+
| ‘`’ varid ‘`’
5652
plainid ::= alphaid
5753
| op
5854
id ::= plainid
59-
| ‘`’ { charNoBackQuoteOrNewline | UnicodeEscape | charEscapeSeq } ‘`’
55+
| ‘`’ { charNoBackQuoteOrNewline | escapeSeq } ‘`’
6056
idrest ::= {letter | digit} [‘_’ op]
6157
quoteId ::= ‘'’ alphaid
6258
spliceId ::= ‘$’ alphaid ;
6359
6460
integerLiteral ::= (decimalNumeral | hexNumeral) [‘L’ | ‘l’]
65-
decimalNumeral ::= ‘0’ | nonZeroDigit [{digit | ‘_’} digit]
61+
decimalNumeral ::= ‘0’ | digit [{digit | ‘_’} digit]
6662
hexNumeral ::= ‘0’ (‘x’ | ‘X’) hexDigit [{hexDigit | ‘_’} hexDigit]
67-
nonZeroDigit ::= ‘1’ | … | ‘9’
6863
6964
floatingPointLiteral
7065
::= [decimalNumeral] ‘.’ digit [{digit | ‘_’} digit] [exponentPart] [floatType]
@@ -75,25 +70,25 @@ floatType ::= ‘F’ | ‘f’ | ‘D’ | ‘d’
7570
7671
booleanLiteral ::= ‘true’ | ‘false’
7772
78-
characterLiteral ::= ‘'’ (printableChar | charEscapeSeq) ‘'’
73+
characterLiteral ::= ‘'’ (charNoQuoteOrNewline | escapeSeq) ‘'’
7974
8075
stringLiteral ::= ‘"’ {stringElement} ‘"’
8176
| ‘"""’ 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
9085
::= 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
9792
9893
comment ::= ‘/*’ “any sequence of characters; nested comments are allowed” ‘*/’
9994
| ‘//’ “any sequence of characters up to end of line”
@@ -159,7 +154,7 @@ SimpleLiteral ::= [‘-’] integerLiteral
159154
| characterLiteral
160155
| stringLiteral
161156
Literal ::= SimpleLiteral
162-
| processedStringLiteral
157+
| interpolatedStringLiteral
163158
| symbolLiteral
164159
| ‘null’
165160

docs/_docs/reference/changed-features/overload-resolution.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ as follows:
6666

6767
Replace the sentence
6868

69-
> Otherwise, let `S1,,Sm` be the vector of types obtained by typing each argument with an undefined expected type.
69+
> Otherwise, let `S1,...,Sm` be the vector of types obtained by typing each argument with an undefined expected type.
7070
7171
with the following paragraph:
7272

73-
> Otherwise, let `S1,,Sm` be the vector of known types of all argument types, where the _known type_ of an argument `E`
73+
> Otherwise, let `S1,...,Sm` be the vector of known types of all argument types, where the _known type_ of an argument `E`
7474
is determined as followed:
7575

7676
- If `E` is a function value `(p_1, ..., p_n) => B` that misses some parameter types, the known type

docs/_docs/reference/syntax.md

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -21,51 +21,48 @@ productions map to AST nodes.
2121
The following description of Scala tokens uses literal characters `‘c’` when
2222
referring to the ASCII fragment `\u0000``\u007F`.
2323

24-
_Unicode escapes_ are used to represent the [Unicode character](https://www.w3.org/International/articles/definitions-characters/) with the given
25-
hexadecimal code:
26-
27-
```
28-
UnicodeEscape ::= ‘\’ ‘u’ {‘u’} hexDigit hexDigit hexDigit hexDigit
29-
hexDigit ::= ‘0’ | … | ‘9’ | ‘A’ | … | ‘F’ | ‘a’ | … | ‘f’
30-
```
31-
3224
Informal descriptions are typeset as `“some comment”`.
3325

3426
## Lexical Syntax
3527

36-
The lexical syntax of Scala is given by the following grammar in EBNF
37-
form.
28+
The lexical syntax of Scala is given by the following grammar in EBNF form:
3829

39-
```
30+
```ebnf
4031
whiteSpace ::= ‘\u0020’ | ‘\u0009’ | ‘\u000D’ | ‘\u000A’
41-
upper ::= ‘A’ | … | ‘Z’ | ‘\$’ | ‘_’ “… and Unicode category Lu”
42-
lower ::= ‘a’ | … | ‘z’ “… and Unicode category Ll”
43-
letter ::= upper | lower “… and Unicode categories Lo, Lt, Nl”
44-
digit ::= ‘0’ | … | ‘9’
32+
upper ::= ‘A’ | ... | ‘Z’ | ‘$’ and any character in Unicode categories Lu, Lt or Nl,
33+
and any character in Unicode categories Lo and Lm that doesn't have
34+
contributory property Other_Lowercase
35+
lower ::= ‘a’ | ... | ‘z’ | ‘_’ and any character in Unicode category Ll,
36+
and any character in Unicode categories Lo or Lm that has contributory
37+
property Other_Lowercase
38+
letter ::= upper | lower
39+
digit ::= ‘0’ | ... | ‘9’
4540
paren ::= ‘(’ | ‘)’ | ‘[’ | ‘]’ | ‘{’ | ‘}’
4641
delim ::= ‘`’ | ‘'’ | ‘"’ | ‘.’ | ‘;’ | ‘,’
4742
opchar ::= ‘!’ | ‘#’ | ‘%’ | ‘&’ | ‘*’ | ‘+’ | ‘-’ | ‘/’ | ‘:’ |
4843
‘<’ | ‘=’ | ‘>’ | ‘?’ | ‘@’ | ‘\’ | ‘^’ | ‘|’ | ‘~’
49-
“… and Unicode categories Sm, So”
50-
printableChar ::= “all characters in [\u0020, \u007E] inclusive”
44+
and any character in Unicode categories Sm or So
45+
printableChar ::= all characters in [\u0020, \u007E] inclusive
46+
UnicodeEscape ::= ‘\’ ‘u’ {‘u’} hexDigit hexDigit hexDigit hexDigit
47+
hexDigit ::= ‘0’ | ... | ‘9’ | ‘A’ | ... | ‘F’ | ‘a’ | ... | ‘f’
5148
charEscapeSeq ::= ‘\’ (‘b’ | ‘t’ | ‘n’ | ‘f’ | ‘r’ | ‘"’ | ‘'’ | ‘\’)
49+
escapeSeq ::= UnicodeEscape | charEscapeSeq
5250
5351
op ::= opchar {opchar}
5452
varid ::= lower idrest
55-
alphaid ::= upper idrest
56-
| varid
53+
boundvarid ::= varid
54+
| ‘`’ varid ‘`’
5755
plainid ::= alphaid
5856
| op
5957
id ::= plainid
60-
| ‘`’ { charNoBackQuoteOrNewline | UnicodeEscape | charEscapeSeq } ‘`’
58+
| ‘`’ { charNoBackQuoteOrNewline | escapeSeq } ‘`’
6159
idrest ::= {letter | digit} [‘_’ op]
6260
quoteId ::= ‘'’ alphaid
6361
spliceId ::= ‘$’ alphaid ;
6462
6563
integerLiteral ::= (decimalNumeral | hexNumeral) [‘L’ | ‘l’]
66-
decimalNumeral ::= ‘0’ | nonZeroDigit [{digit | ‘_’} digit]
64+
decimalNumeral ::= ‘0’ | digit [{digit | ‘_’} digit]
6765
hexNumeral ::= ‘0’ (‘x’ | ‘X’) hexDigit [{hexDigit | ‘_’} hexDigit]
68-
nonZeroDigit ::= ‘1’ | … | ‘9’
6966
7067
floatingPointLiteral
7168
::= [decimalNumeral] ‘.’ digit [{digit | ‘_’} digit] [exponentPart] [floatType]
@@ -76,25 +73,25 @@ floatType ::= ‘F’ | ‘f’ | ‘D’ | ‘d’
7673
7774
booleanLiteral ::= ‘true’ | ‘false’
7875
79-
characterLiteral ::= ‘'’ (printableChar | charEscapeSeq) ‘'’
76+
characterLiteral ::= ‘'’ (charNoQuoteOrNewline | escapeSeq) ‘'’
8077
8178
stringLiteral ::= ‘"’ {stringElement} ‘"’
8279
| ‘"""’ multiLineChars ‘"""’
83-
stringElement ::= printableChar \ (‘"’ | ‘\’)
84-
| UnicodeEscape
85-
| charEscapeSeq
86-
multiLineChars ::= {[‘"’] [‘"’] char \ ‘"’} {‘"’}
87-
processedStringLiteral
88-
::= alphaid ‘"’ {[‘\’] processedStringPart | ‘\\’ | ‘\"’} ‘"’
89-
| alphaid ‘"""’ {[‘"’] [‘"’] char \ (‘"’ | ‘$’) | escape} {‘"’} ‘"""’
90-
processedStringPart
80+
stringElement ::= charNoDoubleQuoteOrNewline
81+
| escapeSeq
82+
multiLineChars ::= {[‘"’] [‘"’] charNoDoubleQuote} {‘"’}
83+
84+
interpolatedString
85+
::= alphaid ‘"’ {[‘\’] interpolatedStringPart | ‘\\’ | ‘\"’} ‘"’
86+
| alphaid ‘"""’ {[‘"’] [‘"’] char \ (‘"’ | ‘\$’) | escape} {‘"’} ‘"""’
87+
interpolatedStringPart
9188
::= printableChar \ (‘"’ | ‘$’ | ‘\’) | escape
92-
escape ::= ‘$$’
93-
| ‘$’ letter { letter | digit }
94-
| ‘{’ Block [‘;’ whiteSpace stringFormat whiteSpace] ‘}’
95-
stringFormat ::= {printableChar \ (‘"’ | ‘}’ | ‘ ’ | ‘\t’ | ‘\n’)}
96-
97-
symbolLiteral ::= ‘'’ plainid // until 2.13
89+
escape ::= ‘\$\$’
90+
| ‘\$"’
91+
| ‘\$’ alphaid
92+
| ‘\$’ BlockExpr
93+
alphaid ::= upper idrest
94+
| varid
9895
9996
comment ::= ‘/*’ “any sequence of characters; nested comments are allowed” ‘*/’
10097
| ‘//’ “any sequence of characters up to end of line”
@@ -163,7 +160,7 @@ SimpleLiteral ::= [‘-’] integerLiteral
163160
| characterLiteral
164161
| stringLiteral
165162
Literal ::= SimpleLiteral
166-
| processedStringLiteral
163+
| interpolatedStringLiteral
167164
| symbolLiteral
168165
| ‘null’
169166

0 commit comments

Comments
 (0)