Skip to content

Commit 802dffc

Browse files
committed
[パターン、宣言]Grammarの改善
1 parent 55c7584 commit 802dffc

File tree

2 files changed

+79
-177
lines changed

2 files changed

+79
-177
lines changed

language-reference/patterns.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# パターン\(Patterns\)
22

3-
最終更新日: 2022/12/3
3+
最終更新日: 2023/8/11
44
原文: https://docs.swift.org/swift-book/ReferenceManual/Patterns.html
55

66
値を一致させて分解する。

language-reference/statements.md

Lines changed: 78 additions & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,15 @@ Swift では、単純な文、コンパイラ制御文、および制御フロ
1313

1414
> Grammar of a statement:
1515
>
16-
> *statement**expression* **`;`**_?_
17-
>
18-
> *statement**declaration* **`;`**_?_
19-
>
20-
> *statement**loop-statement* **`;`**_?_
21-
>
22-
> *statement**branch-statement* **`;`**_?_
23-
>
24-
> *statement**labeled-statement* **`;`**_?_
25-
>
26-
> *statement**control-transfer-statement* **`;`**_?_
27-
>
28-
> *statement**defer-statement* **`;`**_?_
29-
>
30-
> *statement**do-statement* **`;`**_?_
31-
>
32-
> *statement**compiler-control-statement*
33-
>
16+
> *statement**expression* **`;`**_?_ \
17+
> *statement**declaration* **`;`**_?_ \
18+
> *statement**loop-statement* **`;`**_?_ \
19+
> *statement**branch-statement* **`;`**_?_ \
20+
> *statement**labeled-statement* **`;`**_?_ \
21+
> *statement**control-transfer-statement* **`;`**_?_ \
22+
> *statement**defer-statement* **`;`**_?_ \
23+
> *statement**do-statement* **`;`**_?_ \
24+
> *statement**compiler-control-statement* \
3425
> *statements**statement* *statements*_?_
3526
3627
## ループ文\(Loop Statements\)
@@ -41,10 +32,8 @@ Swift では、単純な文、コンパイラ制御文、および制御フロ
4132

4233
> Grammar of a loop statement:
4334
>
44-
> *loop-statement**for-in-statement*
45-
>
46-
> *loop-statement**while-statement*
47-
>
35+
> *loop-statement**for-in-statement* \
36+
> *loop-statement**while-statement* \
4837
> *loop-statement**repeat-while-statement*
4938
5039
### For-In 文\(For-In Statement\)
@@ -90,16 +79,10 @@ _condition_ の値は、`Bool` 型または `Bool` にブリッジされた型
9079
>
9180
> *while-statement***`while`** *condition-list* *code-block*
9281
>
93-
>
94-
>
95-
> *condition-list**condition* | *condition* **`,`** *condition-list*
96-
>
82+
> *condition-list**condition* | *condition* **`,`** *condition-list* \
9783
> *condition**expression* | *availability-condition* | *case-condition* | *optional-binding-condition*
9884
>
99-
>
100-
>
101-
> *case-condition***`case`** *pattern* *initializer*
102-
>
85+
> *case-condition***`case`** *pattern* *initializer* \
10386
> *optional-binding-condition***`let`** *pattern* *initializer*_?_ | **`var`** *pattern* *initializer*_?_
10487
10588
### Repeat-While 文\(Repeat-While Statement\)
@@ -135,10 +118,8 @@ _condition_ の値は、`Bool` 型または `Bool` にブリッジされた型
135118

136119
> Grammar of a branch statement:
137120
>
138-
> *branch-statement**if-statement*
139-
>
140-
> *branch-statement**guard-statement*
141-
>
121+
> *branch-statement**if-statement* \
122+
> *branch-statement**guard-statement* \
142123
> *branch-statement**switch-statement*
143124
144125
### If 文\(If Statement\)
@@ -181,8 +162,7 @@ if <#condition 1#> {
181162

182163
> Grammar of an if statement:
183164
>
184-
> *if-statement* **`if`** *condition-list* *code-block* *else-clause*_?_
185-
>
165+
> *if-statement* **`if`** *condition-list* *code-block* *else-clause*_?_ \
186166
> *else-clause* **`else`** *code-block* | **`else`** *if-statement*
187167

188168
### <a id="guard-statement">Guard 文\(Guard Statement\)</a>
@@ -285,40 +265,23 @@ case .suppressed:
285265

