Skip to content

Commit 744e2db

Browse files
committed
fix the parser to allow lower-case module names
1 parent 55b6f07 commit 744e2db

File tree

6 files changed

+43
-33
lines changed

6 files changed

+43
-33
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/erik-krogh/tree-sitter-ql.git", rev = "d8da4b8190a3c1f3fab293016bbbb60469e56ea3" }
13+
tree-sitter-ql = { git = "https://github.com/erik-krogh/tree-sitter-ql.git", rev = "343cc5873e20510586ade803659ef8ce153bd603" }
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/erik-krogh/tree-sitter-ql.git", rev = "d8da4b8190a3c1f3fab293016bbbb60469e56ea3" }
14+
tree-sitter-ql = { git = "https://github.com/erik-krogh/tree-sitter-ql.git", rev = "343cc5873e20510586ade803659ef8ce153bd603" }

ql/ql/src/codeql_ql/ast/Ast.qll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ class Module extends TModule, ModuleDeclaration {
699699

700700
override string getAPrimaryQlClass() { result = "Module" }
701701

702-
override string getName() { result = mod.getName().getValue() }
702+
override string getName() { result = mod.getName().getChild().getValue() }
703703

704704
/**
705705
* Gets a member of the module.
@@ -1129,7 +1129,7 @@ class Import extends TImport, ModuleMember, ModuleRef {
11291129
* import semmle.javascript.dataflow.Configuration as Flow
11301130
* ```
11311131
*/
1132-
string importedAs() { result = imp.getChild(1).(QL::ModuleName).getValue() }
1132+
string importedAs() { result = imp.getChild(1).(QL::ModuleName).getChild().getValue() }
11331133

11341134
/**
11351135
* Gets the `i`th selected name from the imported module.
@@ -2200,12 +2200,12 @@ class ModuleExpr extends TModuleExpr, ModuleRef {
22002200
* is `Bar`.
22012201
*/
22022202
string getName() {
2203-
result = me.getName().(QL::ModuleName).getValue()
2203+
result = me.getName().(QL::SimpleId).getValue()
22042204
or
2205-
not exists(me.getName()) and result = me.getChild().(QL::ModuleName).getValue()
2205+
not exists(me.getName()) and result = me.getChild().(QL::SimpleId).getValue()
22062206
or
22072207
exists(QL::ModuleInstantiation instantiation | instantiation.getParent() = me |
2208-
result = instantiation.getName().getValue()
2208+
result = instantiation.getName().getChild().getValue()
22092209
)
22102210
}
22112211

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,10 +1023,16 @@ module QL {
10231023
final override AstNode getAFieldOrChild() { ql_module_member_child(this, _, result) }
10241024
}
10251025

1026-
/** A class representing `moduleName` tokens. */
1027-
class ModuleName extends @ql_token_module_name, Token {
1026+
/** A class representing `moduleName` nodes. */
1027+
class ModuleName extends @ql_module_name, AstNode {
10281028
/** Gets the name of the primary QL class for this element. */
10291029
final override string getAPrimaryQlClass() { result = "ModuleName" }
1030+
1031+
/** Gets the child of this node. */
1032+
final SimpleId getChild() { ql_module_name_def(this, result) }
1033+
1034+
/** Gets a field or child node of this node. */
1035+
final override AstNode getAFieldOrChild() { ql_module_name_def(this, result) }
10301036
}
10311037

10321038
/** A class representing `moduleParam` nodes. */

ql/ql/src/ql.dbscheme

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ ql_implication_def(
529529
int right: @ql_implication_right_type ref
530530
);
531531

532-
@ql_importDirective_child_type = @ql_import_module_expr | @ql_token_module_name
532+
@ql_importDirective_child_type = @ql_import_module_expr | @ql_module_name
533533

534534
#keyset[ql_import_directive, index]
535535
ql_import_directive_child(
@@ -626,22 +626,22 @@ ql_module_child(
626626

627627
ql_module_def(
628628
unique int id: @ql_module,
629-
int name: @ql_token_module_name ref
629+
int name: @ql_module_name ref
630630
);
631631

632632
ql_module_alias_body_def(
633633
unique int id: @ql_module_alias_body,
634634
int child: @ql_module_expr ref
635635
);
636636

637-
@ql_moduleExpr_name_type = @ql_module_instantiation | @ql_token_module_name
637+
@ql_moduleExpr_name_type = @ql_module_instantiation | @ql_token_simple_id
638638

639639
ql_module_expr_name(
640640
unique int ql_module_expr: @ql_module_expr ref,
641641
unique int name: @ql_moduleExpr_name_type ref
642642
);
643643

644-
@ql_moduleExpr_child_type = @ql_module_expr | @ql_module_instantiation | @ql_token_module_name
644+
@ql_moduleExpr_child_type = @ql_module_expr | @ql_module_instantiation | @ql_token_simple_id
645645

646646
ql_module_expr_def(
647647
unique int id: @ql_module_expr,
@@ -657,7 +657,7 @@ ql_module_instantiation_child(
657657

658658
ql_module_instantiation_def(
659659
unique int id: @ql_module_instantiation,
660-
int name: @ql_token_module_name ref
660+
int name: @ql_module_name ref
661661
);
662662

663663
@ql_moduleMember_child_type = @ql_annotation | @ql_classless_predicate | @ql_dataclass | @ql_datatype | @ql_import_directive | @ql_module | @ql_select | @ql_token_qldoc
@@ -673,6 +673,11 @@ ql_module_member_def(
673673
unique int id: @ql_module_member
674674
);
675675

676+
ql_module_name_def(
677+
unique int id: @ql_module_name,
678+
int child: @ql_token_simple_id ref
679+
);
680+
676681
ql_module_param_def(
677682
unique int id: @ql_module_param,
678683
int parameter: @ql_token_simple_id ref,
@@ -1086,27 +1091,26 @@ case @ql_token.kind of
10861091
| 22 = @ql_token_integer
10871092
| 23 = @ql_token_line_comment
10881093
| 24 = @ql_token_literal_id
1089-
| 25 = @ql_token_module_name
1090-
| 26 = @ql_token_mulop
1091-
| 27 = @ql_token_predicate
1092-
| 28 = @ql_token_predicate_name
1093-
| 29 = @ql_token_primitive_type
1094-
| 30 = @ql_token_qldoc
1095-
| 31 = @ql_token_quantifier
1096-
| 32 = @ql_token_result
1097-
| 33 = @ql_token_simple_id
1098-
| 34 = @ql_token_special_id
1099-
| 35 = @ql_token_string
1100-
| 36 = @ql_token_super
1101-
| 37 = @ql_token_this
1102-
| 38 = @ql_token_true
1103-
| 39 = @ql_token_underscore
1104-
| 40 = @ql_token_unop
1105-
| 41 = @ql_token_yaml_value
1094+
| 25 = @ql_token_mulop
1095+
| 26 = @ql_token_predicate
1096+
| 27 = @ql_token_predicate_name
1097+
| 28 = @ql_token_primitive_type
1098+
| 29 = @ql_token_qldoc
1099+
| 30 = @ql_token_quantifier
1100+
| 31 = @ql_token_result
1101+
| 32 = @ql_token_simple_id
1102+
| 33 = @ql_token_special_id
1103+
| 34 = @ql_token_string
1104+
| 35 = @ql_token_super
1105+
| 36 = @ql_token_this
1106+
| 37 = @ql_token_true
1107+
| 38 = @ql_token_underscore
1108+
| 39 = @ql_token_unop
1109+
| 40 = @ql_token_yaml_value
11061110
;
11071111

11081112

1109-
@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_instantiation | @ql_module_member | @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
1113+
@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_instantiation | @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
11101114

11111115
@ql_ast_node_parent = @file | @ql_ast_node
11121116

0 commit comments

Comments
 (0)