Skip to content

Commit ede5c00

Browse files
committed
Revert "Change doc pages for syntax and indentation"
This reverts commit 1ac12ce. # Conflicts: # docs/docs/reference/other-new-features/indentation.md # docs/docs/reference/syntax.md
1 parent 7d520d1 commit ede5c00

File tree

3 files changed

+132
-150
lines changed

3 files changed

+132
-150
lines changed

docs/docs/internals/syntax.md

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ layout: doc-page
33
title: "Scala 3 Syntax Summary"
44
---
55

6-
The following description of Scala tokens uses literal characters `‘c’` when
6+
The following descriptions of Scala tokens uses literal characters `‘c’` when
77
referring to the ASCII fragment `\u0000``\u007F`.
88

9-
_Unicode escapes_ are used to represent the [Unicode character](https://www.w3.org/International/articles/definitions-characters/) with the given
9+
_Unicode escapes_ are used to represent the Unicode character with the given
1010
hexadecimal code:
1111

1212
```ebnf
@@ -17,7 +17,6 @@ hexDigit ::= ‘0’ | … | ‘9’ | ‘A’ | … | ‘F’ | ‘a’ |
1717
Informal descriptions are typeset as `“some comment”`.
1818

1919
### Lexical Syntax
20-
2120
The lexical syntax of Scala is given by the following grammar in EBNF
2221
form.
2322

@@ -29,9 +28,9 @@ letter ::= upper | lower “… and Unicode categories Lo, Lt, Nl”
2928
digit ::= ‘0’ | … | ‘9’
3029
paren ::= ‘(’ | ‘)’ | ‘[’ | ‘]’ | ‘{’ | ‘}’ | ‘'(’ | ‘'[’ | ‘'{’
3130
delim ::= ‘`’ | ‘'’ | ‘"’ | ‘.’ | ‘;’ | ‘,’
32-
opchar ::= “printableChar not matched by (whiteSpace | upper |
33-
lower | letter | digit | paren | delim | opchar |
34-
Unicode_Sm | Unicode_So)”
31+
opchar ::= “printableChar not matched by (whiteSpace | upper | lower |
32+
letter | digit | paren | delim | opchar | Unicode_Sm |
33+
Unicode_So)”
3534
printableChar ::= “all characters in [\u0020, \u007F] inclusive”
3635
charEscapeSeq ::= ‘\’ (‘b’ | ‘t’ | ‘n’ | ‘f’ | ‘r’ | ‘"’ | ‘'’ | ‘\’)
3736
@@ -43,6 +42,7 @@ plainid ::= alphaid
4342
| op
4443
id ::= plainid
4544
| ‘`’ { charNoBackQuoteOrNewline | UnicodeEscape | charEscapeSeq } ‘`’
45+
| INT // interpolation id, only for quasi-quotes
4646
idrest ::= {letter | digit} [‘_’ op]
4747
quoteId ::= ‘'’ alphaid
4848
@@ -85,36 +85,26 @@ nl ::= “new line character”
8585
semi ::= ‘;’ | nl {nl}
8686
```
8787

88-
The lexical analyzer also inserts `indent` and `outdent` tokensthat represent regions of indented code [at certain points](../reference/other-new-features-indentation.html)
89-
90-
In the context-free productions below we use the notation `<<< ts >>>`
91-
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`.
92-
93-
9488
## Keywords
9589

9690
### Regular keywords
9791

9892
```
99-
abstract case catch class def do else
100-
enum export extends false final finally for
101-
given if implicit import lazy match new
102-
null object override package private protected return
103-
sealed super then throw trait true try
104-
type val var while with yield
105-
: = <- => <: :> #
106-
@ =>> ?=>
93+
abstract case catch class def do else enum
94+
export extends false final finally for given if
95+
implicit import lazy match new null object package
96+
private protected override return super sealed then throw
97+
trait true try type val var while with
98+
yield
99+
: = <- => <: :> # @
100+
=>> ?=>
107101
```
108102

109103
### Soft keywords
110104

111105
```
112-
derives end extension infix inline opaque open transparent using | * + -
106+
derives end extension inline infix opaque open transparent using | * + -
113107
```
114-
115-
See the [separate section on soft keywords](./soft-modifier.md) for additional
116-
details on where a soft keyword is recognized.
117-
118108
## Context-free Syntax
119109

120110
The context-free syntax of Scala is given by the following EBNF
@@ -156,7 +146,7 @@ FunArgTypes ::= InfixType
156146
| FunParamClause
157147
FunParamClause ::= ‘(’ TypedFunParam {‘,’ TypedFunParam } ‘)’
158148
TypedFunParam ::= id ‘:’ Type
159-
MatchType ::= InfixType `match` <<< TypeCaseClauses >>>
149+
MatchType ::= InfixType `match` ‘{’ TypeCaseClauses ‘}’
160150
InfixType ::= RefinedType {id [nl] RefinedType} InfixOp(t1, op, t2)
161151
RefinedType ::= WithType {[nl | ‘with’] Refinement} RefinedTypeTree(t, ds)
162152
WithType ::= AnnotType {‘with’ AnnotType} (deprecated)
@@ -182,7 +172,7 @@ FunArgType ::= Type
182172
ParamType ::= [‘=>’] ParamValueType
183173
ParamValueType ::= Type [‘*’] PostfixOp(t, "*")
184174
TypeArgs ::= ‘[’ Types ‘]’ ts
185-
Refinement ::= <<< [RefineDcl] {semi [RefineDcl]} >>> ds
175+
Refinement ::= ‘{’ [RefineDcl] {semi [RefineDcl]} ‘}’ ds
186176
TypeBounds ::= [‘>:’ Type] [‘<:’ Type] TypeBoundsTree(lo, hi)
187177
TypeParamBounds ::= TypeBounds {‘:’ Type} ContextBounds(typeBounds, tps)
188178
Types ::= Type {‘,’ Type}
@@ -218,7 +208,7 @@ PostfixExpr ::= InfixExpr [id]
218208
InfixExpr ::= PrefixExpr
219209
| InfixExpr id [nl] InfixExpr InfixOp(expr, op, expr)
220210
| InfixExpr MatchClause
221-
MatchClause ::= ‘match’ <<< CaseClauses >>> Match(expr, cases)
211+
MatchClause ::= ‘match’ ‘{’ CaseClauses ‘}’ Match(expr, cases)
222212
PrefixExpr ::= [‘-’ | ‘+’ | ‘~’ | ‘!’] SimpleExpr PrefixOp(expr, op)
223213
SimpleExpr ::= SimpleRef
224214
| Literal
@@ -245,7 +235,7 @@ ParArgumentExprs ::= ‘(’ [‘using’] ExprsInParens ‘)’
245235
| ‘(’ [ExprsInParens ‘,’] PostfixExpr ‘:’ ‘_’ ‘*’ ‘)’ exprs :+ Typed(expr, Ident(wildcardStar))
246236
ArgumentExprs ::= ParArgumentExprs
247237
| BlockExpr
248-
BlockExpr ::= <<< (CaseClauses | Block) >>>
238+
BlockExpr ::= ‘{’ (CaseClauses | Block) ‘}’
249239
Block ::= {BlockStat semi} [BlockResult] Block(stats, expr?)
250240
BlockStat ::= Import
251241
| {Annotation {nl}} [‘implicit’ | ‘lazy’] Def
@@ -364,6 +354,7 @@ EndMarkerTag ::= id | ‘if’ | ‘while’ | ‘for’ | ‘match’ |
364354
RefineDcl ::= ‘val’ ValDcl
365355
| ‘def’ DefDcl
366356
| ‘type’ {nl} TypeDcl
357+
| INT
367358
Dcl ::= RefineDcl
368359
| ‘var’ VarDcl
369360
ValDcl ::= ids ‘:’ Type PatDef(_, ids, tpe, EmptyTree)
@@ -379,7 +370,7 @@ Def ::= ‘val’ PatDef
379370
| ‘type’ {nl} TypeDcl
380371
| TmplDef
381372
PatDef ::= ids [‘:’ Type] ‘=’ Expr
382-
| Pattern2 [‘:’ Type] ‘=’ Expr PatDef(_, pats, tpe?, expr)
373+
| Pattern2 [‘:’ Type] ‘=’ Expr PatDef(_, pats, tpe?, expr)
383374
VarDef ::= PatDef
384375
| ids ‘:’ Type ‘=’ ‘_’
385376
DefDef ::= DefSig [‘:’ Type] ‘=’ Expr DefDef(_, name, tparams, vparamss, tpe, expr)
@@ -398,19 +389,18 @@ GivenDef ::= [GivenSig] (AnnotType [‘=’ Expr] | ConstrApps Templat
398389
GivenSig ::= [id] [DefTypeParamClause] {UsingParamClause} ‘:’ -- one of `id`, `DefParamClause`, `UsingParamClause` must be present
399390
Extension ::= ‘extension’ [DefTypeParamClause] ‘(’ DefParam ‘)’
400391
{UsingParamClause}] ExtMethods
401-
ExtMethods ::= ExtMethod | [nl] <<< ExtMethod {semi ExtMethod >>>
392+
ExtMethods ::= ExtMethod | [nl] ‘{’ ExtMethod {semi ExtMethod ‘}’
402393
ExtMethod ::= {Annotation [nl]} {Modifier} ‘def’ DefDef
403394
Template ::= InheritClauses [TemplateBody] Template(constr, parents, self, stats)
404395
InheritClauses ::= [‘extends’ ConstrApps] [‘derives’ QualId {‘,’ QualId}]
405396
ConstrApps ::= ConstrApp ({‘,’ ConstrApp} | {‘with’ ConstrApp})
406397
ConstrApp ::= SimpleType1 {Annotation} {ParArgumentExprs} Apply(tp, args)
407398
ConstrExpr ::= SelfInvocation
408-
| <<< SelfInvocation {semi BlockStat} >>>
399+
| ‘{’ SelfInvocation {semi BlockStat} ‘}’
409400
SelfInvocation ::= ‘this’ ArgumentExprs {ArgumentExprs}
410401
411-
TemplateBody ::= [nl | ‘with’] <<< [SelfType] TemplateStats >>>
412-
| ‘with’ SelfType indent TemplateStats outdent
413-
TemplateStats ::= TemplateStat {semi TemplateStat}
402+
TemplateBody ::= [nl | ‘with’] ‘{’ [SelfType] TemplateStat {semi TemplateStat} ‘}’
403+
| ‘with’ [SelfType] indent TemplateStats outdent
414404
TemplateStat ::= Import
415405
| Export
416406
| {Annotation [nl]} {Modifier} Def
@@ -422,14 +412,14 @@ TemplateStat ::= Import
422412
SelfType ::= id [‘:’ InfixType] ‘=>’ ValDef(_, name, tpt, _)
423413
| ‘this’ ‘:’ InfixType ‘=>’
424414
425-
EnumBody ::= [nl | ‘with’] <<< [SelfType] EnumStats >>>
415+
EnumBody ::= [nl | ‘with’] ‘{’ [SelfType] EnumStats ‘}’
426416
| ‘with’ [SelfType] indent EnumStats outdent
427417
EnumStats ::= EnumStat {semi EnumStat}
428418
EnumStat ::= TemplateStat
429419
| {Annotation [nl]} {Modifier} EnumCase
430420
EnumCase ::= ‘case’ (id ClassConstr [‘extends’ ConstrApps]] | ids)
431421
432-
TopStats ::= TopStat {semi TopStat}
422+
TopStatSeq ::= TopStat {semi TopStat}
433423
TopStat ::= Import
434424
| Export
435425
| {Annotation [nl]} {Modifier} Def
@@ -438,8 +428,8 @@ TopStat ::= Import
438428
| PackageObject
439429
| EndMarker
440430
|
441-
Packaging ::= ‘package’ QualId [nl| ‘with’] <<< TopStats >>> Package(qid, stats)
431+
Packaging ::= ‘package’ QualId [nl| ‘with’] ‘{’ TopStatSeq ‘}’ Package(qid, stats)
442432
PackageObject ::= ‘package’ ‘object’ ObjectDef object with package in mods.
443433
444-
CompilationUnit ::= {‘package’ QualId semi} TopStats Package(qid, stats)
434+
CompilationUnit ::= {‘package’ QualId semi} TopStatSeq Package(qid, stats)
445435
```

docs/docs/reference/other-new-features/indentation.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,23 @@ There are two rules:
5858

5959
An indentation region can start
6060

61+
- after the leading parameters of an `extension`, or
62+
- after a `with` in a given instance, or
63+
- after a ": at end of line" token (see below)
6164
- after one of the following tokens:
65+
6266
```
63-
= => ?=> <- catch do else finally for if
64-
match return then throw try with while yield
67+
= => ?=> <- catch do else finally for
68+
if match return then throw try while yield
6569
```
66-
- after the leading parameters of an `extension`.
6770

6871
If an `<indent>` is inserted, the indentation width of the token on the next line
6972
is pushed onto `IW`, which makes it the new current indentation width.
7073

7174
2. An `<outdent>` is inserted at a line break, if
7275

7376
- the first token on the next line has an indentation width strictly less
74-
than the current indentation width, and
77+
than the current indentation width, and
7578
- the last token on the previous line is not one of the following tokens
7679
which indicate that the previous statement continues:
7780
```
@@ -88,7 +91,7 @@ There are two rules:
8891

8992
- An `<outdent>` is also inserted if the next token following a statement sequence starting with an `<indent>` closes an indentation region, i.e. is one of `then`, `else`, `do`, `catch`, `finally`, `yield`, `}`, `)`, `]` or `case`.
9093

91-
- An `<outdent>` is finally inserted in front of a comma that follows a statement sequence starting with an `<indent>` if the indented region is itself enclosed in parentheses
94+
An `<outdent>` is finally inserted in front of a comma that follows a statement sequence starting with an `<indent>` if the indented region is itself enclosed in parentheses
9295

9396
It is an error if the indentation width of the token following an `<outdent>` does not match the indentation of some previous line in the enclosing indentation region. For instance, the following would be rejected.
9497

0 commit comments

Comments
 (0)