Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cfa9bad

Browse files
committed
Issue #28755: Improve syntax highlighting in Arg Clinic howto
1 parent a277c13 commit cfa9bad

1 file changed

Lines changed: 29 additions & 15 deletions

File tree

Doc/howto/clinic.rst

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. highlightlang:: c
2+
13
**********************
24
Argument Clinic How-To
35
**********************
@@ -78,17 +80,23 @@ Basic Concepts And Usage
7880
========================
7981

8082
Argument Clinic ships with CPython; you'll find it in ``Tools/clinic/clinic.py``.
81-
If you run that script, specifying a C file as an argument::
83+
If you run that script, specifying a C file as an argument:
84+
85+
.. code-block:: shell-session
8286
83-
% python3 Tools/clinic/clinic.py foo.c
87+
$ python3 Tools/clinic/clinic.py foo.c
8488
8589
Argument Clinic will scan over the file looking for lines that
86-
look exactly like this::
90+
look exactly like this:
91+
92+
.. code-block:: none
8793
8894
/*[clinic input]
8995
9096
When it finds one, it reads everything up to a line that looks
91-
exactly like this::
97+
exactly like this:
98+
99+
.. code-block:: none
92100
93101
[clinic start generated code]*/
94102
@@ -99,7 +107,9 @@ lines, are collectively called an Argument Clinic "block".
99107
When Argument Clinic parses one of these blocks, it
100108
generates output. This output is rewritten into the C file
101109
immediately after the block, followed by a comment containing a checksum.
102-
The Argument Clinic block now looks like this::
110+
The Argument Clinic block now looks like this:
111+
112+
.. code-block:: none
103113
104114
/*[clinic input]
105115
... clinic input goes here ...
@@ -378,9 +388,7 @@ Let's dive in!
378388
12. Save and close the file, then run ``Tools/clinic/clinic.py`` on
379389
it. With luck everything worked---your block now has output, and
380390
a ``.c.h`` file has been generated! Reopen the file in your
381-
text editor to see:
382-
383-
.. code-block:: c
391+
text editor to see::
384392

385393
/*[clinic input]
386394
_pickle.Pickler.dump
@@ -402,9 +410,7 @@ Let's dive in!
402410

403411
For readability, most of the glue code has been generated to a ``.c.h``
404412
file. You'll need to include that in your original ``.c`` file,
405-
typically right after the clinic module block:
406-
407-
.. code-block:: c
413+
typically right after the clinic module block::
408414

409415
#include "clinic/_pickle.c.h"
410416

@@ -1028,7 +1034,9 @@ that value, and an error has been set (``PyErr_Occurred()`` returns a true
10281034
value), then the generated code will propagate the error. Otherwise it will
10291035
encode the value you return like normal.
10301036

1031-
Currently Argument Clinic supports only a few return converters::
1037+
Currently Argument Clinic supports only a few return converters:
1038+
1039+
.. code-block:: none
10321040
10331041
bool
10341042
int
@@ -1607,7 +1615,9 @@ code probably looks like this::
16071615
#endif /* HAVE_FUNCTIONNAME */
16081616

16091617
And then in the ``PyMethodDef`` structure at the bottom the existing code
1610-
will have::
1618+
will have:
1619+
1620+
.. code-block:: none
16111621
16121622
#ifdef HAVE_FUNCTIONNAME
16131623
{'functionname', ... },
@@ -1657,7 +1667,9 @@ extra code when using the "block" output preset? It can't go in the output bloc
16571667
because that could be deactivated by the ``#ifdef``. (That's the whole point!)
16581668

16591669
In this situation, Argument Clinic writes the extra code to the "buffer" destination.
1660-
This may mean that you get a complaint from Argument Clinic::
1670+
This may mean that you get a complaint from Argument Clinic:
1671+
1672+
.. code-block:: none
16611673
16621674
Warning in file "Modules/posixmodule.c" on line 12357:
16631675
Destination buffer 'buffer' not empty at end of file, emptying.
@@ -1677,7 +1689,9 @@ wouldn't make any sense to the Python interpreter. But using Argument Clinic
16771689
to run Python blocks lets you use Python as a Python preprocessor!
16781690

16791691
Since Python comments are different from C comments, Argument Clinic
1680-
blocks embedded in Python files look slightly different. They look like this::
1692+
blocks embedded in Python files look slightly different. They look like this:
1693+
1694+
.. code-block:: python3
16811695
16821696
#/*[python input]
16831697
#print("def foo(): pass")

0 commit comments

Comments
 (0)