Skip to content

Commit 167a572

Browse files
authored
Merge pull request github#13156 from github/ginsbach/SpecifyParameterisedSyntax
add parameter syntax for module declarations and module references
2 parents 9dede31 + c5be3fb commit 167a572

File tree

1 file changed

+34
-16
lines changed

1 file changed

+34
-16
lines changed

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

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,11 @@ A QL module definition has the following syntax:
176176

177177
::
178178

179-
module ::= annotation* "module" modulename "{" moduleBody "}"
179+
module ::= annotation* "module" modulename parameters? implements? "{" moduleBody "}"
180+
181+
parameters ::= "<" signatureExpr simpleId ("," signatureExpr simpleId)* ">"
182+
183+
implements ::= "implements" moduleSignatureExpr ("," moduleSignatureExpr)*
180184

181185
moduleBody ::= (import | predicate | class | module | alias | select)*
182186

@@ -208,12 +212,15 @@ An import directive refers to a module identifier:
208212

209213
::
210214

211-
import ::= annotations "import" importModuleId ("as" modulename)?
215+
import ::= annotations "import" importModuleExpr ("as" modulename)?
212216

213217
qualId ::= simpleId | qualId "." simpleId
214218

215-
importModuleId ::= qualId
216-
| importModuleId "::" simpleId
219+
importModuleExpr ::= qualId | importModuleExpr "::" simpleId arguments?
220+
221+
arguments ::= "<" argument ("," argument)* ">"
222+
223+
argument ::= moduleExpr | type | predicateRef "/" int
217224

218225
An import directive may optionally name the imported module using an ``as`` declaration. If a name is defined, then the import directive adds to the declared module environment of the current module a mapping from the name to the declaration of the imported module. Otherwise, the current module *directly imports* the imported module.
219226

@@ -280,9 +287,9 @@ With the exception of class domain types and character types (which cannot be re
280287

281288
::
282289

283-
type ::= (moduleId "::")? classname | dbasetype | "boolean" | "date" | "float" | "int" | "string"
290+
type ::= (moduleExpr "::")? classname | dbasetype | "boolean" | "date" | "float" | "int" | "string"
284291

285-
moduleId ::= simpleId | moduleId "::" simpleId
292+
moduleExpr ::= simpleId arguments? | moduleExpr "::" simpleId arguments?
286293

287294
A type reference is resolved to a type as follows:
288295

@@ -597,7 +604,7 @@ Identifiers are used in following syntactic constructs:
597604
modulename ::= simpleId
598605
classname ::= upperId
599606
dbasetype ::= atLowerId
600-
predicateRef ::= (moduleId "::")? literalId
607+
predicateRef ::= (moduleExpr "::")? literalId
601608
predicateName ::= lowerId
602609
varname ::= lowerId
603610
literalId ::= lowerId | atLowerId
@@ -1615,7 +1622,7 @@ Aliases define new names for existing QL entities.
16151622

16161623
alias ::= qldoc? annotations "predicate" literalId "=" predicateRef "/" int ";"
16171624
| qldoc? annotations "class" classname "=" type ";"
1618-
| qldoc? annotations "module" modulename "=" moduleId ";"
1625+
| qldoc? annotations "module" modulename "=" moduleExpr ";"
16191626

16201627

16211628
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.
@@ -2064,16 +2071,23 @@ The complete grammar for QL is as follows:
20642071

20652072
ql ::= qldoc? moduleBody
20662073

2067-
module ::= annotation* "module" modulename "{" moduleBody "}"
2074+
module ::= annotation* "module" modulename parameters? implements? "{" moduleBody "}"
2075+
2076+
parameters ::= "<" signatureExpr simpleId ("," signatureExpr simpleId)* ">"
2077+
2078+
implements ::= "implements" moduleSignatureExpr ("," moduleSignatureExpr)*
20682079

20692080
moduleBody ::= (import | predicate | class | module | alias | select)*
20702081

2071-
import ::= annotations "import" importModuleId ("as" modulename)?
2082+
import ::= annotations "import" importModuleExpr ("as" modulename)?
20722083

20732084
qualId ::= simpleId | qualId "." simpleId
20742085

2075-
importModuleId ::= qualId
2076-
| importModuleId "::" simpleId
2086+
importModuleExpr ::= qualId | importModuleExpr "::" simpleId arguments?
2087+
2088+
arguments ::= "<" argument ("," argument)* ">"
2089+
2090+
argument ::= moduleExpr | type | predicateRef "/" int
20772091

20782092
select ::= ("from" var_decls)? ("where" formula)? "select" as_exprs ("order" "by" orderbys)?
20792093

@@ -2120,15 +2134,19 @@ The complete grammar for QL is as follows:
21202134

21212135
field ::= qldoc? annotations var_decl ";"
21222136

2123-
moduleId ::= simpleId | moduleId "::" simpleId
2137+
moduleExpr ::= simpleId arguments? | moduleExpr "::" simpleId arguments?
2138+
2139+
moduleSignatureExpr ::= (moduleExpr "::")? upperId arguments?
2140+
2141+
signatureExpr : (moduleExpr "::")? simpleId ("/" Integer | arguments)?;
21242142

2125-
type ::= (moduleId "::")? classname | dbasetype | "boolean" | "date" | "float" | "int" | "string"
2143+
type ::= (moduleExpr "::")? classname | dbasetype | "boolean" | "date" | "float" | "int" | "string"
21262144

21272145
exprs ::= expr ("," expr)*
21282146

21292147
alias ::= qldoc? annotations "predicate" literalId "=" predicateRef "/" int ";"
21302148
| qldoc? annotations "class" classname "=" type ";"
2131-
| qldoc? annotations "module" modulename "=" moduleId ";"
2149+
| qldoc? annotations "module" modulename "=" moduleExpr ";"
21322150

21332151
var_decls ::= (var_decl ("," var_decl)*)?
21342152

@@ -2249,7 +2267,7 @@ The complete grammar for QL is as follows:
22492267

22502268
dbasetype ::= atLowerId
22512269

2252-
predicateRef ::= (moduleId "::")? literalId
2270+
predicateRef ::= (moduleExpr "::")? literalId
22532271

22542272
predicateName ::= lowerId
22552273

0 commit comments

Comments
 (0)