Skip to content

Commit a08be0d

Browse files
authored
QL: Add parser support for parameterised modules
1 parent 84518c8 commit a08be0d

File tree

5 files changed

+112
-6
lines changed

5 files changed

+112
-6
lines changed

ql/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ql/extractor/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ edition = "2018"
1010
flate2 = "1.0"
1111
node-types = { path = "../node-types" }
1212
tree-sitter = "0.19"
13-
tree-sitter-ql = { git = "https://github.com/tausbn/tree-sitter-ql.git", rev = "725395405e65814f10095a451404b0ced5dc6289" }
13+
tree-sitter-ql = { git = "https://github.com/tausbn/tree-sitter-ql.git", rev = "4239ed505a53e9f5340e03725de76911d17387b1" }
1414
clap = "2.33"
1515
tracing = "0.1"
1616
tracing-subscriber = { version = "0.3.3", features = ["env-filter"] }

ql/generator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ clap = "2.33"
1111
node-types = { path = "../node-types" }
1212
tracing = "0.1"
1313
tracing-subscriber = { version = "0.3.3", features = ["env-filter"] }
14-
tree-sitter-ql = { git = "https://github.com/tausbn/tree-sitter-ql.git", rev = "725395405e65814f10095a451404b0ced5dc6289" }
14+
tree-sitter-ql = { git = "https://github.com/tausbn/tree-sitter-ql.git", rev = "4239ed505a53e9f5340e03725de76911d17387b1" }

ql/ql/src/codeql_ql/ast/internal/TreeSitter.qll

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,15 +944,24 @@ module QL {
944944
/** Gets the name of the primary QL class for this element. */
945945
final override string getAPrimaryQlClass() { result = "Module" }
946946

947+
/** Gets the node corresponding to the field `implements`. */
948+
final AstNode getImplements(int i) { ql_module_implements(this, i, result) }
949+
947950
/** Gets the node corresponding to the field `name`. */
948951
final ModuleName getName() { ql_module_def(this, result) }
949952

953+
/** Gets the node corresponding to the field `parameter`. */
954+
final AstNode getParameter(int i) { ql_module_parameter(this, i, result) }
955+
950956
/** Gets the `i`th child of this node. */
951957
final AstNode getChild(int i) { ql_module_child(this, i, result) }
952958

953959
/** Gets a field or child node of this node. */
954960
final override AstNode getAFieldOrChild() {
955-
ql_module_def(this, result) or ql_module_child(this, _, result)
961+
ql_module_implements(this, _, result) or
962+
ql_module_def(this, result) or
963+
ql_module_parameter(this, _, result) or
964+
ql_module_child(this, _, result)
956965
}
957966
}
958967

@@ -968,6 +977,18 @@ module QL {
968977
final override AstNode getAFieldOrChild() { ql_module_alias_body_def(this, result) }
969978
}
970979

