Skip to content

Commit ca14c36

Browse files
authored
[docs] Fix syntax highlighting issues to support newer Sphinxes. (#4283)
- Update the Pygments lexer we use for parsing Swift-like code. - State more explicitly which highlighting should be used in which code blocks. - Disable highlighting altogether in certain cases (such as SIL.rst, which has equal amounts grammar and SIL excerpts). This should fix the warnings-as-error issues coming from Sphinx > 1.3.4. Based on a patch by Jeremy Fergason! https://bugs.swift.org/browse/SR-620
1 parent b906a25 commit ca14c36

18 files changed

+161
-61
lines changed

docs/ABI.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
.. @raise litre.TestsAreMissing
44
.. _ABI:
55

6+
.. highlight:: none
7+
68
The Swift ABI
79
=============
810

docs/ARCOptimization.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
:orphan:
22

3+
.. highlight:: sil
4+
35
==========================
46
ARC Optimization for Swift
57
==========================

docs/DebuggingTheCompiler.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
:orphan:
22

3+
.. highlight:: none
4+
35
Debugging the Swift Compiler
46
============================
57

docs/DriverParseableOutput.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Parseable Driver Output
55
.. contents::
66
:local:
77

8+
.. highlight:: none
9+
810
Introduction
911
============
1012

docs/ErrorHandlingRationale.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -879,15 +879,19 @@ generally needs as much code in the function as implicit manual
879879
propagation would. However, we could optimize this for many common
880880
cases by causing clean-ups to be called automatically by the
881881
interpretation function. That is, instead of a landing pad that looks
882-
notionally like this::
882+
notionally like this:
883883
884-
void *exception = ...;
884+
.. code-block:: objc++
885+
886+
void *exception = /*...*/;
885887
SomeCXXType::~SomeCXXType(&foo);
886888
objc_release(bar);
887889
objc_release(baz);
888890
_Unwind_Resume(exception);
889891
890-
The unwind table would have a record that looks notionally like this::
892+
The unwind table would have a record that looks notionally like this:
893+
894+
.. code-block:: objc++
891895
892896
CALL_WITH_FRAME_ADDRESS(&SomeCXXType::~SomeCXXType, FRAME_OFFSET_OF(foo))
893897
CALL_WITH_FRAME_VALUE(&objc_release, FRAME_OFFSET_OF(bar))

docs/GitWorkflows.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
:orphan:
22

3+
.. highlight:: bash
4+
35
Git Workflows
46
=============
57

docs/LibraryEvolution.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ specifying the name of the client library along with the required version::
121121

122122
// Client code
123123
@available(Magician 1.5)
124-
class CrystalBallView : MagicView { }
124+
class CrystalBallView : MagicView { /*…*/ }
125125

126126
Library versions can also be checked dynamically using ``#available``, allowing
127127
for fallback behavior when the requested library version is not present::
@@ -351,7 +351,7 @@ example using methods::
351351

352352
public struct Point2D {
353353
var x, y: Double
354-
public init(x: Double, y: Double) { }
354+
public init(x: Double, y: Double) { /*…*/ }
355355
}
356356

357357
extension Point2D {
@@ -368,7 +368,7 @@ polar representation::
368368

369369
public struct Point2D {
370370
var r, theta: Double
371-
public init(x: Double, y: Double) { }
371+
public init(x: Double, y: Double) { /*…*/ }
372372
}
373373

374374
and the ``x`` and ``y`` properties have now disappeared. To avoid this, the
@@ -693,13 +693,13 @@ can enforce its safe use.
693693
We've considered two possible syntaxes for this::
694694

695695
@available(1.1)
696-
extension Wand : MagicType {}
696+
extension Wand : MagicType {/*…*/}
697697

698698
and
699699

700700
::
701701

702-
extension Wand : @available(1.1) MagicType {}
702+
extension Wand : @available(1.1) MagicType {/*…*/}
703703

704704
The former requires fewer changes to the language grammar, but the latter could
705705
also be used on the declaration of the type itself (i.e. the ``struct``

docs/MutationModel.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ What do we do with this? Since ``+=`` has an ``inout`` first
4444
argument, we detect this situation statically (hopefully one day we'll
4545
have a better error message):
4646

47-
::
47+
.. code-block:: swift-console
4848
4949
<REPL Input>:1:9: error: expression does not type-check
5050
w.title += " (parenthesized remark)"

docs/PatternMatching.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,20 +292,20 @@ braces end up causing a lot of unnecessary vertical whitespace, like so::
292292

293293
switch (x)
294294
case .foo {
295-
295+
//
296296
}
297297
case .bar {
298-
298+
//
299299
}
300300
301301
So instead, let's require the switch statement to have braces, and
302302
we'll allow the cases to be written without them::
303303

304304
switch (x) {
305305
case .foo:
306-
306+
//
307307
case .bar:
308-
308+
//
309309
}
310310

311311
That's really a lot prettier, except it breaks the rule about always grouping

docs/SIL.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.. @raise litre.TestsAreMissing
2+
.. highlight:: none
23

34
Swift Intermediate Language (SIL)
45
=================================

docs/StringDesign.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,9 @@ end, strings support properties for more-specific segmentations:
389389
`Search Grapheme Cluster: o`
390390
391391
Also, each such segmentation provides a unique ``IndexType``, allowing
392-
a string to be indexed directly with different indexing schemes::
392+
a string to be indexed directly with different indexing schemes
393+
394+
.. code-block:: swift-console
393395
394396
|swift| var i = s.searchCharacters.startIndex
395397
`// r2 : UInt8 = UInt8(83)`

docs/Testing.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ test suite, via ``utils/build-script --validation-test``.
6262
Although it is not recommended for day-to-day contributions, it is also
6363
technically possible to execute the tests directly via CMake. For example, if you have
6464
built Swift products at the directory ``build/Ninja-ReleaseAssert/swift-macosx-x86_64``,
65-
you may run the entire test suite directly using the following command::
65+
you may run the entire test suite directly using the following command:
66+
67+
.. code-block:: bash
6668
6769
cmake --build build/Ninja-ReleaseAssert/swift-macosx-x86_64 -- check-swift-macosx-x86_64
6870
@@ -112,7 +114,9 @@ For every target above, there are variants for different optimizations:
112114
``executable_test`` in ``-Onone`` mode.
113115

114116
If you need to manually run certain tests, you can invoke LLVM's lit.py script
115-
directly. For example::
117+
directly. For example:
118+
119+
.. code-block:: bash
116120
117121
% ${LLVM_SOURCE_ROOT}/utils/lit/lit.py -sv ${SWIFT_BUILD_ROOT}/test-iphonesimulator-i386/Parse/
118122
@@ -128,7 +132,7 @@ source 'test/' directory.) There is a more verbose form that specifies the
128132
testing configuration explicitly, which then allows you to test files
129133
regardless of location.
130134

131-
::
135+
.. code-block:: bash
132136
133137
% ${LLVM_SOURCE_ROOT}/utils/lit/lit.py -sv --param swift_site_config=${SWIFT_BUILD_ROOT}/test-iphonesimulator-i386/lit.site.cfg ${SWIFT_SOURCE_ROOT}/test/Parse/
134138

docs/archive/LangRefNew.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ The Swift compiler does not normalize Unicode source code, and matches
494494
identifiers by code points only. Source code must be normalized to a consistent
495495
normalization form before being submitted to the compiler.
496496

497-
::
497+
.. code-block:: none
498498
499499
// Valid identifiers
500500
foo

docs/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@
287287
def swift_get_lexer_by_name(_alias, *args, **kw):
288288
if _alias == 'swift':
289289
return swift_pygments_lexers.SwiftLexer()
290+
elif _alias == 'sil':
291+
return swift_pygments_lexers.SILLexer()
290292
elif _alias == 'swift-console':
291293
return swift_pygments_lexers.SwiftConsoleLexer()
292294
else:

docs/proposals/Concurrency.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ deallocated class instance. To understand the bug try to imagine two threads
6565
executing the SIL code below in lockstep. After they both load the same value
6666
they both try to release the object. One thread succeeds and deallocates the
6767
object while another thread attempts to read the memory of a deallocated
68-
object::
68+
object:
69+
70+
.. code-block:: sil
6971
7072
%10 = global_addr @singleton : $*Bird
7173
@@ -78,7 +80,9 @@ object::
7880
7981
Next, we'll look into the problem of sliced values. Intuitively, it is easy to
8082
see why sharing memory between two threads could lead to catastrophic bugs.
81-
Consider the program below::
83+
Consider the program below:
84+
85+
.. code-block:: none
8286
8387
Thread #1: Thread #2:
8488
A.first = "John" A.first = "Paul"

docs/proposals/InoutCOWOptimization.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
:orphan:
2+
3+
.. highlight:: sil
24

35
================================================
46
Copy-On-Write Optimization of ``inout`` Values

docs/proposals/archive/ProgramStructureAndCompilationModel.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
.. @raise litre.TestsAreMissing
44
.. _ProgramStructureAndCompilationModel:
55

6+
.. highlight:: none
7+
68
Swift Program Structure and Compilation Model
79
=============================================
810

0 commit comments

Comments
 (0)