286266
> Grammar of a switch statement:
287267
>
288-
> *switch-statement* **`switch`** *expression* **`{`** *switch-cases*_?_ **`}`**
289-
>
290-
> *switch-cases* *switch-case* *switch-cases*_?_
291-
>
292-
> *switch-case* *case-label* *statements*
293-
>
294-
> *switch-case* *default-label* *statements*
295-
>
268+
> *switch-statement* **`switch`** *expression* **`{`** *switch-cases*_?_ **`}`** \
269+
> *switch-cases* *switch-case* *switch-cases*_?_ \
270+
> *switch-case* *case-label* *statements* \
271+
> *switch-case* *default-label* *statements* \
296272
> *switch-case* *conditional-switch-case*
297273
>
298-
>
299-
>
300-
> *case-label* *attributes*_?_ **`case`** *case-item-list* **`:`**
301-
>
302-
> *case-item-list* *pattern* *where-clause*_?_ | *pattern* *where-clause*_?_ **`,`** *case-item-list*
303-
>
274+
> *case-label* *attributes*_?_ **`case`** *case-item-list* **`:`** \
275+
> *case-item-list* *pattern* *where-clause*_?_ | *pattern* *where-clause*_?_ **`,`** *case-item-list* \
304276
> *default-label* *attributes*_?_ **`default`** **`:`**
305277
>
306-
>
307-
>
308-
> *where-clause* **`where`** *where-expression*
309-
>
278+
> *where-clause* **`where`** *where-expression* \
310279
> *where-expression* *expression*
311280
>
312-
>
313-
>
314-
> *conditional-switch-case* *switch-if-directive-clause* *switch-elseif-directive-clauses*_?_ *switch-else-directive-clause*_?_ *endif-directive*
315-
>
316-
> *switch-if-directive-clause* *if-directive* *compilation-condition* *switch-cases*_?_
317-
>
318-
> *switch-elseif-directive-clauses* *elseif-directive-clause* *switch-elseif-directive-clauses*_?_
319-
>
320-
> *switch-elseif-directive-clause* *elseif-directive* *compilation-condition* *switch-cases*_?_
321-
>
281+
> *conditional-switch-case* *switch-if-directive-clause* *switch-elseif-directive-clauses*_?_ *switch-else-directive-clause*_?_ *endif-directive* \
282+
> *switch-if-directive-clause* *if-directive* *compilation-condition* *switch-cases*_?_ \
283+
> *switch-elseif-directive-clauses* *elseif-directive-clause* *switch-elseif-directive-clauses*_?_ \
284+
> *switch-elseif-directive-clause* *elseif-directive* *compilation-condition* *switch-cases*_?_ \
322285
> *switch-else-directive-clause* *else-directive* *switch-cases*_?_
323286

324287
## ラベル付き文\(Labeled Statement\)
@@ -331,18 +294,12 @@ case .suppressed:
331294

332295
> Grammar of a labeled statement:
333296
>
334-
> *labeled-statement* *statement-label* *loop-statement*
335-
>
336-
> *labeled-statement* *statement-label* *if-statement*
337-
>
338-
> *labeled-statement* *statement-label* *switch-statement*
339-
>
297+
> *labeled-statement* *statement-label* *loop-statement* \
298+
> *labeled-statement* *statement-label* *if-statement* \
299+
> *labeled-statement* *statement-label* *switch-statement* \
340300
> *labeled-statement* *statement-label* *do-statement*
341301
>
342-
>
343-
>
344-
> *statement-label* *label-name* **`:`**
345-
>
302+
> *statement-label* *label-name* **`:`** \
346303
> *label-name* *identifier*
347304

348305
## 制御転送文\(Control Transfer Statements\)
@@ -351,14 +308,10 @@ case .suppressed:
351308

352309
> Grammar of a control transfer statement:
353310
>
354-
> *control-transfer-statement* *break-statement*
355-
>
356-
> *control-transfer-statement* *continue-statement*
357-
>
358-
> *control-transfer-statement* *fallthrough-statement*
359-
>
360-
> *control-transfer-statement* *return-statement*
361-
>
311+
> *control-transfer-statement* *break-statement* \
312+
> *control-transfer-statement* *continue-statement* \
313+
> *control-transfer-statement* *fallthrough-statement* \
314+
> *control-transfer-statement* *return-statement* \
362315
> *control-transfer-statement* *throw-statement*
363316

