Skip to content

Commit 308bb29

Browse files
committed
feat(ast): Enhance Bicep AST with underscore-prefixed node classes and update child type references
1 parent 2b5a346 commit 308bb29

File tree

4 files changed

+70
-76
lines changed

4 files changed

+70
-76
lines changed

ql/lib/bicep.dbscheme

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,26 @@ yaml_locations(unique int locatable: @yaml_locatable ref,
109109
@yaml_locatable = @yaml_node | @yaml_error;
110110

111111
/*- BICEP dbscheme -*/
112+
@bicep_underscore_declaration = @bicep_assert_statement | @bicep_metadata_declaration | @bicep_module_declaration | @bicep_output_declaration | @bicep_parameter_declaration | @bicep_resource_declaration | @bicep_test_block | @bicep_type_declaration | @bicep_user_defined_function | @bicep_variable_declaration
113+
114+
@bicep_underscore_expression = @bicep_assignment_expression | @bicep_binary_expression | @bicep_lambda_expression | @bicep_ternary_expression | @bicep_unary_expression | @bicep_underscore_primary_expression
115+
116+
@bicep_underscore_primary_expression = @bicep_array | @bicep_call_expression | @bicep_for_statement | @bicep_member_expression | @bicep_object | @bicep_parenthesized_expression | @bicep_resource_expression | @bicep_string__ | @bicep_subscript_expression | @bicep_token_boolean | @bicep_token_identifier | @bicep_token_null | @bicep_token_number
117+
118+
@bicep_underscore_statement = @bicep_decorators | @bicep_import_functionality | @bicep_import_statement | @bicep_import_with_statement | @bicep_target_scope_assignment | @bicep_underscore_declaration | @bicep_using_statement
119+
112120
#keyset[bicep_arguments, index]
113121
bicep_arguments_child(
114122
int bicep_arguments: @bicep_arguments ref,
115123
int index: int ref,
116-
unique int child: @bicep_expression ref
124+
unique int child: @bicep_underscore_expression ref
117125
);
118126

119127
bicep_arguments_def(
120128
unique int id: @bicep_arguments
121129
);
122130

123-
@bicep_array_child_type = @bicep_decorators | @bicep_expression
131+
@bicep_array_child_type = @bicep_decorators | @bicep_underscore_expression
124132

125133
#keyset[bicep_array, index]
126134
bicep_array_child(
@@ -141,15 +149,15 @@ bicep_array_type_def(
141149
bicep_assert_statement_def(
142150
unique int id: @bicep_assert_statement,
143151
int name: @bicep_token_identifier ref,
144-
int child: @bicep_expression ref
152+
int child: @bicep_underscore_expression ref
145153
);
146154

147155
@bicep_assignment_expression_left_type = @bicep_member_expression | @bicep_parenthesized_expression | @bicep_resource_expression | @bicep_subscript_expression | @bicep_token_identifier
148156

149157
bicep_assignment_expression_def(
150158
unique int id: @bicep_assignment_expression,
151159
int left: @bicep_assignment_expression_left_type ref,
152-
int right: @bicep_expression ref
160+
int right: @bicep_underscore_expression ref
153161
);
154162

155163
case @bicep_binary_expression.operator of
@@ -175,9 +183,9 @@ case @bicep_binary_expression.operator of
175183

176184
bicep_binary_expression_def(
177185
unique int id: @bicep_binary_expression,
178-
int left: @bicep_expression ref,
186+
int left: @bicep_underscore_expression ref,
179187
int operator: int ref,
180-
int right: @bicep_expression ref
188+
int right: @bicep_underscore_expression ref
181189
);
182190

183191
bicep_call_expression_child(
@@ -188,16 +196,14 @@ bicep_call_expression_child(
188196
bicep_call_expression_def(
189197
unique int id: @bicep_call_expression,
190198
int arguments: @bicep_arguments ref,
191-
int function: @bicep_expression ref
199+
int function: @bicep_underscore_expression ref
192200
);
193201

194202
bicep_compatible_identifier_def(
195203
unique int id: @bicep_compatible_identifier,
196204
int child: @bicep_token_identifier ref
197205
);
198206

199-
@bicep_declaration = @bicep_assert_statement | @bicep_metadata_declaration | @bicep_module_declaration | @bicep_output_declaration | @bicep_parameter_declaration | @bicep_resource_declaration | @bicep_test_block | @bicep_type_declaration | @bicep_user_defined_function | @bicep_variable_declaration
200-
201207
bicep_decorator_def(
202208
unique int id: @bicep_decorator,
203209
int child: @bicep_call_expression ref
@@ -214,8 +220,6 @@ bicep_decorators_def(
214220
unique int id: @bicep_decorators
215221
);
216222

217-
@bicep_expression = @bicep_assignment_expression | @bicep_binary_expression | @bicep_lambda_expression | @bicep_primary_expression | @bicep_ternary_expression | @bicep_unary_expression
218-
219223
@bicep_for_loop_parameters_child_type = @bicep_token_loop_enumerator | @bicep_token_loop_variable
220224

221225
#keyset[bicep_for_loop_parameters, index]
@@ -229,14 +233,14 @@ bicep_for_loop_parameters_def(
229233
unique int id: @bicep_for_loop_parameters
230234
);
231235

232-
@bicep_for_statement_body_type = @bicep_expression | @bicep_if_statement
236+
@bicep_for_statement_body_type = @bicep_if_statement | @bicep_underscore_expression
233237

234238
bicep_for_statement_initializer(
235239
unique int bicep_for_statement: @bicep_for_statement ref,
236240
unique int initializer: @bicep_token_identifier ref
237241
);
238242

239-
@bicep_for_statement_child_type = @bicep_expression | @bicep_for_loop_parameters
243+
@bicep_for_statement_child_type = @bicep_for_loop_parameters | @bicep_underscore_expression
240244

241245
#keyset[bicep_for_statement, index]
242246
bicep_for_statement_child(
@@ -289,7 +293,7 @@ bicep_import_statement_def(
289293
unique int id: @bicep_import_statement
290294
);
291295

292-
@bicep_import_with_statement_child_type = @bicep_expression | @bicep_string__ | @bicep_token_identifier
296+
@bicep_import_with_statement_child_type = @bicep_string__ | @bicep_token_identifier | @bicep_underscore_expression
293297

294298
#keyset[bicep_import_with_statement, index]
295299
bicep_import_with_statement_child(
@@ -306,7 +310,7 @@ bicep_import_with_statement_def(
306310
bicep_infrastructure_child(
307311
int bicep_infrastructure: @bicep_infrastructure ref,
308312
int index: int ref,
309-
unique int child: @bicep_statement ref
313+
unique int child: @bicep_underscore_statement ref
310314
);
311315

312316
bicep_infrastructure_def(
@@ -315,29 +319,29 @@ bicep_infrastructure_def(
315319

316320
bicep_interpolation_def(
317321
unique int id: @bicep_interpolation,
318-
int child: @bicep_expression ref
322+
int child: @bicep_underscore_expression ref
319323
);
320324

321325
#keyset[bicep_lambda_expression, index]
322326
bicep_lambda_expression_child(
323327
int bicep_lambda_expression: @bicep_lambda_expression ref,
324328
int index: int ref,
325-
unique int child: @bicep_expression ref
329+
unique int child: @bicep_underscore_expression ref
326330
);
327331

328332
bicep_lambda_expression_def(
329333
unique int id: @bicep_lambda_expression
330334
);
331335

332-
@bicep_member_expression_object_type = @bicep_expression | @bicep_parameterized_type
336+
@bicep_member_expression_object_type = @bicep_parameterized_type | @bicep_underscore_expression
333337

334338
bicep_member_expression_def(
335339
unique int id: @bicep_member_expression,
336340
int object: @bicep_member_expression_object_type ref,
337341
int property: @bicep_token_property_identifier ref
338342
);
339343

340-
@bicep_metadata_declaration_child_type = @bicep_expression | @bicep_token_identifier
344+
@bicep_metadata_declaration_child_type = @bicep_token_identifier | @bicep_underscore_expression
341345

342346
#keyset[bicep_metadata_declaration, index]
343347
bicep_metadata_declaration_child(
@@ -368,7 +372,7 @@ bicep_negated_type_def(
368372
int child: @bicep_type__ ref
369373
);
370374

371-
@bicep_nullable_type_child_type = @bicep_array_type | @bicep_expression | @bicep_parenthesized_type | @bicep_token_primitive_type
375+
@bicep_nullable_type_child_type = @bicep_array_type | @bicep_parenthesized_type | @bicep_token_primitive_type | @bicep_underscore_expression
372376

373377
bicep_nullable_type_def(
374378
unique int id: @bicep_nullable_type,
@@ -388,7 +392,7 @@ bicep_object_def(
388392
unique int id: @bicep_object
389393
);
390394

391-
@bicep_object_property_child_type = @bicep_array_type | @bicep_compatible_identifier | @bicep_expression | @bicep_nullable_type | @bicep_parameterized_type | @bicep_resource_declaration | @bicep_string__ | @bicep_token_identifier | @bicep_token_primitive_type | @bicep_union_type
395+
@bicep_object_property_child_type = @bicep_array_type | @bicep_compatible_identifier | @bicep_nullable_type | @bicep_parameterized_type | @bicep_resource_declaration | @bicep_string__ | @bicep_token_identifier | @bicep_token_primitive_type | @bicep_underscore_expression | @bicep_union_type
392396

393397
#keyset[bicep_object_property, index]
394398
bicep_object_property_child(
@@ -401,7 +405,7 @@ bicep_object_property_def(
401405
unique int id: @bicep_object_property
402406
);
403407

404-
@bicep_output_declaration_child_type = @bicep_expression | @bicep_token_identifier | @bicep_type__
408+
@bicep_output_declaration_child_type = @bicep_token_identifier | @bicep_type__ | @bicep_underscore_expression
405409

406410
#keyset[bicep_output_declaration, index]
407411
bicep_output_declaration_child(
@@ -427,7 +431,7 @@ bicep_parameter_def(
427431
unique int id: @bicep_parameter
428432
);
429433

430-
@bicep_parameter_declaration_child_type = @bicep_expression | @bicep_token_identifier | @bicep_type__
434+
@bicep_parameter_declaration_child_type = @bicep_token_identifier | @bicep_type__ | @bicep_underscore_expression
431435

432436
#keyset[bicep_parameter_declaration, index]
433437
bicep_parameter_declaration_child(
@@ -468,7 +472,7 @@ bicep_parameters_def(
468472
bicep_parenthesized_expression_child(
469473
int bicep_parenthesized_expression: @bicep_parenthesized_expression ref,
470474
int index: int ref,
471-
unique int child: @bicep_expression ref
475+
unique int child: @bicep_underscore_expression ref
472476
);
473477

474478
bicep_parenthesized_expression_def(
@@ -480,8 +484,6 @@ bicep_parenthesized_type_def(
480484
int child: @bicep_type__ ref
481485
);
482486

483-
@bicep_primary_expression = @bicep_array | @bicep_call_expression | @bicep_for_statement | @bicep_member_expression | @bicep_object | @bicep_parenthesized_expression | @bicep_resource_expression | @bicep_string__ | @bicep_subscript_expression | @bicep_token_boolean | @bicep_token_identifier | @bicep_token_null | @bicep_token_number
484-
485487
@bicep_resource_declaration_child_type = @bicep_for_statement | @bicep_if_statement | @bicep_object | @bicep_string__ | @bicep_token_identifier
486488

487489
#keyset[bicep_resource_declaration, index]
@@ -497,12 +499,10 @@ bicep_resource_declaration_def(
497499

498500
bicep_resource_expression_def(
499501
unique int id: @bicep_resource_expression,
500-
int object: @bicep_expression ref,
502+
int object: @bicep_underscore_expression ref,
501503
int resource: @bicep_token_identifier ref
502504
);
503505

504-
@bicep_statement = @bicep_declaration | @bicep_decorators | @bicep_import_functionality | @bicep_import_statement | @bicep_import_with_statement | @bicep_target_scope_assignment | @bicep_using_statement
505-
506506
@bicep_string_child_type = @bicep_interpolation | @bicep_token_escape_sequence | @bicep_token_string_content
507507

508508
#keyset[bicep_string__, index]
@@ -518,8 +518,8 @@ bicep_string_def(
518518

519519
bicep_subscript_expression_def(
520520
unique int id: @bicep_subscript_expression,
521-
int index: @bicep_expression ref,
522-
int object: @bicep_expression ref
521+
int index: @bicep_underscore_expression ref,
522+
int object: @bicep_underscore_expression ref
523523
);
524524

525525
bicep_target_scope_assignment_def(
@@ -529,9 +529,9 @@ bicep_target_scope_assignment_def(
529529

530530
bicep_ternary_expression_def(
531531
unique int id: @bicep_ternary_expression,
532-
int alternative: @bicep_expression ref,
533-
int condition: @bicep_expression ref,
534-
int consequence: @bicep_expression ref
532+
int alternative: @bicep_underscore_expression ref,
533+
int condition: @bicep_underscore_expression ref,
534+
int consequence: @bicep_underscore_expression ref
535535
);
536536

537537
@bicep_test_block_child_type = @bicep_object | @bicep_string__ | @bicep_token_identifier
@@ -565,7 +565,7 @@ bicep_type_arguments_def(
565565
unique int id: @bicep_type_arguments
566566
);
567567

568-
@bicep_type_declaration_child_type = @bicep_array_type | @bicep_expression | @bicep_nullable_type | @bicep_parameterized_type | @bicep_token_identifier | @bicep_union_type
568+
@bicep_type_declaration_child_type = @bicep_array_type | @bicep_nullable_type | @bicep_parameterized_type | @bicep_token_identifier | @bicep_underscore_expression | @bicep_union_type
569569

570570
#keyset[bicep_type_declaration, index]
571571
bicep_type_declaration_child(
@@ -586,11 +586,11 @@ case @bicep_unary_expression.operator of
586586

587587
bicep_unary_expression_def(
588588
unique int id: @bicep_unary_expression,
589-
int argument: @bicep_expression ref,
589+
int argument: @bicep_underscore_expression ref,
590590
int operator: int ref
591591
);
592592

593-
@bicep_union_type_child_type = @bicep_array_type | @bicep_expression | @bicep_member_expression | @bicep_negated_type | @bicep_nullable_type | @bicep_object | @bicep_parameterized_type | @bicep_parenthesized_type | @bicep_string__ | @bicep_token_boolean | @bicep_token_identifier | @bicep_token_null | @bicep_token_number | @bicep_token_primitive_type
593+
@bicep_union_type_child_type = @bicep_array_type | @bicep_member_expression | @bicep_negated_type | @bicep_nullable_type | @bicep_object | @bicep_parameterized_type | @bicep_parenthesized_type | @bicep_string__ | @bicep_token_boolean | @bicep_token_identifier | @bicep_token_null | @bicep_token_number | @bicep_token_primitive_type | @bicep_underscore_expression
594594

595595
#keyset[bicep_union_type, index]
596596
bicep_union_type_child(
@@ -603,7 +603,7 @@ bicep_union_type_def(
603603
unique int id: @bicep_union_type
604604
);
605605

606-
@bicep_user_defined_function_child_type = @bicep_expression | @bicep_parameters
606+
@bicep_user_defined_function_child_type = @bicep_parameters | @bicep_underscore_expression
607607

608608
#keyset[bicep_user_defined_function, index]
609609
bicep_user_defined_function_child(
@@ -623,7 +623,7 @@ bicep_using_statement_def(
623623
int child: @bicep_string__ ref
624624
);
625625

626-
@bicep_variable_declaration_child_type = @bicep_expression | @bicep_token_identifier
626+
@bicep_variable_declaration_child_type = @bicep_token_identifier | @bicep_underscore_expression
627627

628628
#keyset[bicep_variable_declaration, index]
629629
bicep_variable_declaration_child(

ql/lib/codeql/bicep/ast/internal/AstNodes.qll

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@ newtype TAstNode =
1515
TCallExpression(BICEP::CallExpression r) or
1616
TComment(BICEP::Comment r) or
1717
TCompatibleIdentifier(BICEP::CompatibleIdentifier r) or
18-
TDeclaration(BICEP::Declaration r) or
1918
TDecorator(BICEP::Decorator r) or
2019
TDecorators(BICEP::Decorators r) or
2120
TDiagnosticComment(BICEP::DiagnosticComment r) or
2221
TEscapeSequence(BICEP::EscapeSequence r) or
23-
TExpression(BICEP::Expression r) or
2422
TForLoopParameters(BICEP::ForLoopParameters r) or
2523
TForStatement(BICEP::ForStatement r) or
2624
TIdentifier(BICEP::Identifier r) or
@@ -50,12 +48,10 @@ newtype TAstNode =
5048
TParameters(BICEP::Parameters r) or
5149
TParenthesizedExpression(BICEP::ParenthesizedExpression r) or
5250
TParenthesizedType(BICEP::ParenthesizedType r) or
53-
TPrimaryExpression(BICEP::PrimaryExpression r) or
5451
TPrimitiveType(BICEP::PrimitiveType r) or
5552
TPropertyIdentifier(BICEP::PropertyIdentifier r) or
5653
TResourceDeclaration(BICEP::ResourceDeclaration r) or
5754
TResourceExpression(BICEP::ResourceExpression r) or
58-
TStatement(BICEP::Statement r) or
5955
TString(BICEP::String r) or
6056
TStringContent(BICEP::StringContent r) or
6157
TSubscriptExpression(BICEP::SubscriptExpression r) or
@@ -88,7 +84,7 @@ class TIdents = TIdentifier or TPropertyIdentifier;
8884
*/
8985
class TStmts =
9086
TInfrastructure or TAssertStatement or TForStatement or TIfStatement or TImportStatement or
91-
TImportWithStatement or TStatement or TUsingStatement or TVariableDeclaration or
87+
TImportWithStatement or TUsingStatement or TVariableDeclaration or
9288
TParameterDeclaration or TOutputDeclaration or TUserDefinedFunction;
9389

9490
class TStmtSeq = TInfrastructure;
@@ -101,8 +97,8 @@ class TScopes = TInfrastructure;
10197
class TExpr =
10298
TLiterals or TConditionals or TCall or TCallable or TStmts or TIdents or TObject or
10399
TObjectProperty or TAssignmentExpression or TArguments or TBinaryExpression or TCallExpression or
104-
TExpression or TLambdaExpression or TMemberExpression or TParenthesizedExpression or
105-
TPrimaryExpression or TResourceExpression or TSubscriptExpression or TTernaryExpression or
100+
TLambdaExpression or TMemberExpression or TParenthesizedExpression or
101+
TResourceExpression or TSubscriptExpression or TTernaryExpression or
106102
TUnaryExpression;
107103

108104
class TConditionals = TIfStatement;
@@ -133,12 +129,10 @@ BICEP::AstNode toTreeSitter(TAstNode n) {
133129
n = TCallExpression(result) or
134130
n = TComment(result) or
135131
n = TCompatibleIdentifier(result) or
136-
n = TDeclaration(result) or
137132
n = TDecorator(result) or
138133
n = TDecorators(result) or
139134
n = TDiagnosticComment(result) or
140135
n = TEscapeSequence(result) or
141-
n = TExpression(result) or
142136
n = TForLoopParameters(result) or
143137
n = TForStatement(result) or
144138
n = TIdentifier(result) or
@@ -168,12 +162,10 @@ BICEP::AstNode toTreeSitter(TAstNode n) {
168162
n = TParameters(result) or
169163
n = TParenthesizedExpression(result) or
170164
n = TParenthesizedType(result) or
171-
n = TPrimaryExpression(result) or
172165
n = TPrimitiveType(result) or
173166
n = TPropertyIdentifier(result) or
174167
n = TResourceDeclaration(result) or
175168
n = TResourceExpression(result) or
176-
n = TStatement(result) or
177169
n = TString(result) or
178170
n = TStringContent(result) or
179171
n = TSubscriptExpression(result) or

0 commit comments

Comments
 (0)