You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/codeql/ql-language-reference/ql-language-specification.rst
+74-16Lines changed: 74 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -446,7 +446,7 @@ A one-line comment is two slash characters (``/``, U+002F) followed by any seque
446
446
447
447
// This is a comment
448
448
449
-
A multiline comment is a *comment start*, followed by a *comment body*, followed by a *comment end*. A comment start is a slash (``/``, U+002F) followed by an asterisk (``*``, U+002A), and a comment end is an asterisk followed by a slash. A comment body is any sequence of characters that does not include a comment end. Here is an example multiline comment:
449
+
A multiline comment is a *comment start*, followed by a *comment body*, followed by a *comment end*. A comment start is a slash (``/``, U+002F) followed by an asterisk (``*``, U+002A), and a comment end is an asterisk followed by a slash. A comment body is any sequence of characters that does not include a comment end and does not start with an asterisk. Here is an example multiline comment:
450
450
451
451
::
452
452
@@ -456,6 +456,21 @@ A multiline comment is a *comment start*, followed by a *comment body*, followed
456
456
It had a multiline comment.
457
457
*/
458
458
459
+
QLDoc (qldoc)
460
+
~~~~~~~~
461
+
462
+
A QLDoc comment is a *qldoc comment start*, followed by a *comment body*, followed by a *qldoc comment end*. A comment start is a slash (``/``, U+002F) followed by two asterisks (``*``, U+002A), and a qldoc comment end is an asterisk followed by a slash. A qldoc comment body is any sequence of characters that does not include a comment end. Here is an example qldoc comment:
463
+
464
+
::
465
+
466
+
/**
467
+
It was the best of code.
468
+
It was the worst of code.
469
+
It had a qldoc comment.
470
+
*/
471
+
472
+
The ‘content’ of a QLDoc comment is the comment body of the comment, omitting the initial /**, the trailing */, and the leading whitespace followed by * on each internal line.
473
+
459
474
Keywords
460
475
~~~~~~~~
461
476
@@ -738,6 +753,49 @@ A predicate may have several different binding sets, which can be stated by usin
QLDoc is used for documenting ql entities and bindings. QLDoc that is used as part of the
760
+
declaration is said to be declared.
761
+
762
+
Ambiguous QLDoc
763
+
~~~~~~~~~~~
764
+
765
+
If QLDoc could be parsed as part a file module or as part of the first declaration in the file then
766
+
it is parsed as part of the first declaration.
767
+
768
+
Inheriting QLDoc
769
+
~~~~~~~~~~~
770
+
771
+
If no qldoc is provided then in may be inherited.
772
+
773
+
In the case of an alias then it may be inherited from the right-hand-side of the alias.
774
+
775
+
In the case of a member predicate we collect all member predicates that it overrides with declared QLDoc. Then if there is a member predicate in that collection that
776
+
that overrides every other member predicate in that collection then the QLDoc of that field is used as the QLDoc.
777
+
778
+
In the case of a field we collect all fields that it overrides with declared QLDoc. Then if there is a field in that collection that
779
+
that overrides every other field in that collection then its QLDoc of that field used as the QLDoc.
780
+
781
+
Content
782
+
~~~~~~~
783
+
784
+
The content of a QLDoc comment is interpreted as standard Markdown, with the following extensions:
785
+
786
+
- Fenced code blocks using backticks.
787
+
- Automatic interpretation of links and email addresses.
788
+
- Use of appropriate characters for ellipses, dashes, apostrophes, and quotes.
789
+
790
+
The content of a QLDoc comment may contain metadata tags as follows:
791
+
792
+
The tag begins with any number of whitespace characters, followed by an '@' sign. At this point there may be any number of non-whitespace characters, which form the key of the tag. Then, a single whitespace character which separates the key from the value. The value of the tag is formed by the remainder of the line, and any subsequent lines until another '@' tag is seen, or the end of the content is reached. Any sequence of consecutive whitespace characters in the value are replaced by a single space.
793
+
794
+
Metadata
795
+
~~~~~~~~
796
+
797
+
If the query file starts with whitespace followed by a qldoc comment then the tags from that qldoc comment form the query metadata.
798
+
741
799
Top-level entities
742
800
------------------
743
801
@@ -750,7 +808,7 @@ A *predicate* is declared as a sequence of annotations, a head, and an optional
750
808
751
809
::
752
810
753
-
predicate ::= annotations head optbody
811
+
predicate ::= qldoc? annotations head optbody
754
812
755
813
A predicate definition adds a mapping from the predicate name and arity to the predicate declaration to the current module's declared predicate environment.
756
814
@@ -785,7 +843,7 @@ A class definition has the following syntax:
785
843
786
844
::
787
845
788
-
class ::= annotations "class" classname "extends" type ("," type)* "{" member* "}"
846
+
class ::= qldoc? annotations "class" classname "extends" type ("," type)* "{" member* "}"
789
847
790
848
The identifier following the ``class`` keyword is the name of the class.
791
849
@@ -824,8 +882,8 @@ Each member of a class is either a *character*, a predicate, or a field:
824
882
::
825
883
826
884
member ::= character | predicate | field
827
-
character ::= annotations classname "(" ")" "{" formula "}"
828
-
field ::= annotations var_decl ";"
885
+
character ::= qldoc? annotations classname "(" ")" "{" formula "}"
886
+
field ::= qldoc? annotations var_decl ";"
829
887
830
888
Characters
831
889
^^^^^^^^^^
@@ -1476,9 +1534,9 @@ Aliases define new names for existing QL entities.
1476
1534
1477
1535
::
1478
1536
1479
-
alias ::= annotations "predicate" literalId "=" predicateRef "/" int ";"
An alias introduces a binding from the new name to the entity referred to by the right-hand side in the current module's declared predicate, type, or module environment respectively.
@@ -1896,7 +1954,7 @@ The complete grammar for QL is as follows:
0 commit comments