Skip to content

Commit 45900c4

Browse files
smartersjrd
authored andcommitted
Port most of syntax.md except context-free syntax section.
1 parent 692b2b3 commit 45900c4

File tree

2 files changed

+43
-18
lines changed

2 files changed

+43
-18
lines changed

docs/_spec/01-lexical-syntax.md

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,28 @@ To construct tokens, characters are distinguished according to the following cla
2020
1. Delimiter characters ``‘`’ | ‘'’ | ‘"’ | ‘.’ | ‘;’ | ‘,’ ``.
2121
1. Operator characters. These consist of all printable ASCII characters (`\u0020` - `\u007E`) that are in none of the sets above, mathematical symbols (`Sm`) and other symbols (`So`).
2222

23+
## Optional Braces
24+
25+
The principle of optional braces is that any keyword that can be followed by `{` can also be followed by an indented block, without needing an intervening `:`.
26+
(Allowing an optional `:` would be counterproductive since it would introduce several ways to do the same thing.)
27+
28+
The lexical analyzer inserts `indent` and `outdent` tokens that represent regions of indented code [at certain points](./other-new-features/indentation.md).
29+
30+
´\color{red}{\text{TODO SCALA3: Port soft-modifier.md and link it here.}}´
31+
32+
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+
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+
35+
A `colon` token reads as the standard colon "`:`" but is generated instead of it where `colon` is legal according to the context free syntax, but only if the previous token is an alphanumeric identifier, a backticked identifier, or one of the tokens `this`, `super`, `new`, "`)`", and "`]`".
36+
37+
```
38+
colon ::= ':' -- with side conditions explained above
39+
<<< ts >>> ::= ‘{’ ts ‘}’
40+
| indent ts outdent
41+
:<<< ts >>> ::= [nl] ‘{’ ts ‘}’
42+
| colon indent ts outdent
43+
```
44+
2345
## Identifiers
2446

2547
```ebnf
@@ -80,28 +102,30 @@ Some examples of constant identifiers are
80102
The ‘$’ character is reserved for compiler-synthesized identifiers.
81103
User programs should not define identifiers that contain ‘$’ characters.
82104
105+
### Regular keywords
106+
83107
The following names are reserved words instead of being members of the syntactic class `id` of lexical identifiers.
84108
85109
```scala
86-
abstract case catch class def
87-
do else extends false final
88-
finally for forSome if implicit
89-
import lazy macro match new
90-
null object override package private
91-
protected return sealed super this
92-
throw trait try true type
93-
val var while with yield
94-
_ : = => <- <: <% >: # @
110+
abstract case catch class def do else
111+
enum export extends false final finally for
112+
given if implicit import lazy match new
113+
null object override package private protected return
114+
sealed super then throw trait true try
115+
type val var while with yield
116+
: = <- => <: >: #
117+
@ =>> ?=>
95118
```
96119
97-
The Unicode operators `\u21D2` ‘´\Rightarrow´’ and `\u2190` ‘´\leftarrow´’, which have the ASCII equivalents `=>` and `<-`, are also reserved.
120+
### Soft keywords
98121

99-
> Here are examples of identifiers:
100-
> ```scala
101-
> x Object maxIndex p2p empty_?
102-
> + `yield` αρετη _y dot_product_*
103-
> __system _MAX_LEN_
104-
> ```
122+
Additionally, the following soft keywords are reserved only in some situations.
123+
124+
´\color{red}{\text{TODO SCALA3: Port soft-modifier.md and link it here.}}´
125+
126+
```
127+
as derives end extension infix inline opaque open transparent using | * + -
128+
```
105129

106130
<!-- -->
107131

docs/_spec/TODOreference/syntax.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ productions map to AST nodes.
1818
1919
-->
2020

21-
<!-- Lexical syntax already merged into _spec. -->
21+
<!-- Everything but "Context-free Syntax" already merged into _spec. -->
2222
<!--
2323
The following description of Scala tokens uses literal characters `‘c’` when
2424
referring to the ASCII fragment `\u0000` – `\u007F`.
@@ -104,7 +104,6 @@ comment ::= ‘/*’ “any sequence of characters; nested comments ar
104104
nl ::= “new line character”
105105
semi ::= ‘;’ | nl {nl}
106106
```
107-
-->
108107
109108
## Optional Braces
110109
@@ -153,6 +152,8 @@ as derives end extension infix inline opaque open transparent using |
153152
See the [separate section on soft keywords](./soft-modifier.md) for additional
154153
details on where a soft keyword is recognized.
155154
155+
-->
156+
156157
## Context-free Syntax
157158

158159
The context-free syntax of Scala is given by the following EBNF

0 commit comments

Comments
 (0)