Skip to content

Commit d6e9bb0

Browse files
committed
Spec: Apply soft-modifiers.
1 parent 482dfeb commit d6e9bb0

File tree

2 files changed

+26
-32
lines changed

2 files changed

+26
-32
lines changed

docs/_spec/01-lexical-syntax.md

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ The principle of optional braces is that any keyword that can be followed by `{`
2727

2828
The lexical analyzer inserts `indent` and `outdent` tokens that represent regions of indented code [at certain points](./other-new-features/indentation.md).
2929

30-
´\color{red}{\text{TODO SCALA3: Port soft-modifier.md and link it here.}}´
31-
3230
In the context-free productions below we use the notation `<<< ts >>>` to indicate a token sequence `ts` that is either enclosed in a pair of braces `{ ts }` or that constitutes an indented region `indent ts outdent`.
3331
Analogously, the notation `:<<< ts >>>` indicates a token sequence `ts` that is either enclosed in a pair of braces `{ ts }` or that constitutes an indented region `indent ts outdent` that follows a `colon` token.
3432

@@ -121,12 +119,35 @@ type val var while with yield
121119

122120
Additionally, the following soft keywords are reserved only in some situations.
123121

124-
´\color{red}{\text{TODO SCALA3: Port soft-modifier.md and link it here.}}´
125-
126122
```
127-
as derives end extension infix inline opaque open transparent using | * + -
123+
as derives end extension infix inline opaque
124+
open transparent using
125+
| * + -
128126
```
129127

128+
A soft modifier is one of the identifiers `infix`, `inline`, `opaque`, `open` and `transparent`.
129+
130+
A soft keyword is a soft modifier, or one of `as`, `derives`, `end`, `extension`, `using`, `|`, `+`, `-`, `*`.
131+
132+
A soft modifier is treated as an actual modifier of a definition if it is followed by a hard modifier or a keyword combination starting a definition (`def`, `val`, `var`, `type`, `given`, `class`, `trait`, `object`, `enum`, `case class`, `case object`).
133+
Between the two words, there may be a sequence of newline tokens and/or other soft modifiers.
134+
135+
Otherwise, soft keywords are treated as actual keywords in the following situations:
136+
137+
- `as`, if it appears in a renaming import clause.
138+
- `derives`, if it appears after an extension clause or after the name and possibly parameters of a class, trait, object, or enum definition.
139+
- `end`, if it appears at the start of a line following a statement (i.e. definition or toplevel expression) and is followed on the same line by a single non-comment token that is:
140+
- one of the keywords `for`, `given`, `if`, `match`, `new`, `this`, `throw`, `try`, `val`, `while`, or
141+
- an identifier.
142+
- `extension`, if it appears at the start of a statement and is followed by `(` or `[`.
143+
- `inline`, if it is followed by any token that can start an expression.
144+
- `using`, if it appears at the start of a parameter or argument list.
145+
- `|`, if it separates two patterns in an alternative.
146+
- `+`, `-`, if they appear in front of a type parameter.
147+
- `*`, if it appears in a wildcard import, or if it follows the type of a parameter, or if it appears in a vararg splice `x*`.
148+
149+
Everywhere else, a soft keyword is treated as a normal identifier.
150+
130151
<!-- -->
131152

132153
> When one needs to access Java identifiers that are reserved words in Scala, use backquote-enclosed strings.

docs/_spec/TODOreference/soft-modifier.md

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)