980+
/** A class representing `moduleApplication` nodes. */
981+
class ModuleApplication extends @ql_module_application, AstNode {
982+
/** Gets the name of the primary QL class for this element. */
983+
final override string getAPrimaryQlClass() { result = "ModuleApplication" }
984+
985+
/** Gets the `i`th child of this node. */
986+
final SignatureExpr getChild(int i) { ql_module_application_child(this, i, result) }
987+
988+
/** Gets a field or child node of this node. */
989+
final override AstNode getAFieldOrChild() { ql_module_application_child(this, _, result) }
990+
}
991+
971992
/** A class representing `moduleExpr` nodes. */
972993
class ModuleExpr extends @ql_module_expr, AstNode {
973994
/** Gets the name of the primary QL class for this element. */
@@ -1009,6 +1030,18 @@ module QL {
10091030
final override AstNode getAFieldOrChild() { ql_module_name_def(this, result) }
10101031
}
10111032

1033+
/** A class representing `moduleParam` nodes. */
1034+
class ModuleParam extends @ql_module_param, AstNode {
1035+
/** Gets the name of the primary QL class for this element. */
1036+
final override string getAPrimaryQlClass() { result = "ModuleParam" }
1037+
1038+
/** Gets the `i`th child of this node. */
1039+
final AstNode getChild(int i) { ql_module_param_child(this, i, result) }
1040+
1041+
/** Gets a field or child node of this node. */
1042+
final override AstNode getAFieldOrChild() { ql_module_param_child(this, _, result) }
1043+
}
1044+
10121045
/** A class representing `mul_expr` nodes. */
10131046
class MulExpr extends @ql_mul_expr, AstNode {
10141047
/** Gets the name of the primary QL class for this element. */
@@ -1277,6 +1310,23 @@ module QL {
12771310
final override AstNode getAFieldOrChild() { ql_set_literal_child(this, _, result) }
12781311
}
12791312

1313+
/** A class representing `signatureExpr` nodes. */
1314+
class SignatureExpr extends @ql_signature_expr, AstNode {
1315+
/** Gets the name of the primary QL class for this element. */
1316+
final override string getAPrimaryQlClass() { result = "SignatureExpr" }
1317+
1318+
/** Gets the node corresponding to the field `name`. */
1319+
final SimpleId getName() { ql_signature_expr_def(this, result) }
1320+
1321+
/** Gets the `i`th child of this node. */
1322+
final AstNode getChild(int i) { ql_signature_expr_child(this, i, result) }
1323+
1324+
/** Gets a field or child node of this node. */
1325+
final override AstNode getAFieldOrChild() {
1326+
ql_signature_expr_def(this, result) or ql_signature_expr_child(this, _, result)
1327+
}
1328+
}
1329+
12801330
/** A class representing `simpleId` tokens. */
12811331
class SimpleId extends @ql_token_simple_id, Token {
12821332
/** Gets the name of the primary QL class for this element. */

ql/ql/src/ql.dbscheme

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,24 @@ ql_member_predicate_def(
601601
int return_type: @ql_memberPredicate_returnType_type ref
602602
);
603603

604+
@ql_module_implements_type = @ql_reserved_word | @ql_signature_expr
605+
606+
#keyset[ql_module, index]
607+
ql_module_implements(
608+
int ql_module: @ql_module ref,
609+
int index: int ref,
610+
unique int implements: @ql_module_implements_type ref
611+
);
612+
613+
@ql_module_parameter_type = @ql_module_param | @ql_reserved_word
614+
615+
#keyset[ql_module, index]
616+
ql_module_parameter(
617+
int ql_module: @ql_module ref,
618+
int index: int ref,
619+
unique int parameter: @ql_module_parameter_type ref
620+
);
621+
604622
@ql_module_child_type = @ql_module_alias_body | @ql_module_member
605623

606624
#keyset[ql_module, index]
@@ -620,12 +638,23 @@ ql_module_alias_body_def(
620638
int child: @ql_module_expr ref
621639
);
622640

641+
#keyset[ql_module_application, index]
642+
ql_module_application_child(
643+
int ql_module_application: @ql_module_application ref,
644+
int index: int ref,
645+
unique int child: @ql_signature_expr ref
646+
);
647+
648+
ql_module_application_def(
649+
unique int id: @ql_module_application
650+
);
651+
623652
ql_module_expr_name(
624653
unique int ql_module_expr: @ql_module_expr ref,
625654
unique int name: @ql_token_simple_id ref
626655
);
627656

628-
@ql_moduleExpr_child_type = @ql_module_expr | @ql_token_simple_id
657+
@ql_moduleExpr_child_type = @ql_module_application | @ql_module_expr | @ql_token_simple_id
629658

630659
ql_module_expr_def(
631660
unique int id: @ql_module_expr,
@@ -650,6 +679,19 @@ ql_module_name_def(
650679
int child: @ql_token_simple_id ref
651680
);
652681

682+
@ql_moduleParam_child_type = @ql_signature_expr | @ql_token_simple_id
683+
684+
#keyset[ql_module_param, index]
685+
ql_module_param_child(
686+
int ql_module_param: @ql_module_param ref,
687+
int index: int ref,
688+
unique int child: @ql_moduleParam_child_type ref
689+
);
690+
691+
ql_module_param_def(
692+
unique int id: @ql_module_param
693+
);
694+
653695
@ql_mul_expr_left_type = @ql_add_expr | @ql_aggregate | @ql_call_or_unqual_agg_expr | @ql_comp_term | @ql_conjunction | @ql_disjunction | @ql_expr_annotation | @ql_if_term | @ql_implication | @ql_in_expr | @ql_instance_of | @ql_literal | @ql_mul_expr | @ql_negation | @ql_par_expr | @ql_prefix_cast | @ql_qualified_expr | @ql_quantified | @ql_range | @ql_set_literal | @ql_special_call | @ql_super_ref | @ql_unary_expr | @ql_variable
654696

655697
@ql_mul_expr_right_type = @ql_add_expr | @ql_aggregate | @ql_call_or_unqual_agg_expr | @ql_comp_term | @ql_conjunction | @ql_disjunction | @ql_expr_annotation | @ql_if_term | @ql_implication | @ql_in_expr | @ql_instance_of | @ql_literal | @ql_mul_expr | @ql_negation | @ql_par_expr | @ql_prefix_cast | @ql_qualified_expr | @ql_quantified | @ql_range | @ql_set_literal | @ql_special_call | @ql_super_ref | @ql_unary_expr | @ql_variable
@@ -855,6 +897,20 @@ ql_set_literal_def(
855897
unique int id: @ql_set_literal
856898
);
857899

900+
@ql_signatureExpr_child_type = @ql_module_expr | @ql_token_integer
901+
902+
#keyset[ql_signature_expr, index]
903+
ql_signature_expr_child(
904+
int ql_signature_expr: @ql_signature_expr ref,
905+
int index: int ref,
906+
unique int child: @ql_signatureExpr_child_type ref
907+
);
908+
909+
ql_signature_expr_def(
910+
unique int id: @ql_signature_expr,
911+
int name: @ql_token_simple_id ref
912+
);
913+
858914
ql_special_call_def(
859915
unique int id: @ql_special_call,
860916
int child: @ql_token_special_id ref
@@ -1057,7 +1113,7 @@ case @ql_token.kind of
10571113
;
10581114

10591115

1060-
@ql_ast_node = @ql_add_expr | @ql_aggregate | @ql_annot_arg | @ql_annotation | @ql_arityless_predicate_expr | @ql_as_expr | @ql_as_exprs | @ql_body | @ql_bool | @ql_call_body | @ql_call_or_unqual_agg_expr | @ql_charpred | @ql_class_member | @ql_classless_predicate | @ql_comp_term | @ql_conjunction | @ql_dataclass | @ql_datatype | @ql_datatype_branch | @ql_datatype_branches | @ql_db_annotation | @ql_db_args_annotation | @ql_db_branch | @ql_db_case_decl | @ql_db_col_type | @ql_db_column | @ql_db_entry | @ql_db_repr_type | @ql_db_table | @ql_db_table_name | @ql_db_union_decl | @ql_disjunction | @ql_expr_aggregate_body | @ql_expr_annotation | @ql_field | @ql_full_aggregate_body | @ql_higher_order_term | @ql_if_term | @ql_implication | @ql_import_directive | @ql_import_module_expr | @ql_in_expr | @ql_instance_of | @ql_literal | @ql_member_predicate | @ql_module | @ql_module_alias_body | @ql_module_expr | @ql_module_member | @ql_module_name | @ql_mul_expr | @ql_negation | @ql_order_by | @ql_order_bys | @ql_par_expr | @ql_predicate_alias_body | @ql_predicate_expr | @ql_prefix_cast | @ql_ql | @ql_qual_module_expr | @ql_qualified_expr | @ql_qualified_rhs | @ql_quantified | @ql_range | @ql_select | @ql_set_literal | @ql_special_call | @ql_super_ref | @ql_token | @ql_type_alias_body | @ql_type_expr | @ql_type_union_body | @ql_unary_expr | @ql_unqual_agg_body | @ql_var_decl | @ql_var_name | @ql_variable | @ql_yaml_comment | @ql_yaml_entry | @ql_yaml_key | @ql_yaml_keyvaluepair | @ql_yaml_listitem
1116+
@ql_ast_node = @ql_add_expr | @ql_aggregate | @ql_annot_arg | @ql_annotation | @ql_arityless_predicate_expr | @ql_as_expr | @ql_as_exprs | @ql_body | @ql_bool | @ql_call_body | @ql_call_or_unqual_agg_expr | @ql_charpred | @ql_class_member | @ql_classless_predicate | @ql_comp_term | @ql_conjunction | @ql_dataclass | @ql_datatype | @ql_datatype_branch | @ql_datatype_branches | @ql_db_annotation | @ql_db_args_annotation | @ql_db_branch | @ql_db_case_decl | @ql_db_col_type | @ql_db_column | @ql_db_entry | @ql_db_repr_type | @ql_db_table | @ql_db_table_name | @ql_db_union_decl | @ql_disjunction | @ql_expr_aggregate_body | @ql_expr_annotation | @ql_field | @ql_full_aggregate_body | @ql_higher_order_term | @ql_if_term | @ql_implication | @ql_import_directive | @ql_import_module_expr | @ql_in_expr | @ql_instance_of | @ql_literal | @ql_member_predicate | @ql_module | @ql_module_alias_body | @ql_module_application | @ql_module_expr | @ql_module_member | @ql_module_name | @ql_module_param | @ql_mul_expr | @ql_negation | @ql_order_by | @ql_order_bys | @ql_par_expr | @ql_predicate_alias_body | @ql_predicate_expr | @ql_prefix_cast | @ql_ql | @ql_qual_module_expr | @ql_qualified_expr | @ql_qualified_rhs | @ql_quantified | @ql_range | @ql_select | @ql_set_literal | @ql_signature_expr | @ql_special_call | @ql_super_ref | @ql_token | @ql_type_alias_body | @ql_type_expr | @ql_type_union_body | @ql_unary_expr | @ql_unqual_agg_body | @ql_var_decl | @ql_var_name | @ql_variable | @ql_yaml_comment | @ql_yaml_entry | @ql_yaml_key | @ql_yaml_keyvaluepair | @ql_yaml_listitem
10611117

10621118
@ql_ast_node_parent = @file | @ql_ast_node
10631119

0 commit comments

Comments
 (0)