Skip to content

Commit 064abd1

Browse files
authored
Convert the formal grammar for DocC compatibility (#55)
DocC doesn't support subscripts, so instead of using subscript "opt" for optionality, use a postfix question mark. Alternatives considered included text like "OPT" or "(opt)" and Unicode subscript characters. The former are hard to read and interrupt the flow of the grammar. The latter render poorly because they're intended for phonetic annotation, so the different letters don't share a baseline in many fonts. It's a known issue that DocC doesn't support hard breaks [1], so insert a paragraph break between each grammar production for now. I added a "double" paragraph break between groups, where there used to be a blank line, to preserve that information for when DocC adds hard break support in the future. 1: https://github.com/apple/swift-docc/issues/412 Fixes #3 Fixes rdar://101001280
2 parents fd82527 + d73aab8 commit 064abd1

File tree

11 files changed

+3294
-1170
lines changed

11 files changed

+3294
-1170
lines changed

Sources/TSPL/TSPL.docc/ReferenceManual/AboutTheLanguageReference.md

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,43 +22,34 @@ follows a few conventions:
2222
- An arrow (→) is used to mark grammar productions and can be read as "can consist of."
2323
- Syntactic categories are indicated by *italic* text and appear on both sides
2424
of a grammar production rule.
25-
- Literal words and punctuation are indicated by boldface `constant width` text
25+
- Literal words and punctuation are indicated by **`boldface constant width`** text
2626
and appear only on the right-hand side of a grammar production rule.
2727
- Alternative grammar productions are separated by vertical
2828
bars (|). When alternative productions are too long to read easily,
2929
they're broken into multiple grammar production rules on new lines.
3030
- In a few cases, regular font text is used to describe the right-hand side
3131
of a grammar production rule.
3232
- Optional syntactic categories and literals are marked by a trailing
33-
subscript, *opt*.
33+
question mark, *?*.
3434

3535
As an example, the grammar of a getter-setter block is defined as follows:
3636

37-
```
38-
Grammar of a getter-setter block
39-
40-
getter-setter-block --> ``{`` getter-clause setter-clause-OPT ``}`` | ``{`` setter-clause getter-clause ``}``
41-
```
42-
37+
> Grammar of a getter-setter block:
38+
>
39+
> *getter-setter-block***`{`** *getter-clause* *setter-clause*_?_ **`}`** | **`{`** *setter-clause* *getter-clause* **`}`**
4340
4441
This definition indicates that a getter-setter block can consist of a getter clause
4542
followed by an optional setter clause, enclosed in braces,
4643
*or* a setter clause followed by a getter clause, enclosed in braces.
4744
The grammar production above is equivalent to the following two productions,
4845
where the alternatives are spelled out explicitly:
4946

50-
```
51-
Grammar of a getter-setter block
52-
53-
getter-setter-block --> ``{`` getter-clause setter-clause-OPT ``}``
54-
getter-setter-block --> ``{`` setter-clause getter-clause ``}``
55-
```
56-
57-
58-
*getter-setter-block*`{` *getter-clause* *setter-clause?* `}`
59-
60-
*getter-setter-block*`{` *setter-clause* *getter-clause* `}`
61-
47+
> Grammar of a getter-setter block:
48+
>
49+
>
50+
> *getter-setter-block***`{`** *getter-clause* *setter-clause*_?_ **`}`**
51+
>
52+
> *getter-setter-block***`{`** *setter-clause* *getter-clause* **`}`**
6253
6354
<!--
6455
This source file is part of the Swift.org open source project

Sources/TSPL/TSPL.docc/ReferenceManual/Attributes.md

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,21 +2237,30 @@ at the time the code is compiled.
22372237
For an example of how to use the `unknown` attribute,
22382238
see <doc:Statements#Switching-Over-Future-Enumeration-Cases>.
22392239

2240-
```
2241-
Grammar of an attribute
2242-
2243-
attribute --> ``@`` attribute-name attribute-argument-clause-OPT
2244-
attribute-name --> identifier
2245-
attribute-argument-clause --> ``(`` balanced-tokens-OPT ``)``
2246-
attributes --> attribute attributes-OPT
2247-
2248-
balanced-tokens --> balanced-token balanced-tokens-OPT
2249-
balanced-token --> ``(`` balanced-tokens-OPT ``)``
2250-
balanced-token --> ``[`` balanced-tokens-OPT ``]``
2251-
balanced-token --> ``{`` balanced-tokens-OPT ``}``
2252-
balanced-token --> Any identifier, keyword, literal, or operator
2253-
balanced-token --> Any punctuation except ``(``, ``)``, ``[``, ``]``, ``{``, or ``}``
2254-
```
2240+
> Grammar of an attribute:
2241+
>
2242+
> *attribute***`@`** *attribute-name* *attribute-argument-clause*_?_
2243+
>
2244+
> *attribute-name**identifier*
2245+
>
2246+
> *attribute-argument-clause***`(`** *balanced-tokens*_?_ **`)`**
2247+
>
2248+
> *attributes**attribute* *attributes*_?_
2249+
>
2250+
>
2251+
>
2252+
> *balanced-tokens**balanced-token* *balanced-tokens*_?_
2253+
>
2254+
> *balanced-token***`(`** *balanced-tokens*_?_ **`)`**
2255+
>
2256+
> *balanced-token***`[`** *balanced-tokens*_?_ **`]`**
2257+
>
2258+
> *balanced-token***`{`** *balanced-tokens*_?_ **`}`**
2259+
>
2260+
> *balanced-token* → Any identifier, keyword, literal, or operator
2261+
>
2262+
> *balanced-token* → Any punctuation except **`(`**, **`)`**, **`[`**, **`]`**, **`{`**, or **`}`**
2263+
22552264

22562265

22572266

0 commit comments

Comments
 (0)