You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/_spec/01-lexical-syntax.md
+26-5Lines changed: 26 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -27,8 +27,6 @@ The principle of optional braces is that any keyword that can be followed by `{`
27
27
28
28
The lexical analyzer inserts `indent` and `outdent` tokens that represent regions of indented code [at certain points](./other-new-features/indentation.md).
29
29
30
-
´\color{red}{\text{TODO SCALA3: Port soft-modifier.md and link it here.}}´
31
-
32
30
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`.
33
31
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.
34
32
@@ -121,12 +119,35 @@ type val var while with yield
121
119
122
120
Additionally, the following soft keywords are reserved only in some situations.
123
121
124
-
´\color{red}{\text{TODO SCALA3: Port soft-modifier.md and link it here.}}´
125
-
126
122
```
127
-
as derives end extension infix inline opaque open transparent using | * + -
123
+
as derives end extension infix inline opaque
124
+
open transparent using
125
+
| * + -
128
126
```
129
127
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
+
130
151
<!---->
131
152
132
153
> When one needs to access Java identifiers that are reserved words in Scala, use backquote-enclosed strings.
0 commit comments