Skip to content

Commit 999e7f9

Browse files
authored
Merge pull request github#13222 from github/ginsbach/SignatureSyntax
add syntax for signature definitions to QL specification
2 parents f943502 + 6957857 commit 999e7f9

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

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

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ A QL module definition has the following syntax:
182182

183183
implements ::= "implements" moduleSignatureExpr ("," moduleSignatureExpr)*
184184

185-
moduleBody ::= (import | predicate | class | module | alias | select)*
185+
moduleBody ::= (import | predicate | class | module | signature | alias | select)*
186186

187187
A module definition extends the current module's declared module environment with a mapping from the module name to the module definition.
188188

@@ -334,6 +334,40 @@ Active types
334334

335335
In a QL program, the *active* types are those defined in active modules. In the remainder of this specification, any reference to the types in the program refers only to the active types.
336336

337+
338+
Signatures
339+
----------
340+
341+
Signature definitions
342+
~~~~~~~~~~~~~~~~~~~~~
343+
344+
A QL signature definition has the following syntax:
345+
346+
::
347+
348+
signature ::= predicateSignature | typeSignature | moduleSignature
349+
350+
predicateSignature ::= qldoc? annotations "signature" head ";"
351+
352+
typeSignature ::= qldoc? annotations "signature" "class" upperId ("extends" type ("," type)*)? (";" | "{" signaturePredicate* "}")
353+
354+
moduleSignature ::= qldoc? annotation* "signature" "module" upperId parameters? "{" moduleSignatureBody "}"
355+
356+
moduleSignatureBody ::= (signaturePredicate | defaultPredicate | signatureType)*
357+
358+
signaturePredicate ::= qldoc? annotations head ";"
359+
360+
defaultPredicate ::= qldoc? annotations "default" head "{" formula "}"
361+
362+
signatureType ::= qldoc? annotations "class" upperId ("extends" type ("," type)*)? "{" signaturePredicate* "}"
363+
364+
365+
A predicate signature definition extends the current module's declared predicate signature environment with a mapping from the predicate signature name and arity to the predicate signature definition.
366+
367+
A type signature definition extends the current module's declared type signature environment with a mapping from the type signature name to the type signature definition.
368+
369+
A module signature definition extends the current module's declared module signature environment with a mapping from the module signature name to the module signature definition.
370+
337371
Values
338372
------
339373

@@ -2089,6 +2123,22 @@ The complete grammar for QL is as follows:
20892123

20902124
argument ::= moduleExpr | type | predicateRef "/" int
20912125

2126+
signature ::= predicateSignature | typeSignature | moduleSignature
2127+
2128+
predicateSignature ::= qldoc? annotations "signature" head ";"
2129+
2130+
typeSignature ::= qldoc? annotations "signature" "class" upperId ("extends" type ("," type)*)? (";" | "{" signaturePredicate* "}")
2131+
2132+
moduleSignature ::= qldoc? annotation* "signature" "module" upperId parameters? "{" moduleSignatureBody "}"
2133+
2134+
moduleSignatureBody ::= (signaturePredicate | defaultPredicate | signatureType)*
2135+
2136+
signaturePredicate ::= qldoc? annotations head ";"
2137+
2138+
defaultPredicate ::= qldoc? annotations "default" head "{" formula "}"
2139+
2140+
signatureType ::= qldoc? annotations "class" upperId ("extends" type ("," type)*)? "{" signaturePredicate* "}"
2141+
20922142
select ::= ("from" var_decls)? ("where" formula)? "select" as_exprs ("order" "by" orderbys)?
20932143

20942144
as_exprs ::= as_expr ("," as_expr)*

0 commit comments

Comments
 (0)