364317
### <a id="break-statement">Break 文\(Break Statement\)</a>
@@ -550,14 +503,10 @@ do {
550503

551504
> Grammar of a do statement:
552505
>
553-
> *do-statement* **`do`** *code-block* *catch-clauses*_?_
554-
>
555-
> *catch-clauses* *catch-clause* *catch-clauses*_?_
556-
>
557-
> *catch-clause* **`catch`** *catch-pattern-list*_?_ *code-block*
558-
>
559-
> *catch-pattern-list* *catch-pattern* | *catch-pattern* **`,`** *catch-pattern-list*
560-
>
506+
> *do-statement* **`do`** *code-block* *catch-clauses*_?_ \
507+
> *catch-clauses* *catch-clause* *catch-clauses*_?_ \
508+
> *catch-clause* **`catch`** *catch-pattern-list*_?_ *code-block* \
509+
> *catch-pattern-list* *catch-pattern* | *catch-pattern* **`,`** *catch-pattern-list* \
561510
> *catch-pattern* *pattern* *where-clause*_?_
562511

563512
## <a id="compiler-control-statements">コンパイラ制御文\(Compiler Control Statements\)</a>
@@ -566,10 +515,8 @@ do {
566515

567516
> Grammar of a compiler control statement:
568517
>
569-
> *compiler-control-statement* *conditional-compilation-block*
570-
>
571-
> *compiler-control-statement* *line-control-statement*
572-
>
518+
> *compiler-control-statement* *conditional-compilation-block* \
519+
> *compiler-control-statement* *line-control-statement* \
573520
> *compiler-control-statement* *diagnostic-statement*
574521

575522
### <a id="conditional-compilation-block">条件付きコンパイルブロック\(Conditional Compilation Block\)</a>
@@ -644,64 +591,34 @@ print("Compiled with the Swift 5 compiler or later in a Swift mode earlier than
644591
>
645592
> *conditional-compilation-block* *if-directive-clause* *elseif-directive-clauses*_?_ *else-directive-clause*_?_ *endif-directive*
646593
>
647-
>
648-
>
649-
> *if-directive-clause* *if-directive* *compilation-condition* *statements*_?_
650-
>
651-
> *elseif-directive-clauses* *elseif-directive-clause* *elseif-directive-clauses*_?_
652-
>
653-
> *elseif-directive-clause* *elseif-directive* *compilation-condition* *statements*_?_
654-
>
655-
> *else-directive-clause* *else-directive* *statements*_?_
656-
>
657-
> *if-directive* **`#if`**
658-
>
659-
> *elseif-directive* **`#elseif`**
660-
>
661-
> *else-directive* **`#else`**
662-
>
594+
> *if-directive-clause* *if-directive* *compilation-condition* *statements*_?_ \
595+
> *elseif-directive-clauses* *elseif-directive-clause* *elseif-directive-clauses*_?_ \
596+
> *elseif-directive-clause* *elseif-directive* *compilation-condition* *statements*_?_ \
597+
> *else-directive-clause* *else-directive* *statements*_?_ \
598+
> *if-directive* **`#if`** \
599+
> *elseif-directive* **`#elseif`** \
600+
> *else-directive* **`#else`** \
663601
> *endif-directive* **`#endif`**
664602
>
665-
>
666-
>
667-
> *compilation-condition* *platform-condition*
668-
>
669-
> *compilation-condition* *identifier*
670-
>
671-
> *compilation-condition* *boolean-literal*
672-
>
673-
> *compilation-condition* **`(`** *compilation-condition* **`)`**
674-
>
675-
> *compilation-condition* **`!`** *compilation-condition*
676-
>
677-
> *compilation-condition* *compilation-condition* **`&&`** *compilation-condition*
678-
>
603+
> *compilation-condition* *platform-condition* \
604+
> *compilation-condition* *identifier* \
605+
> *compilation-condition* *boolean-literal* \
606+
> *compilation-condition* **`(`** *compilation-condition* **`)`** \
607+
> *compilation-condition* **`!`** *compilation-condition* \
608+
> *compilation-condition* *compilation-condition* **`&&`** *compilation-condition* \
679609
> *compilation-condition* *compilation-condition* **`||`** *compilation-condition*
680610
>
681-
>
682-
>
683-
> *platform-condition* **`os`** **`(`** *operating-system* **`)`**
684-
>
685-
> *platform-condition* **`arch`** **`(`** *architecture* **`)`**
686-
>
687-
> *platform-condition* **`swift`** **`(`** **`>=`** *swift-version* **`)`** | **`swift`** **`(`** **`<`** *swift-version* **`)`**
688-
>
689-
> *platform-condition* **`compiler`** **`(`** **`>=`** *swift-version* **`)`** | **`compiler`** **`(`** **`<`** *swift-version* **`)`**
690-
>
691-
> *platform-condition* **`canImport`** **`(`** *import-path* **`)`**
692-
>
611+
> *platform-condition* **`os`** **`(`** *operating-system* **`)`** \
612+
> *platform-condition* **`arch`** **`(`** *architecture* **`)`** \
613+
> *platform-condition* **`swift`** **`(`** **`>=`** *swift-version* **`)`** | **`swift`** **`(`** **`<`** *swift-version* **`)`** \
614+
> *platform-condition* **`compiler`** **`(`** **`>=`** *swift-version* **`)`** | **`compiler`** **`(`** **`<`** *swift-version* **`)`** \
615+
> *platform-condition* **`canImport`** **`(`** *import-path* **`)`** \
693616
> *platform-condition* **`targetEnvironment`** **`(`** *environment* **`)`**
694617
>
695-
>
696-
>
697-
> *operating-system* **`macOS`** | **`iOS`** | **`watchOS`** | **`tvOS`** | **`Linux`** | **`Windows`**
698-
>
699-
> *architecture* **`i386`** | **`x86_64`** | **`arm`** | **`arm64`**
700-
>
701-
> *swift-version* *decimal-digits* *swift-version-continuation*_?_
702-
>
703-
> *swift-version-continuation* **`.`** *decimal-digits* *swift-version-continuation*_?_
704-
>
618+
> *operating-system* **`macOS`** | **`iOS`** | **`watchOS`** | **`tvOS`** | **`Linux`** | **`Windows`** \
619+
> *architecture* **`i386`** | **`x86_64`** | **`arm`** | **`arm64`** \
620+
> *swift-version* *decimal-digits* *swift-version-continuation*_?_ \
621+
> *swift-version-continuation* **`.`** *decimal-digits* *swift-version-continuation*_?_ \
705622
> *environment* **`simulator`** | **`macCatalyst`**
706623

707624
### <a id="line-control-statement">行制御文\(Line Control Statement\)</a>
@@ -721,12 +638,9 @@ print("Compiled with the Swift 5 compiler or later in a Swift mode earlier than
721638

722639
> Grammar of a line control statement:
723640
>
724-
> *line-control-statement* **`#sourceLocation`** **`(`** **`file:`** *file-path* **`,`** **`line:`** *line-number* **`)`**
725-
>
726-
> *line-control-statement* **`#sourceLocation`** **`(`** **`)`**
727-
>
728-
> *line-number* A decimal integer greater than zero
729-
>
641+
> *line-control-statement* **`#sourceLocation`** **`(`** **`file:`** *file-path* **`,`** **`line:`** *line-number* **`)`** \
642+
> *line-control-statement* **`#sourceLocation`** **`(`** **`)`** \
643+
> *line-number* A decimal integer greater than zero \
730644
> *file-path* *static-string-literal*
731645

732646
### <a id="compile-time-diagnostic-statement">コンパイル時診断文\(Compile-Time Diagnostic Statement\)</a>
@@ -766,33 +680,21 @@ if #unavailable(<#platform name#> <#version#>, <#...#>) {
766680

767681
> Grammar of an availability condition:
768682
>
769-
> *availability-condition* **`#available`** **`(`** *availability-arguments* **`)`**
770-
>
771-
> *availability-condition* **`#unavailable`** **`(`** *availability-arguments* **`)`**
772-
>
773-
> *availability-arguments* *availability-argument* | *availability-argument* **`,`** *availability-arguments*
774-
>
775-
> *availability-argument* *platform-name* *platform-version*
776-
>
683+
> *availability-condition* **`#available`** **`(`** *availability-arguments* **`)`** \
684+
> *availability-condition* **`#unavailable`** **`(`** *availability-arguments* **`)`** \
685+
> *availability-arguments* *availability-argument* | *availability-argument* **`,`** *availability-arguments* \
686+
> *availability-argument* *platform-name* *platform-version* \
777687
> *availability-argument* **`*`**
778688
>
779689
>
780690
>
781-
> *platform-name* **`iOS`** | **`iOSApplicationExtension`**
782-
>
783-
> *platform-name* **`macOS`** | **`macOSApplicationExtension`**
784-
>
785-
> *platform-name* **`macCatalyst`** | **`macCatalystApplicationExtension`**
786-
>
787-
> *platform-name* **`watchOS`** | **`watchOSApplicationExtension`**
788-
>
789-
> *platform-name* **`tvOS`** | **`tvOSApplicationExtension`**
790-
>
791-
> *platform-name* **`visionOS`**
792-
>
793-
> *platform-version* *decimal-digits*
794-
>
795-
> *platform-version* *decimal-digits* **`.`** *decimal-digits*
796-
>
691+
> *platform-name* **`iOS`** | **`iOSApplicationExtension`** \
692+
> *platform-name* **`macOS`** | **`macOSApplicationExtension`** \
693+
> *platform-name* **`macCatalyst`** | **`macCatalystApplicationExtension`** \
694+
> *platform-name* **`watchOS`** | **`watchOSApplicationExtension`** \
695+
> *platform-name* **`tvOS`** | **`tvOSApplicationExtension`** \
696+
> *platform-name* **`visionOS`** \
697+
> *platform-version* *decimal-digits* \
698+
> *platform-version* *decimal-digits* **`.`** *decimal-digits* \
797699
> *platform-version* *decimal-digits* **`.`** *decimal-digits* **`.`** *decimal-digits*
798700

0 commit comments

Comments
 (0)