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

Skip to content

Commit f1d8d94

Browse files
committed
Fix code blocks in QL language reference
1 parent a14f53c commit f1d8d94

11 files changed

Lines changed: 157 additions & 70 deletions

File tree

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
...
@@ -328,8 +330,10 @@ When you use this annotation, be aware of the following issues:
328330
In particular, you can't chain predicate :ref:`calls <calls>` or call predicates on a
329331
:ref:`cast <casts>`. You must write them as multiple conjuncts and explicitly order them.
330332

331-
For example, suppose you have the following definitions::
332-
333+
For example, suppose you have the following definitions:
334+
335+
.. code-block:: ql
336+
333337
class Small extends int {
334338
Small() { this in [1 .. 10] }
335339
Small getSucc() { result = this + 1}
@@ -343,8 +347,10 @@ When you use this annotation, be aware of the following issues:
343347
s.getSucc().getSucc() = 3
344348
}
345349
346-
If you add ``noopt`` pragmas, you must rewrite the predicates. For example::
347-
350+
If you add ``noopt`` pragmas, you must rewrite the predicates. For example:
351+
352+
.. code-block:: ql
353+
348354
pragma[noopt]
349355
predicate p(int i) {
350356
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: 46 additions & 24 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
407421
#. If there 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)
@@ -637,7 +655,9 @@ is exactly equivalent to ``((Foo)x)``.
637655
Casts are useful if you want to call a :ref:`member predicate <member-predicates>` that is only defined for a more
638656
specific type. For example, the following query selects Java
639657
`classes <https://codeql.github.com/codeql-standard-libraries/java/semmle/code/java/Type.qll/type.Type$Class.html>`_
640-
that have a direct supertype called "List"::
658+
that have a direct supertype called "List":
659+
660+
.. code-block:: ql
641661
642662
import java
643663
@@ -668,7 +688,9 @@ Unlike other expressions, a don't-care expression does not have a type. In pract
668688
means that ``_`` doesn't have any :ref:`member predicates <member-predicates>`, so you can't
669689
call ``_.somePredicate()``.
670690

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

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -381,13 +381,14 @@ disjunction.
381381
**Example**
382382

383383
With the following definition, an integer is in the class ``OneTwoThree`` if it is equal to
384-
``1``, ``2``, or ``3``::
384+
``1``, ``2``, or ``3``:
385+
386+
.. code-block:: ql
385387
386388
class OneTwoThree extends int {
387389
OneTwoThree() {
388390
this = 1 or this = 2 or this = 3
389391
}
390-
...
391392
}
392393
393394
.. index:: implies
@@ -418,15 +419,15 @@ The following query selects any ``SmallInt`` that is odd, or a multiple of ``4``
418419
.. [#] The difference between ``A != B`` and ``not A = B`` is due to the underlying quantifiers.
419420
If you think of ``A`` and ``B`` as sets of values, then ``A != B`` means:
420421
421-
.. code-block:: ql
422+
.. code-block:: ql
422423
423-
exists( a, b | a in A and b in B | a != b )
424+
exists( a, b | a in A and b in B | a != b )
424425
425426
On the other hand, ``not A = B`` means:
426427
427-
.. code-block:: ql
428+
.. code-block:: ql
428429
429430
not exists( a, b | a in A and b in B | a = b )
430431
431432
This is equivalent to ``forall( a, b | a in A and b in B | a != b )``, which is very
432-
different from the first formula.
433+
different from the first formula.

0 commit comments

Comments
 (0)