Skip to content

Split apart the grammar for statements and items #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions Sources/TSPL/TSPL.docc/ReferenceManual/Declarations.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,36 @@ or a file that contains top-level executable code.
```
Grammar of a top-level declaration

top-level-declaration --> statements-OPT
top-level-declaration --> items-OPT
```


## Code Blocks

A *code block* is used by a variety of declarations and control structures
to group statements together.
to group items together.
It has the following form:

```
{
<#statements#>
<#items#>
}
```


The *statements* inside a code block include declarations,
The *items* inside a code block include declarations,
expressions, and other kinds of statements and are executed in order
of their appearance in source code.

```
Grammar of an item

item --> expression ``;``-OPT
item --> declaration ``;``-OPT
item --> statement ``;``-OPT
items --> item items-OPT
```

@Comment {
TR: What exactly are the scope rules for Swift?
}
Expand All @@ -102,7 +111,7 @@ of their appearance in source code.
```
Grammar of a code block

code-block --> ``{`` statements-OPT ``}``
code-block --> ``{`` items-OPT ``}``
```


Expand Down
2 changes: 1 addition & 1 deletion Sources/TSPL/TSPL.docc/ReferenceManual/Expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,7 @@ see <doc:AutomaticReferenceCounting#Resolving-Strong-Reference-Cycles-for-Closur
```
Grammar of a closure expression

closure-expression --> ``{`` attributes-OPT closure-signature-OPT statements-OPT ``}``
closure-expression --> ``{`` attributes-OPT closure-signature-OPT items-OPT ``}``

closure-signature --> capture-list-OPT closure-parameter-clause ``async``-OPT ``throws``-OPT function-result-OPT ``in``
closure-signature --> capture-list ``in``
Expand Down
8 changes: 3 additions & 5 deletions Sources/TSPL/TSPL.docc/ReferenceManual/Statements.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ and is used to separate multiple statements if they appear on the same line.
```
Grammar of a statement

statement --> expression ``;``-OPT
statement --> declaration ``;``-OPT
statement --> loop-statement ``;``-OPT
statement --> branch-statement ``;``-OPT
statement --> labeled-statement ``;``-OPT
Expand Down Expand Up @@ -1216,10 +1214,10 @@ Grammar of a conditional compilation block

conditional-compilation-block --> if-directive-clause elseif-directive-clauses-OPT else-directive-clause-OPT endif-directive

if-directive-clause --> if-directive compilation-condition statements-OPT
if-directive-clause --> if-directive compilation-condition items-OPT
elseif-directive-clauses --> elseif-directive-clause elseif-directive-clauses-OPT
elseif-directive-clause --> elseif-directive compilation-condition statements-OPT
else-directive-clause --> else-directive statements-OPT
elseif-directive-clause --> elseif-directive compilation-condition items-OPT
else-directive-clause --> else-directive items-OPT
if-directive --> ``#if``
elseif-directive --> ``#elseif``
else-directive --> ``#else``
Expand Down