Skip to content

Commit b230868

Browse files
authored
Merge pull request #4874 from shati-patel/docs-highlighting
Docs: Tweak syntax highlighting
2 parents 2483b09 + ad07072 commit b230868

18 files changed

+222
-93
lines changed

docs/codeql/codeql-language-guides/codeql-library-for-csharp.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ Count the number of lines of code, excluding the directory ``external``:
108108
.. code-block:: ql
109109
110110
select sum(SourceFile f |
111-
not exists(Folder external | external.getShortName() = "external" |
112-
external.getAFolder*().getAFile() = f) |
111+
not exists(Folder ext | ext.getShortName() = "external" |
112+
ext.getAFolder*().getAFile() = f) |
113113
f.getNumberOfLines())
114114
115115
Exercises
@@ -961,7 +961,7 @@ Find all obsolete elements:
961961
962962
Model NUnit test fixtures:
963963

964-
.. code-block:: csharp
964+
.. code-block:: ql
965965
966966
class TestFixture extends Class
967967
{

docs/codeql/conf.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@
3939
# The name of the Pygments (syntax highlighting) style to use.
4040
pygments_style = 'sphinx'
4141

42+
# The default language for syntax highlighting. We need to explicitly set this to "none",
43+
# otherwise Sphinx tries to highlight any unlabeled code samples as "python3".
44+
# See https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-highlight_language.
45+
46+
highlight_language = "none"
47+
4248
# Import the QL Lexer to use for syntax highlighting
4349
import os
4450
import sys

docs/codeql/ql-language-reference/aliases.rst

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ to the name that it aliases.
3333
Module aliases
3434
==============
3535

36-
Use the following syntax to define an alias for a :ref:`module <modules>`::
36+
Use the following syntax to define an alias for a :ref:`module <modules>`:
37+
38+
.. code-block:: ql
3739
3840
module ModAlias = ModuleName;
3941
@@ -52,14 +54,18 @@ a deprecation warning is displayed.
5254
Type aliases
5355
============
5456

55-
Use the following syntax to define an alias for a :ref:`type <types>`::
57+
Use the following syntax to define an alias for a :ref:`type <types>`:
58+
59+
.. code-block:: ql
5660
5761
class TypeAlias = TypeName;
5862
5963
Note that ``class`` is just a keyword. You can define an alias for any type—namely, :ref:`primitive types <primitive-types>`,
6064
:ref:`database types <database-types>` and user-defined :ref:`classes <classes>`.
6165

62-
For example, you can use an alias to abbreviate the name of the primitive type ``boolean`` to ``bool``::
66+
For example, you can use an alias to abbreviate the name of the primitive type ``boolean`` to ``bool``:
67+
68+
.. code-block:: ql
6369
6470
class bool = boolean;
6571
@@ -80,21 +86,27 @@ Or, to use a class ``OneTwo`` defined in a :ref:`module <explicit-modules>` ``M`
8086
Predicate aliases
8187
=================
8288

83-
Use the following syntax to define an alias for a :ref:`non-member predicate <non-member-predicates>`::
89+
Use the following syntax to define an alias for a :ref:`non-member predicate <non-member-predicates>`:
90+
91+
.. code-block:: ql
8492
8593
predicate PredAlias = PredicateName/Arity;
8694
8795
This works for predicates :ref:`with <predicates-with-result>` or :ref:`without <predicates-without-result>` result.
8896

8997
For example, suppose you frequently use the following predicate, which calculates the successor of a positive integer
90-
less than ten::
98+
less than ten:
99+
100+
.. code-block:: ql
91101
92102
int getSuccessor(int i) {
93103
result = i + 1 and
94104
i in [1 .. 9]
95105
}
96106
97-
You can use an alias to abbreviate the name to ``succ``::
107+
You can use an alias to abbreviate the name to ``succ``:
108+
109+
.. code-block:: ql
98110
99111
predicate succ = getSuccessor/1;
100112

docs/codeql/ql-language-reference/annotations.rst

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ to describe specific configurations. Any non-abstract subtypes must override it
8383
indirectly) to describe what sources of data they each track.
8484

8585
In other words, all non-abstract classes that extend ``Configuration`` must override ``isSource`` in their
86-
own body, or they must inherit from another class that overrides ``isSource``::
86+
own body, or they must inherit from another class that overrides ``isSource``:
87+
88+
.. code-block:: ql
8789
8890
class ConfigA extends Configuration {
8991
...
@@ -329,8 +331,10 @@ When you use this annotation, be aware of the following issues:
329331
In particular, you can't chain predicate :ref:`calls <calls>` or call predicates on a
330332
:ref:`cast <casts>`. You must write them as multiple conjuncts and explicitly order them.
331333

332-
For example, suppose you have the following definitions::
333-
334+
For example, suppose you have the following definitions:
335+
336+
.. code-block:: ql
337+
334338
class Small extends int {
335339
Small() { this in [1 .. 10] }
336340
Small getSucc() { result = this + 1}
@@ -344,8 +348,10 @@ When you use this annotation, be aware of the following issues:
344348
s.getSucc().getSucc() = 3
345349
}
346350
347-
If you add ``noopt`` pragmas, you must rewrite the predicates. For example::
348-
351+
If you add ``noopt`` pragmas, you must rewrite the predicates. For example:
352+
353+
.. code-block:: ql
354+
349355
pragma[noopt]
350356
predicate p(int i) {
351357
exists(Small s | s = i and s.getSucc() = 2)

docs/codeql/ql-language-reference/evaluation-of-ql-programs.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,27 @@ Here are some common ways that you might define infinite predicates. These all g
4848
compilation errors:
4949

5050
- The following query conceptually selects all values of type ``int``, without restricting them.
51-
The QL compiler returns the error ``'i' is not bound to a value``::
51+
The QL compiler returns the error ``'i' is not bound to a value``:
52+
53+
.. code-block:: ql
5254
5355
from int i
5456
select i
5557
5658
- The following predicate generates two errors: ``'n' is not bound to a value`` and ``'result' is
57-
not bound to a value``::
59+
not bound to a value``:
5860

61+
.. code-block:: ql
62+
5963
int timesTwo(int n) {
6064
result = n * 2
6165
}
6266
6367
- The following class ``Person`` contains all strings that start with ``"Peter"``. There are
6468
infinitely many such strings, so this is another invalid definition. The QL compiler gives the
65-
error message ``'this' is not bound to a value``::
69+
error message ``'this' is not bound to a value``:
70+
71+
.. code-block:: ql
6672
6773
class Person extends string {
6874
Person() {

docs/codeql/ql-language-reference/expressions.rst

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,17 @@ You can express certain values directly in QL, such as numbers, booleans, and st
3737
possibly starting with a minus sign (``-``).
3838
For example:
3939

40-
.. code-block:: ql
40+
.. code-block:: ql
4141
4242
0
4343
42
4444
-2048
4545
4646
- :ref:`Float <float>` literals: These are sequences of decimal digits separated by a dot
4747
(``.``), possibly starting with a minus sign (``-``).
48-
For example::
48+
For example:
49+
50+
.. code-block:: ql
4951
5052
2.0
5153
123.456
@@ -56,7 +58,7 @@ You can express certain values directly in QL, such as numbers, booleans, and st
5658
characters represent themselves, but there are a few characters that you need to "escape"
5759
with a backslash. The following are examples of string literals:
5860

59-
.. code-block:: ql
61+
.. code-block:: ql
6062
6163
"hello"
6264
"They said, \"Please escape quotation marks!\""
@@ -135,7 +137,7 @@ In the following example, the class ``C`` inherits two definitions of the predic
135137
``getANumber()``—one from ``A`` and one from ``B``.
136138
Instead of overriding both definitions, it uses the definition from ``B``.
137139

138-
::
140+
.. code-block:: ql
139141
140142
class A extends int {
141143
A() { this = 1 }
@@ -213,7 +215,7 @@ The following aggregates are available in QL:
213215
For example, the following aggregation returns the number of files that have more than
214216
``500`` lines:
215217

216-
.. code-block:: ql
218+
.. code-block:: ql
217219
218220
count(File f | f.getTotalNumberOfLines() > 500 | f)
219221
@@ -229,15 +231,15 @@ The following aggregates are available in QL:
229231
For example, the following aggregation returns the name of the ``.js`` file (or files) with the
230232
largest number of lines:
231233

232-
.. code-block:: ql
234+
.. code-block:: ql
233235
234236
max(File f | f.getExtension() = "js" | f.getBaseName() order by f.getTotalNumberOfLines())
235237
236238
The following aggregation returns the minimum string ``s`` out of the three strings mentioned
237239
below, that is, the string that comes first in the lexicographic ordering of all the possible
238240
values of ``s``. (In this case, it returns ``"De Morgan"``.)
239241

240-
::
242+
.. code-block:: ql
241243
242244
min(string s | s = "Tarski" or s = "Dedekind" or s = "De Morgan" | s)
243245
@@ -249,7 +251,9 @@ The following aggregates are available in QL:
249251
returns no values. In other words, it evaluates to the empty set.
250252

251253
For example, the following aggregation returns the average of the integers ``0``, ``1``,
252-
``2``, and ``3``::
254+
``2``, and ``3``:
255+
256+
.. code-block:: ql
253257
254258
avg(int i | i = [0 .. 3] | i)
255259
@@ -260,7 +264,9 @@ The following aggregates are available in QL:
260264
If there are no possible assignments to the aggregation variables that satisfy the formula, then the sum is ``0``.
261265

262266
For example, the following aggregation returns the sum of ``i * j`` for all possible values
263-
of ``i`` and ``j``::
267+
of ``i`` and ``j``:
268+
269+
.. code-block:: ql
264270
265271
sum(int i, int j | i = [0 .. 2] and j = [3 .. 5] | i * j)
266272
@@ -274,14 +280,16 @@ The following aggregates are available in QL:
274280
For example, the following aggregation returns the string ``"3210"``, that is, the
275281
concatenation of the strings ``"0"``, ``"1"``, ``"2"``, and ``"3"`` in descending order:
276282

277-
.. code-block:: ql
283+
.. code-block:: ql
278284
279285
concat(int i | i = [0 .. 3] | i.toString() order by i desc)
280286
281287
The ``concat`` aggregate can also take a second expression, separated from the first one by
282288
a comma. This second expression is inserted as a separator between each concatenated value.
283289

284-
For example, the following aggregation returns ``"0|1|2|3"``::
290+
For example, the following aggregation returns ``"0|1|2|3"``:
291+
292+
.. code-block:: ql
285293
286294
concat(int i | i = [0 .. 3] | i.toString(), "|")
287295
@@ -294,7 +302,9 @@ The following aggregates are available in QL:
294302

295303
For example, the following aggregation returns the value that is ranked 4th out of all the
296304
possible values. In this case, ``8`` is the 4th integer in the range from ``5`` through
297-
``15``::
305+
``15``:
306+
307+
.. code-block:: ql
298308
299309
rank[4](int i | i = [5 .. 15] | i)
300310
@@ -317,7 +327,9 @@ The following aggregates are available in QL:
317327

318328
For example, the following query returns the positive integers ``1``, ``2``, ``3``, ``4``, ``5``.
319329
For negative integers ``x``, the expressions ``x`` and ``x.abs()`` have different values, so the
320-
value for ``y`` in the aggregate expression is not uniquely determined. ::
330+
value for ``y`` in the aggregate expression is not uniquely determined.
331+
332+
.. code-block:: ql
321333
322334
from int x
323335
where x in [-5 .. 5] and x != 0
@@ -394,48 +406,54 @@ aggregation in a simpler form:
394406
then you can omit the ``<variable declarations>`` and ``<formula>`` parts and write it
395407
as follows:
396408

397-
.. code-block:: ql
409+
.. code-block:: ql
398410
399411
<aggregate>(<expression>)
400412
401413
For example, the following aggregations determine how many times the letter ``l`` occurs in
402-
string ``"hello"``. These forms are equivalent::
414+
string ``"hello"``. These forms are equivalent:
415+
416+
.. code-block:: ql
403417
404418
count(int i | i = "hello".indexOf("l") | i)
405419
count("hello".indexOf("l"))
406420
407-
#. If there only one aggregation variable, you can omit the ``<expression>`` part instead.
421+
#. If there is only one aggregation variable, you can omit the ``<expression>`` part instead.
408422
In this case, the expression is considered to be the aggregation variable itself.
409-
For example, the following aggregations are equivalent::
410-
423+
For example, the following aggregations are equivalent:
424+
425+
.. code-block:: ql
426+
411427
avg(int i | i = [0 .. 3] | i)
412428
avg(int i | i = [0 .. 3])
413429
414430
#. As a special case, you can omit the ``<expression>`` part from ``count`` even if there is more
415431
than one aggregation variable. In such a case, it counts the number of distinct tuples of
416432
aggregation variables that satisfy the formula. In other words, the expression part is
417-
considered to be the constant ``1``. For example, the following aggregations are equivalent::
418-
433+
considered to be the constant ``1``. For example, the following aggregations are equivalent:
434+
435+
.. code-block:: ql
436+
419437
count(int i, int j | i in [1 .. 3] and j in [1 .. 3] | 1)
420438
count(int i, int j | i in [1 .. 3] and j in [1 .. 3])
421439
422440
#. You can omit the ``<formula>`` part, but in that case you should include two vertical bars:
423441

424-
.. code-block:: ql
442+
.. code-block:: ql
425443
426444
<aggregate>(<variable declarations> | | <expression>)
427445
428446
This is useful if you don't want to restrict the aggregation variables any further.
429447
For example, the following aggregation returns the maximum number of lines across all files:
430448

431-
.. code-block:: ql
449+
.. code-block:: ql
432450
433451
max(File f | | f.getTotalNumberOfLines())
434452
435453
#. Finally, you can also omit both the ``<formula>`` and ``<expression>`` parts. For example,
436454
the following aggregations are equivalent ways to count the number of files in a database:
437455

438-
.. code-block:: ql
456+
.. code-block:: ql
439457
440458
count(File f | any() | 1)
441459
count(File f | | 1)
@@ -638,7 +656,9 @@ is exactly equivalent to ``((Foo)x)``.
638656
Casts are useful if you want to call a :ref:`member predicate <member-predicates>` that is only defined for a more
639657
specific type. For example, the following query selects Java
640658
`classes <https://codeql.github.com/codeql-standard-libraries/java/semmle/code/java/Type.qll/type.Type$Class.html>`_
641-
that have a direct supertype called "List"::
659+
that have a direct supertype called "List":
660+
661+
.. code-block:: ql
642662
643663
import java
644664
@@ -669,7 +689,9 @@ Unlike other expressions, a don't-care expression does not have a type. In pract
669689
means that ``_`` doesn't have any :ref:`member predicates <member-predicates>`, so you can't
670690
call ``_.somePredicate()``.
671691

672-
For example, the following query selects all the characters in the string ``"hello"``::
692+
For example, the following query selects all the characters in the string ``"hello"``:
693+
694+
.. code-block:: ql
673695
674696
from string s
675697
where s = "hello".charAt(_)

0 commit comments

Comments
 (0)